C + + implementation of the data structure chain stack (linkstack) (no main function) __ios

Source: Internet
Author: User
#include <iostream> 
using namespace std;
Class Linknode
{public
:
	linknode (int v): m_value (v), m_next (null) {}
	Linknode (): M_next (null) {}
	int m_value;
	Linknode *m_next;
};
Class Linkstack
{public
:
	linkstack (): M_top (NULL), m_size (0) {}
	~linkstack () {clear ();}
	void Push (int v);
	void Pop ();
	void Print ();
	int Size () Const{return m_size}
	BOOL IsEmpty () const{return m_top = = NULL? True:false;}
	void Clear ();
Private:
	Linknode *m_top;
	int m_size;
};
void Linkstack::clear ()
{while
	(m_top)
	{
		Pop ();
	}
	m_size=0;
}
void Linkstack::P rint ()
{
	Linknode *p = m_top;
	while (p)
	{
		cout<<p->m_value<< "";
		p = p->m_next;
	}
	cout<<endl;
}
void Linkstack::P ush (int v)
{
	Linknode *p = new Linknode (v);
	P->m_next = M_top;
	M_top = p;
	m_size++;
}
void Linkstack::P op ()
{
	if (! IsEmpty ())
	{
		Linknode *p = m_top;
		M_top = m_top->m_next;
		Delete p;
		p = NULL;
		m_size--
	}
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.