Exemple #1
0
    def test_overflow(self):
        s = FixedStack(0)
        with self.assertRaises(Exception):
            s.push(0)

        s = FixedStack(1)
        s.push(0)
        with self.assertRaises(Exception):
            s.push(0)
Exemple #2
0
    def test_underflow(self):
        s = FixedStack(10)
        with self.assertRaises(Exception):
            s.pop()

        s.push(0)
        s.pop()
        with self.assertRaises(Exception):
            s.pop()
Exemple #3
0
    def test_empty(self):
        s = FixedStack(10)
        self.assertTrue(s.empty())

        s.push(randint(0, 100))
        self.assertFalse(s.empty())
        
        s.pop()
        self.assertTrue(s.empty())
Exemple #4
0
 def test_push_pop(self):
     num_push = randint(0, 100)
     num_pop  = randint(0, num_push)
     s1, s2 = [], FixedStack(100)
     for _ in range(num_push):
         e = randint(0, 30)
         s1.append(e)
         s2.push(e)
     for _ in range(num_pop):
         s1.pop()
         s2.pop()
     self.assertEqual(s1, s2._xs[:s2._top + 1])
from enum import Enum
from fixed_stack import FixedStack

Menu = Enum('Menu', ['Push', 'Pop', 'Peek', 'Search', 'Dump', 'Exit'])


def select_menu() -> Menu:
    s = [f'({m.value}){m.name}' for m in Menu]
    while True:
        print(*s, sep=' ', end='')
        n = int(input(": "))
        if 1 <= n <= len(Menu):
            return Menu(n)


s = FixedStack(64)

while True:
    print(f'current number of data: {len(s)} / {s.capacity}')
    menu = select_menu()

    if menu == Menu.Push:
        x = int(input('value: '))
        try:
            s.push(x)
        except FixedStack.Full:
            print('stack is full')

    elif menu == Menu.Pop:
        try:
            x = s.pop()
from enum import Enum
from fixed_stack import FixedStack

Menu = Enum('Menu', ['push', 'pop', 'peek', 'find', 'dump', 'exit'])


def select_menu() -> Menu:
    s = [f'({m.value}){m.name}' for m in Menu]
    while True:
        print(*s, sep='   ', end='')
        n = int(input(': '))
        if 1 <= n <= len(Menu):
            return Menu(n)


s = FixedStack(64)  # 최대 64개의 데이터를 push 할 수 있는 스택

while True:
    print(f'현재 데이터 개수: {len(s)} / {s.capacity}')
    menu = select_menu()

    if menu == Menu.push:
        x = int(input('데이터를 입력 하세요. : '))
        try:
            s.push(x)
        except FixedStack.Full:
            print('Stack is full..')

    elif menu == Menu.pop:
        try:
            x = s.pop()
from enum import Enum
from fixed_stack import FixedStack

Menu=Enum('Menu',['푸시','팝','피크','검색','덤프','종료'])

def select_menu()->Menu:
    s=[f'({m.value}){m.name}'for m in Menu]
    while True:
        print(*s, sep=' ',end='')
        n=int(input(': '))
        if 1<=n<=len(Menu):
            return Menu(n)

s=FixedStack(64)

while True:
    print(f'현재 데이터 개수: {len(s)} / {s.capacity}')
    menu = select_menu()

    if menu==Menu.푸시:
        x=int(input('데이터를 입력하세요: '))
        try:
            s.push(x)
        except FixedStack.Full:
            print('스택이 가득 차 있습니다.')

    elif menu==Menu.팝:
        try:
            x=s.pop()
            print(f'팝한 데이터는 {x}입니다.')
        except FixedStack.Empty:
from fixed_stack import FixedStack

Menu = Enum('Menu', ['push', 'pop', 'peek', 'search', 'dump', 'exit'])


def select_menu() -> Menu:
    """메뉴 선택"""
    s = [f'({m.value}){m.name}' for m in Menu]
    while True:
        print(*s, sep=' ', end='')
        n = int(input(': '))
        if 1 <= n <= len(Menu):
            return Menu(n)


s = FixedStack(64)  # 최대 64개를 푸시할 수 있는 스택

while True:
    print(f'현재 데이터 개수: {len(s)} / {s.capacity}')
    menu = select_menu()  # 매뉴 선택

    if menu == Menu.push:  # push
        x = int(input('데이터를 입력하세요: '))
        try:
            s.push(x)
        except FixedStack.Full:
            print('스택이 가득 차 있습니다.')

    elif menu == Menu.pop:  # pop
        try:
            x = s.pop()
Exemple #9
0
from fixed_stack import FixedStack

Menu = Enum('Menu',['푸시','팝','피크','검색','덤프','종료'])

#Menu 선택 함수
def select_menu() -> Menu:

    s = [f'({m.value}){m.name}'for m in Menu]
    while True:
        print(*s,sep=' ',end='')
        n = int(input(": "))
        if 1<= n <=6:
            return Menu(n)


s = FixedStack(64)

while True:
    print("현재 데이터 갯수: {} / {}".format(len(s),s.capacity))
    menu = select_menu()

    if menu == menu.푸시:
        value = int(input("푸시 데이터:"))
        try:
            s.push(value)
        except FixedStack.Full:
            print('스택이 꽉 차 있습니다.')

    elif menu == menu.팝:
        try:
            x = s.pop()
Exemple #10
0
Menu = Enum('Menu', ['푸시', '팝', '피크', '검색', '덤프', '종료'])  # 메뉴를 선언


def select_menu() -> Menu:
    # 메뉴 선택
    s = [f'({m.value}){m.name}' for m in Menu]

    while True:
        print(*s, sep='   ', end='')
        n = int(input(': '))

        if 1 <= n <= len(Menu):
            return Menu(n)


s = FixedStack(64)  # 크기가 64인 스택

while True:
    print(f'현재 데이터 개수: {len(s)} / {s.capacity}')
    menu = select_menu()  # 메뉴 선택

    if menu == Menu.푸시:  # 푸시
        x = int(input('데이터를 입력하세요.: '))

        try:
            s.push(x)
        except FixedStack.Full:
            print('스택이 가득 차 있습니다')

    elif menu == Menu.팝:  # 팝
        try:
Exemple #11
0
#고정길이 스택 클래스 FixedStack 사용하기

from enum import Enum
from fixed_stack import FixedStack

Menu = Enum('Menu',['Push', 'Pop','Searching','Peek','Dump','Quit'])

def select_menu() ->Menu:
    s = [f'({m.value}){m.name}' for m in Menu]
    while True:
        print(*s, sep='   ',end='')
        n = int(input(': '))
        if 1 <= n <= len(Menu):
            return Menu(n)

s = FixedStack(64) #Stack can be push Max to 64

while True:
    print(f'The number of data: {len(s)} / {s.capacity}')
    menu = select_menu() #메뉴선택

    if menu == Menu.Push:
        x = int(input('Input the data: '))
        try:
            s.push(x)
        except FixedStack.Full:
            print("Stack is Full")

    elif menu == Menu.Pop:
        try:
            x = s.pop()