You are on page 1of 22

(Data Structures)

: .
: .
.
.


LIFO: Last In - First Out
( )
:
( )

2010/11, 4:

-
:
Web browser: .
: (undo).
Java Virtual Machine:
.
:
.

2010/11, 4:


:
Create: .
IsEmpty: (boolean) true , false .
Top: .
Push (or Add): .
Pop (or Delete): .
:
.

2010/11, 4:

:

.

Algorithm size()
return t + 1
Algorithm pop()
if isEmpty() then
throw EmptyStackException
else
tt1
return S[t + 1]

2010/11, 4:

:
.
head.
: (Push) / (Pop)

2010/11, 4:

:
(1).
top maxCapacity.
: (n).
.

: ;

.

2010/11, 4:


(call stack execution stack run-time stack)
() .


. ,
.


(activation record)
:
(
).

.

.

.
.
2010/11, 4:

Hanoi
( ;) [E. Lucas 1883].
,
.
64 .

:
1) .
2)
.
3) .

2010/11, 4:

Hanoi
:
n 1 n-1 3
2 n-2 1
2
( ):
3 : 7 23- 1 .
4 : 15 24- 1 .

64 : 264-1 .
n : 2n -1 .

2010/11, 4:


FIFO: First In - First Out
( ).
:
.
(front) (rear).

2010/11, 4:

-
(.. )
:
.
- .
Routing buffers.

:
.
2010/11, 4:


:
Create: .
Add (or Enqueue or Queue)(): .
Delete (or. Dequeue)(): .
First(): .
Last(): .

2010/11, 4:

:
(.. front)
(.. rear) .

location(i)=front+i-1

2010/11, 4:

:
: (Enqueue) / (Dequeue)

2010/11, 4:

:
front rear.
( ).
( )

2010/11, 4:

:
:
class LinkedQueue {
// FIFO objects
public:
LinkedQueue()
{front = rear = 0;}; // constructor
~LinkedQueue(); // destructor
int IsEmpty() {return ((front) ? 0 : 1);}
int IsFull();
int First(type& x); // return first element of queue
int Last(type& x); // return last element of queue
int operator +(type x); // add x to queue
int operator -(type& x); // delete x from queue
// First,+,- return 0 on failure, 1 on success
private:
Node<type> *front, *rear;
}
2010/11, 4:

-
- .

2010/11, 4:

-
.

2010/11, 4:

location(i)=(front+i)%MaxSize

2010/11, 4:

(Priority Queues)
P
/
( ) (.. ;)
:
Heapsort.
.
Dijkstra

2010/11, 4:


, C++, S. Sahni, , 2004.

, , , .. .,
, 2002.

, . , 2006.

Hanoi: http://en.wikipedia.org/wiki/Tower_of_Hanoi

2010/11, 4: