
本文共 2839 字,大约阅读时间需要 9 分钟。
������������������������
�����������������������������������������������������������������������������������������������ck���������������������������������������������������������������������������.
���������
���������������������������������������������������������
������������
������������������������������������������������������������������������������top���������������������������������
���������
void InitStack(STstack* st) { st->top = 0; st->arr =malloc(CAP*sizeof(STData); st->capacity = CAP;}
���������
void StackPush(STstack* st, STData n) { if (st->top == st->capacity) { StackExpansion(st); } st->arr[st->top++] = n;}
���elements
STData StackPop(STstack* st) { assert(st); assert(!StackEmpty(st)); return st->arr[--st->top];}
������������stack
int StackEmpty(STstack* st) { if (st->top == 0) return 1; return 0;}
������������
void StackExpansion(STstack* st) { STData* tmp = (STData*)realloc(st->arr, sizeof(STData) * st->capacity *2); if (tmp == NULL) { printf("Expansion Error\n");��exit(-1); } st->arr = tmp; st->capacity *=2;}
������������
������������������������������������������top���������������������������
���������
void initstack(sta* a) { top= NULL;}
####������
void pushstack(sta* a, int num) { sta* p = (sta*)malloc(sizeof(sta)); p->n = num; p->point = top; top = p;}
���Stack
int popstack(sta* a) { emptystack(a); sta* des = top; top = top->point; date = des->n; free(des); des = NULL; return date;}
������������stack
void emptystack(sta* a) { if (top == NULL) { printf("Stack empty");��exit(0); }}
������������
���������������������������������������������������������������������������
���������������
������������������������������������������������������Dequeue���������������Enqueue���
���������������
void InitQueue(QUqueue* qu) { qu->Dequeue = qu->Enqueue = NULL;}
####������������
void QueuePush(QUqueue* qu, QUData n) { queue* newcell = (QUData*)malloc(sizeof(QUData)); newcell->data = n; newcell->next = NULL; if (qu->Dequeue == NULL) { qu->Enqueue = qu->Dequeue = newcell; } else { qu->Enqueue->next = newcell; qu->Enqueue = newcell; }}
���elements from������
QUData QueuePop(QUqueue* qu) { if (QueueEmpty(qu)) { printf("Queue Is Empty");��exit(-1); } QUData ret = qu->Dequeue->data; qu->Dequeue = qu->Dequeue->next; return ret;}
������������������
int QueueEmpty(QUqueue* qu) { if (qu->Dequeue == qu->Enqueue) return 1; return 0;}
������
���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
发表评论
最新留言
关于作者
