스택(Stack)과 큐(Queue)를 이용한 예제

2008/05/27 11:38

>>> b = []
>>> e = []

>>> def main():

global c
print '*'*34
print '* Stack is First input Last Out *'
print '* Queue is First input First Out *'
print '*'*34
print '1. Insert Stack'
print '2. Delete Stack'
print '3. Show Stack'
print '4. Insert Queue'
print '5. Delete Queue'
print '6. Show Queue'
print '7. EXIT'
print 'Do you choice Number = ',
c = raw_input()
if c == '1':
insert_stack()
elif c == '2':
delete_stack()
elif c == '3':
recent_stack()
elif c == '4':
insert_queue()
elif c == '5':
delete_queue()
elif c == '6':
recent_queue()
else:
ex()


>>> def insert_stack():
print 'Insert to the Stack'
a = raw_input('-->')
b.append(a)
main()


>>> def delete_stack():
d = len(b) - 1
del b[d:]
print 'Last Stack Delete'
print 'Recent Stack is ',
print b
main()


>>> def recent_stack():
print 'Recent Stack'
print b
main()

>>> def insert_queue():
print 'Insert to the Queue'
a = raw_input('-->')
e.append(a)
main()


>>> def delete_queue():
del e[0]
print 'First Queue Delete'
print 'Recent Queue is',
print e
main()


>>> def recent_queue():
print 'Recent Queue'
print e
main()


>>> def ex():
pass

//--- 프로그램 작성 완료



//--------- 실행 예제

>>> main()
**********************************
* Stack is First input Last Out *
* Queue is First input First Out *
**********************************
1. Insert Stack
2. Delete Stack
3. Show Stack
4. Insert Queue
5. Delete Queue
6. Show Queue
7. EXIT
Do you choice Number = 1
Insert to the Stack
-->222
**********************************
* Stack is First input Last Out *
* Queue is First input First Out *
**********************************
1. Insert Stack
2. Delete Stack
3. Show Stack
4. Insert Queue
5. Delete Queue
6. Show Queue
7. EXIT
Do you choice Number = 1
Insert to the Stack
-->333
**********************************
* Stack is First input Last Out *
* Queue is First input First Out *
**********************************
1. Insert Stack
2. Delete Stack
3. Show Stack
4. Insert Queue
5. Delete Queue
6. Show Queue
7. EXIT
Do you choice Number = 3
Recent Stack
['222', '333']
**********************************
* Stack is First input Last Out *
* Queue is First input First Out *
**********************************
1. Insert Stack
2. Delete Stack
3. Show Stack
4. Insert Queue
5. Delete Queue
6. Show Queue
7. EXIT
Do you choice Number = 7
>>>
크리에이티브 커먼즈 라이센스
Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
이올린에 북마크하기