Exercises (Practice) for stack
- Karla G
- 28 mar 2015
- 1 Min. de lectura
Questions:
1.- Which of the options below, are stacks?
Pile of boxes
Music Reproduction (playlist)
The sheets in a printer
Waiting for your turn in a game
Taking books from a pile
Using Ctrl+Z in a Word document
2.- What kind of order does the Stack respects?
FILO (First in, Last Out)
FIFO (First in, First Out)
3.- Write the pseudocode of a function that returns TRUE when the stack has an empty space where you can still push an element.
Answers:
1.- Pile of boxes, sheets in a printer, taking books from a pile, using Ctrl+Z in a word document.
Why? Because they are all piles where the first uotput, will always be the last element that entered to the pile. In order to carry boxes, you have to take the ones at the top first. When printing, the first page printed will be the last page of the document. Using Ctrl+Z will erase your last movement.
2.- FILO. First in, last out. As it was commented at the previous answer.
3.-
Empty(){
boolean space=FALSE;
for(int i=0; i<STACK.SIZE; i++){
if(Stack[i].isNotEmpty){
space=space;
}
else{
space=TRUE;
}
}
}
Comentarios