Pseudocode for algorithms Flashcards
(10 cards)
What is the pseudocode for finding the size of a stack?
size()
return top + 1
what is the pseudocode for checking if the stack is empty?
isEmpty()
if top < 0:
return True
else:
return False
endif
What is the pseudocode for checking the top item in a stack without removing it?
peek()
if isEmpty():
return error
else:
return stackname[top]
endif
What is the psuedocode for adding an item to a stack?
push(element)
top = top +1
stackname[top] = element
what is the pseudocode for removing an item off the stack?
pop()
if isEmpty():
return error
else:
toRemove = stackname[top]
stackname[top] = “ “
top = top - 1
return toRemove
endif
what is the pseudocode for checking the size of a queue?
size()
return back - front
what is the pseudocode for checking if a queue is empty?
isEmpty()
if front == back:
return True
else:
return False
endif
what is the pseudocode for returning the first item to enter a queue without removing it?
peek()
return queuename[front]
what is the pseudocode for adding an item into a queue?
enqueue(element)
queuename[back] = element
back = back + 1
what is the pseudocode for removing items from a queue?
dequeue()
if isEmpty():
return error
else:
toDequeue = queuename[front]
endif