Пример #1
0
void printList(LinkStack<int> stack){
   cout<<"stack :"<<endl;
   while(!stack.isEmpty()){
	   cout<<stack.Pop()<<" ";
   }
   cout<<endl;
}
Пример #2
0
int main(int argc,char **argv)
{
	LinkStack stack;
	for (int i=0;i<10;i++)
		stack.push(i);
	stack.pop();
	stack.pop();
	return 0;
}
int main()
{
	LinkStack theStack;
	
	theStack.push(20);
	theStack.push(40);

	theStack.displayStack();

	return 0;
}
Пример #4
0
void play()
{
    Student s1, s2, s3;
    s1.age = 21;
    s2.age = 22;
    s3.age = 23;

    LinkStack<Student> ls; // ´´½¨Õ»

    // ÈëÕ»
    ls.push(s1);
    ls.push(s2);
    ls.push(s3);

    // »ñÈ¡Õ»¶¥ÔªËØ
    Student tmp;
    ls.top(tmp);
    cout << "top of stack: " << tmp.age << endl;
    cout << "size of stack: " << ls.size() << endl;

    // ³öÕ»
    while (ls.size() > 0) {
        ls.pop(tmp);
    }

    ls.clear();

}
Пример #5
0
int _tmain(int argc, _TCHAR* argv[])
{
	Stack<int> s;
	s.Add(10);
	s.Add(11);
	s.Add(12);
	std::cout << s.Top()<<std::endl;

	LinkStack<int> ls;
	ls.Add(0);
	ls.Add(1);
	ls.Add(2);
	std::cout << ls.Top()<<std::endl;

	return 0;
}
Пример #6
0
int main()
{
	char item;
	//STL实现
	//stack<char> numbers;
	//自己写的LinkStack模板类
	LinkStack<char> numbers;
	cout << "Please enter the string sequence.\nIf you want to quit, Please enter #\n";
	item = cin.get();
	while (item != '#')
	{
		numbers.push(item);
		item = cin.get();
	}
	cout << endl;
	while (!numbers.empty()) {
		cout << numbers.top();
		numbers.pop();
	}
	cout << endl;
}
Пример #7
0
void push(){
	LinkStack<int> stack ;
	stack.Push(1);
	assert(1==stack.GetTop());

	stack.Push(2);
	assert(2==stack.GetTop());

	stack.Push(3);
	assert(3==stack.GetTop());
	printList(stack);
	cout<<"test pass"<<endl;
}
Пример #8
0
int main()
{
	LinkStack<int> stack;
	int init[10]={1,3,5,7,4,2,8,0,6,9};
	for(int i=0;i<10;i++)
	{
		stack.Push(init[i]);
	}
	stack.Print();

	cout<<stack.Pop()<<endl;
	stack.Print();
	
	cout<<stack.GetTop()<<endl;
	stack.Print();

	cout<<stack.Pop()<<endl;
	stack.Print();

	stack.MakeEmpty();
	stack.Print();

	getchar();


	return 0;
}