Stacks, queues and linked lists by Mikko Karvonen

Stacks, queues and linked lists by Mikko Karvonen -...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
1.12.2003 Stacks, queues and linked lists Mikko Karvonen mkarvonen@iua.upf.es
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Elementary Data Structures ± Stacks, queues and linked lists are elementary data structures that are based on pointers between some of the elements. These pointers are links to the first or last element in the set, to an element’s previous or next element and so on. ± Stacks and queues are dynamic sets in which the element removed from the set by DELETE operation is pre- specified. In linked lists, you must select or search the element to be removed. ± In stacks, the most recently inserted element is deleted = last-in, first-out (LIFO) ± And in queues, the element that has been in the set for the longest time is deleted = first-in, first-out (FIFO)
Background image of page 2
Stacks (1/2) ± In stacks, the basic operations INSERT and DELETE are called PUSH and POP, respectively, to match the physical world. The book uses an analogy of a stack of plates in a cafeteria; the plate that has been put in the stack most recently has to be taken out first. ± A stack can be constructed using an array: array S[1. .n] attribute top[S] –indexes the element at the top so a stack is an array S[1. .top[S]] .
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Stacks (2/2) ± Stack operations in pseudo-code: STACK-EMPTY(S) if top[S] = 0 return true else return false PUSH(S, x) top[S] <- top[S] + 1 S[top[S]] <- x POP(S) if STACK-EMPTY(S) then error ”underflow” else top[S] <- top[S] – 1 return S[top[S] + 1] The running time for the operations is O(1) (constant time).
Background image of page 4
Queues (1/2) ± In queues, the INSERT and DELETE operations are called ENQUEUE and DEQUEUE. As the POP operation of the stack, the
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/25/2010 for the course CPE CPE 360 taught by Professor Jenniferchen during the Spring '10 term at Stevens.

Page1 / 16

Stacks, queues and linked lists by Mikko Karvonen -...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online