#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
Created on 2015-1-28
@author: beyondzhou
@name: test_linkliststack.py
'''
def test_linkliststack():
# import linkListStack
from mystack import LinkListStack
print '#Init a stack named smith using push'
smith = LinkListStack()
smith.push('CSCI-112')
smith.push('MATH-121')
smith.push('HIST-340')
smith.push('ECON-101')
print '\n#output smith stack'
for element in smith:
print element
print '\n#pop one item'
smith.pop()
print '\n#output smith stack after pop'
for element in smith:
print element
print '\n#get the peek item'
peek_item = smith.peek()
print 'peek item is ', peek_item
print '\n#get the length of stack'
print 'the lenght of stack
Python 使用单链表实现堆栈 (基于class, 包含迭代器)
最新推荐文章于 2022-01-16 20:43:36 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)