note stack (stack)

stack definition

A stack is a linear list that is restricted to insert or delete only at the end of the list. For the stack, the end of the table is called the top of the stack (top), and the head of the table is called the bottom of the stack. An empty list with no elements is called an empty stack. Because the stack is limited to insert or delete at the end of the table, the stack is also called 后进先出a linear table

Basic functions:

// empty()    returns true if the stack is empty
//
// pop()        removes the top element of the stack
//
// push()       adds an element to the top of the stack
//
// size()        returns the number of elements in the stack
//
/ /t op()        returns stack top element m
//
/ /swap()      exchange function 

	stack <int>mystack,mystack1;//初始化一个栈

	for(int i=0; i<5; i++)
		mystack.push(i);//将数据压入栈中 
		
	cout<<mystack.size()<<endl;//输出栈的长度 
	
	while(!mystack.empty()) {//当栈不为空时 
		
		cout<<mystack.top();//输出顶部元素  
		
		mystack.pop();//删除栈顶元素
	}

Guess you like

Origin blog.csdn.net/longzaizai_/article/details/120207753