[Stack+list in C++ and Python] Introduction and common methods

  • Stack is a stack data structure with first-in-last-out/last-in-first-out characteristics. List[] can be used in Python.
  • How to use it in C++
stack<..> stk;
stk.push(..)/stk.pop();		// 入栈和出栈
stk.top();		// 栈顶元素
stk.empty();	// 判断栈是否为空
stk.size(); 	// 元素个数
// 注意,stk.pop()和stk.top()必须使用empty()判断栈是否为空
  • How to use it in Python
stk = []/list()
stk[-1]		# 栈顶元素
stk.append(..)/stk.pop()	# 入栈和出栈
not stk		# 是否为空,为空返回True

Guess you like

Origin blog.csdn.net/m0_48086806/article/details/132228397