算法导论笔记(三)

Quick-Sort && Stack

Quick-Sort(快速)

1
2
3
4
5
6
7
8
9
10
11
12
13
PARTITION(A,p,r)
x=A[r]
r=p-1
for(j=p; j<r; j++)
{
if(A[j]<=x)
{
i++
exchange A[i] with A[j]
}
}
exchange A[i+1] with A[r]
return i+1

Stack(栈)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Stack-Empty(s) (置空)
if(s.top==0)
{
return True
}else
return False
Push(s,x) (进栈)
s[s.top++]=x
Pop(s) (出栈)
if(Stack-Empty(s))
{
error "underflow"
}else
s.top--
return s.[s.top++]