标签:
Linear Data Structures:
- Stacks
- Queues
- Deques
- Lists
The names given to the ends are not significant. What distinguishes one linear structure from another is the way in which items are added and removed, in particular the location where these additions and removals occur.
What is a Stack?
A stack (sometimes called a “push-down stack”) is an ordered collection of items where the addition of new items and the removal of existing items always takes place at the same end(top). The end opposite the top is known as the "base".
Items stored in the stack that are closer to the base is the longest, the most recently added item is the position to be removed first.(LIFO, last in first out).
The Stack Abstract Data Type
- stack() create a new stack that is empty. It needs no parameters and returns an empty stack.
- push(item) adds a new item to the top of the stack. It needs the item and returns nothing.
- pop() removes the top item from the stack. It nees no parameters and returns the item. The stack is modified.
- peek() returns the top item from the stack but does not remove it. It needs no parameters. The stack is not modified.
- isEmpty() tests to see whether the stack is empty. It needs no paraemters and returns a boolean value.
- size() returns the number of items on the stack. It needs no parameters and returns an integer.
What is Queue?
A queue is an ordered collection of items where the addition of new items happens at one end, called the “rear,” and the removal of existing items occurs at the other end, commonly called the “front.” (FIFO, First In First Out)
The Queue Abstract Data Type
- Queue() creates a new queue that is empty. It needs no parameters and returns an emtpy queue.
- enqueue(item) adds a new item to the rear of the queue. It needs the item and returns nothing.
- dequeue() removes the front item from the queue. It needs no parameters and returns the item. The queue is modified.
- isEmpty() tests to see whether the queue is empty. It needs no parameters and returns a boolean value.
- size() returns the number of items in the queue. It needs no parameters and returns an integer.
What is Deque(double-ended queue)?
it has two ends, a front and a rear, and the items remain positioned in the collection. What makes a deque different is the unrestrictive nature of adding and removing items.
The Deque Abstract Data Type
- Deque() create a new deque that is empty. It needs no parameters and returns an empty deque.
- addFront(item) adds a new item to the front of the deque. It needs the item and returns nothing.
- addRear(item) adds new item to the rear of the deque. It needs the item and returns nothing.
- removeFront() removes the front item fron the deque. It needs no parameters and returns the item. The deque is modified.
- removeRear() removes the rear item fron the deque. It needs no parameters and returns the item. The deque is modified.
- isEmpty() tests to see whether the deque is empty. It needs no parameters and returns a boolean value.
- size() returns the number of items in the deque. It needs no parameters and returns an integer.
Algorithm - Linear Structures
标签:
原文地址:http://www.cnblogs.com/elewei/p/5621833.html