You are on page 1of 4

Stack

Linked List Implementation

IS EMPTY
start
is Empty(reference to the stack)
1. if stack->top == null
return 1
2. else
return 0
end

PEEK
start
peek(reference to the stack)
1. if stack->top == null
return error message “stack is empty”
2. else
return stack->top
end

PUSH
start
push(reference to the stack,value)
1. cerate a newNode od type node
2. newNode->val = value
3. if stack->top == null
stack->top = newNode
newNode->next = null
4. else
newNode->next = top
top = newNode
end
POP
start
pop(reference to the stack)
1. if stack->top == null
return error message “stack is empty”

2. else
create a tempNode of type reference npde
tempNode = stack->top
if stack->top->next == null
delete tempNode
stack->top = null
else
stack->top = tempNode->next
delete tempNode
return tempNode

end

DISPLAY
strat
display(reference to the stack)
1. create tempNode of type reference node
2. tempNode = stack->top
3. if(tempNode == null)
return error message “stack is empty”
4. else
while(tempNode != null)
print tempNode->value
tempNode = tempNode->next
end while
end
Queue

Linked List Implementation

IS EMPTY
start
is Empty(reference to the queue)
1. if queue->front == null
return 1
2. else
return 0
end

ENQUEUE
start
enqueue(reference to the queue,value)
1. create newNode ot type node
2. newNode->val = value
3. if queue->front == null
queue->front = queue->rear = newNode
newNode->next = null
4. else
newNode->next = queue->rear
rear = newNode
end

DEQUEUE
start
dequeue(reference to the queue)
1. if queue->front == null
return error message “queue is empty”
2. else
create tempNode of type reference node
tempNode = queue->front
if tempNode->next == null
delete tempNode
queue->front = queue->rear = null
else queue->front = tempNode>next
return tempNode

DISPLAY
strat
display(reference to the queue)
1. create tempNode of type reference node
2. tempNode = queue->front
3. if(tempNode == null)
return error message “queue is empty”
4. else
while(tempNode != null)
print tempNode->value
tempNode = tempNode->next
end while
end

You might also like