Title: Abstract Data Type
1??? ?????? ????? (Abstract Data Type)
- ????? ???? ?????? ?? ??????? ??????? ????, ???
???? ??????, ???? - ??? ?????? ????? .(ADT)
- ??? ???? ????? ?????? ???? ADT ?????
2?????? Stack???? ???? ?? ?????? ???? ?????
?????? ??? ??? ???, ????? ??? ???????.??????
????? ??? ?????? ????. LIFO last in first
out))
3?????? ??????? ?? ??????
- Push(x) ????? ???? ???? ???? ???????
- Pop() ? value ????? ???? ???? ???? ???????
- MakeEmptyStack( )?Ptr ????? ???????
- IsEmptyStack() ????? ??? ??????? ????
- Top() ? value ????? ??? ????? ???? ???????
4????? ?????? ???????
- ???? ?? ?????? ??? (15)3 (infix)
- ???? ??? ??????? (postfix) 1 5 3
- ????? ??????? ??? ???? ????
5????? ?????? ???????????? ????? ?-postfix
- ???? ?????? ???? 1 5 3
- ?? ???? --- ??????? ???????
- ??? ?????
- ??????? 2 ?????? ????????
- ?????? ?????
- ??????? ????? ???????
- ???? ????? ??????? ????? (?????) ???? ???????
??? ??????.
6????? ?????? ??????????? ??????? 1 5 3
- Push(1)
- Push(5)
- Pop(5)
- Pop(1)
- 51
- Push(6)
- Push(3)
- Pop(3)
- Pop(6)
- 36
- Push(18)
7????? ?????? ??????? ????? ?????? ???? ?????
- main f g
- X?5 a?2 v?3
- f(X) b?g(a) w?5
- Z?8 c?4
-
8????? ?????? ???????????? ?????? ???? ?????
- ???? program counter (?????? pc) ????, ???? ????
?? ????? ?????? ???? ?????. - ???? ????? ??????, ?-pc ???? ?? ????? ??????
???????. - ????? ????
- ????? ?????? ?- cpu
- ????? ?-pc ?????? ????
- ???? ?????? ?????? ?- cpu
- ????? ??????? ??? ????? ????????
- ????? ?-pc ?????? ????
- ????? ??? ?- pc ???????
- ????? ????? ?????? ??????? ?? ???????? ?- pc
- ?????? ?????????
- ????? ??? ???????? ??????? ?- pc
- ?? ?????? ???????? ???????? ???? - ??????
9????? ?????? ??????????? ???????
- main f g
- X?5 a?2 v?3
- f(X) b?g(a) w?5
- Z?8 c?4
- Push(pc ? z ? 8)
- Push(pc ? c ? 4)
- Pc ? Pop() / c ? 4 /
- Pc ? Pop() / z ? 8 /
- Pc ? Pop() / ??? ??????? ???? ... ??????!/
10?????? ???????? ?? ??????
???? (?????? ????) ????? ?????? (?????? ??
????)
11class Stack int stack // pointer to the
data int head // head of stack int size
// size of stack //............................
............................... public
Stack(int n) stack new intn head
0 this.n n //.........................
................................. public boolean
empty() return (head 0)
//................................................
......... public boolean full() return
(head n)
12 public int pop() if (this.empty())
System.out.println("The stack is empty")
//underflow error return 0 else
int el stackhead-1 head--
return el //........................
................................... public void
push(int el) if (this.full())
System.out.println("The stack is
full")//overflow error else
stackhead el head
//.............................................
..............
13//................................................
........... public static void main(String
args) Stack s new Stack (5)
for(int i0ilt7i) s.push(i)
for(int i0ilt6i) System.out.println(s.po
p()" ")
The stack is full The stack is full 4 3 2 1 0
The stack is empty 0 Process Exit...
14??? ADT (Queue)???? ???? ?? ??????? ????
????? ??? ??? ???, ????? ??? ???? ?????
??? ???? ???? ????? ??? ????.????? ?????? ?????
??? ?????? ????. FIFO first in, first -out))
15?????? ??????? ?? ????
- Front() ? value ????? ??? ????? ?????
???? - Dequeue() ? value ????? ???? ???? ???? ????
- Enqueue(x) ????? ???? ???? ???? ????
- MakeEmptyQueue( ) ????? ????
- IsEmptyQueue() ????? ??? ???? ???
16??????? ???
17?????? ???????? ?? Queue ?? ??? ????
(?????? ????) ????? ?????? (?????? ?? ????)
18??? ADT ?????? (Priority Queue)?? ???? ????
??? ???? ?????? - Priority???? ???? ?? ??????
???? ????? ??? ??? ??? ????? ??? ????
????.????? ??? ??????? ??????? (???????) ???
?????? ????.
19?????? ?? ??? ??????
- Maximum() ? value ?????? ?? ????? ??? ???????
??????? - Extract_Max() ? value ?????? ?? ????? ???
??????? ??????? - AddPriorityQueue (x) ????? ???? ????
MakeEmptyPriorityQueue( ) ????? ???? - IsEmptyPriorityQueue( ) ????? ??? ???? ???
- PriorityQueueSort(set X ) ???? ??????? ???
???????????
20??????? ???? ??????
- to schedule jobs on a shared computer
- When a job is finished, the highest-priority job
is selected from the pending (by Extract_Max()) - A new job can be added to the queue at any time
- (by AddPriorityQueue())
-
21???? ?????
- ??????
- ????? ?? ?????? ??????
- ??? (???? ?????)
- ?"? ???? ADT ??? ???? ??? ???? (?? ?? ?? ????)
22????? ADT (List) ??? ????? ??
???????Lx1,x2,, xnL ???? ???? ????? .
23?????? ???????? ?? ????? ?? ??? ????
(?????? ????) ????? ?????? (?????? ?? ????)
24class lista public static void main(String
args) List startnew List(3)
System.out.println(start.listlength())
start.printList() System.out.println("New
List") start.insertPosition(2, new
Parit(6)) start.printList()
System.out.println(start.listlength())
//main
253 key's value is 0.8776167367223046 key's value
is 0.4333956942608199 key's value is
0.08391059456146222 New List key's value is
0.8776167367223046 key's value is
0.4333956942608199 key's value is 6.0 key's value
is 0.08391059456146222 4 Process Exit...
26 class Parit private double key private
Parit nextnull public Parit(double
val)keyval public double getKey() return
key public Parit getNext() return next
public void setNext(Parit newItem)nextnewItem
public void show()System.out.println("key's
value is " getKey()) public void
connect() double goralMath.random()
nextnew Parit(goral)
27class List private Parit headnull public
Parit getHead()return head public List(int
numberItems) int i if (numberItemsgt0)
headnew Parit(Math.random()) Parit
phead for(i1iltnumberItemsi)
p.connect() pp.getNext() //List
28 public int listlength() int count0
Parit phead while (p!null)
countcount1
pp.getNext() return
count public void printList() Parit
phead while (p!null)
p.show() pp.getNext()
29public void insertPosition(int position, Parit
newItem) Parit phead Parit prevnull if
((position0)(pnull))
headnewItem return //insert to 0 position of
empty list boolean check(positiongtthis.listlengt
h()-1)
30if (check) System.out.println("Impossible
insert") else if (positiongt0)
for(int i0iltpositioni)
prevp pp.getNext()
newItem.setNext(p) prev.setNext(newItem)
else newItem.setNext(p)
headnewItem
31?????? ??????? ?? ??????????? ???????
- Head() ? Ptr
- Next(Ptr) ? Ptr ????? ?? ????? ???
- Prev(Ptr) ? Ptr
- Key(Ptr) ? value
- Insert(Ptr,newPtr) ? Head()
- Delete(Ptr) ? Head()
- MakeEmptyList() ????? ??????
- Length() ? value
- Outside(Ptr) ? boolean ??? ???? ???????
32?????? ??????? ?? ??????????? ???????
- Access(index)?value
- ListSearch(value)?Ptr
- IsEmptyList() ????? ??? ?????? ????
33?????? ??????? ?? ??????????
- ListSearch(value)Ptr
- Ptr x ? Head()
- While (not Outside(x)) and Key(x) ltgt value
- x ? Next(x)
- If Outside(x)
- Return nil
- Else
- Return x