# 常见的基本数据结构——表

struct Node;
typedef struct Node *PtrToNode;
typedef PtrToNode List;
typedef PtrToNode Position;

struct Node{
ElementType Element;
Position Next;
};

int
IsEmpty(List L){
return L->Next == NULL;
}

int
IsLast(Position P,List L){
return P->Next == NULL;
}

Find查找函数

Position
Find(ElementType X, List L){
Position p;
P = L->Next;
while(p != NULL && p->Element != X){
p = p->Next;
}
return p;
}

void
Delete(ElementType X, List L){
Position p, TepCell;
p = FindPrevious(X);
if(!IsLast(P, L)){
TmpCell = p->Next;
p->Next = TmpCell->Next;
free(TmpCell);
}
}

Position
FindPrevious(ElementType X, List L){
Position P;
P = L;
while(P->Next != NULL && P->Next->Element != X){
p=p->next;
}
return P;
}


void
Insert(ElementType X, List L, Position P){
Position TmpCell;
TmpCell = malloc(sizeof(Struct Node));
if(TMpCell == NULL){
FatalError(”out of space”);
}
TmpCell->Element = X;
TmpCell->Next = P->Next;
P->Next = TmpCell;
}

void
DeleteList(List L){
Position P, Tmp;
P = L->Next;
L->Next = NULL;
while(P != NULL){
Tmp = P->Next;
free(P);
P = Temp;
}
}

typedef struct{
int Coeffarray[MaxDegree + 1];
int HighPower;
}* Polynomial;

//将多项式初始化为0的过程
void
ZeroPolynomial(Polynomial Poly){
int i;
for(i=0; i<=MaxDegree; i++){
Poly->CoffArray[i] = 0;
}
Poly->HighPower = 0;
}

void
AddPolynomial(const Polynomial Poly1, const Polynomial Poly2, Polynomial PolySum){
int i;
ZeroPolynomial(PolySum)
PolySum->HighPower = Max(Poly1->HighPower, Poly2->HighPower);
for(i=PolySum->HighPower; i>=0; i++){
PolySum->CoeffArray[i] = Poly1->CoeffArray[i] + Poly2->CoeffArray[i];
}
}

void
MultPolynomial(onst Polynomial Poly1, const Polynomial Poly2, Polynomial PolyProd){
int i, j;
ZeroPolynomial(PolyProd);
PolyProd->HighPower = Poly1->HighPower + Poly2->HighPower;
if(PolyProd->HighPower > MaxDegree){
Error(Except array size);
}else{
for(i=0; i<=Poly1->HighPower; i++){
for(j=0; j<=Poly2->HighPower; j++){
PolyPord->CoeffArray[i + j] = Poly1->CoeffArray[i] * Poly2->CoeffArray[j];
}
}
}
}

typedef struct Node *PtrToNode;
struct Node{
int Coefficient;
int Expoent;
PtrToNode Next;
};
typedef PtrToNode Polynomial;

 0 1 512 343 64 125 316 27 8 729 0 1 2 3 4 5 6 7 8 9

 8 1 0 216 512 729 27 125 343 64 0 1 2 3 4 5 6 7 8 9

 67 27 8 1 0 125 216 343 512 729 0 1 2 3 4 5 6 7 8 9

1.计算待排序数组的最大位数。

2.对桶数组和下表数组进行初始化，根据位数进行循环。

3.根据当前的位数，对待排数组进行遍历，计算出当前位的数值，根据数值将其放入对应的桶数组中，并更新下表数组。

4.将桶数组中的元素更新到待排数组中，

5.更新位数计算，跳转至2步骤，直至位数大于最大位数。

1.数据存储在一组结构体中，每个结构体含有指向下一个结构体的指针。

2.一个新的结构体可以通过调用malloc从系统中得到，并通过调用free而被释放。

struct Node{
ElementType Element;
Position Next;
}
struct Node CursoSpace[SpaceSize];

static Position
CoursorAlloc(void){
Position P;
P = CoursorSpace[0].next;
CursirSpace[0].Next = CursorSpace[P].next;
return P;
}
static void
CursorFree(Position P){
CursorSpace[P].next = CursorSpace[0].next;
CursorSpace[0].next = P;
}

 slot Element Next 0 - 6 1 b 9 2 f 0 3 header 7 4 - 0 5 header 10 6 - 4 7 c 8 8 d 2 9 e 0 10 a 1
 slot Element Next 0 - 6 1 b 9 2 f 0 3 header 7 4 - 0 5 header 10 6 - 4 7 c 8 8 d 2 9 e 0 10 a 1
判断链表是否为空
int IsEmpty(List L){
return CursorSpace[L].Next == 0;
}

int IsLast(Position P, List L){
return CursorSpace[P].Next == 0;
}

Position Find(Element X, List L){
Position P;
P = CursorSpace[L].Next;
while(P && CursorSpace[P].Element != X){
P = CursorSpace[P].Next;
}
reutrn P;
}

void Delete(Element X, List L){
Position P, TmpCell;
P = FindPrevious(X, L);
if(!IsLast){
TmpCell = CursorSpace[P].Next;
CursorSpace[P].Next = CursorSpace[TmpCell].Next;
CursorFree(TmpCell);
}
}
posted @ 2020-01-14 21:41  Baby-Lily  阅读(1043)  评论(0编辑  收藏