{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Stacks, queues and linked lists by Mikko Karvonen

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

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

1.12.2003 Stacks, queues and linked lists Mikko Karvonen [email protected]

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

View Full Document
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)
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]] .

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

View Full Document
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).
Queues (1/2) In queues, the INSERT and DELETE operations are called ENQUEUE and DEQUEUE. As the POP operation of the stack, the

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### 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
Ask a homework question - tutors are online