반응형

배열로 구현된 리스트 테스트

https://pythontutor.com/render.html#mode=display

array = [None] * 10
size = 0
def isEmpty():
    if size == 0: return True
    else : return False

def isFull():
    return size == 10

def insert(pos, e):
    global size
    if not isFull() and 0<=pos<=size:
        for i in range(size, pos, -1):
            array[i] = array[i-1]
        array[pos] = e
        size += 1

def delete(pos):
    global size
    if not isEmpty() and 0<=pos<size:
        e=array[pos]
        for i in range(pos, size-1):
            array[i] = array[i+1]
        size -= 1
        return e

insert(0, 10)
insert(0, 20)
insert(1, 30)
insert(3, 40)
insert(2, 50)
print('insert', array[0:size])
delete(2)
print('delete(2)', array[0:size])
delete(3)
print('delete(3)', array[0:size])
delete(0)
print('delete(0)', array[0:size])