数据结构.....

来源:百度知道 编辑:UC知道 时间:2024/05/05 18:39:36
那位高手会作以下题目???????

1.假设以带头结点的循环链接表表示队列,并且只设一个指向队尾结点的指针,请给出进出队的完整的程序。

2、假设有 N 个栈共同使用一块顺序存储的空间,为简单起见可设为共同使用

数组 int a〔200〕。初始状态为各栈等分所有的空间。每当有某栈上溢

时,将其余各栈的剩余空间 均匀分配给各栈,这样就必然使得堆栈发生移

动。请给出这种情况下的出、入栈实现程序

1.

#define OVERFLOW -2
#define NULL 0
typedef struct QNode{
int data;
struct QNode *next;
}QNode,*QueuePtr;

typedef struct {
QueuePtr front;
QueuePtr rear;
}LinkQueue;

int InitQueue(LinkQueue *q){
q->front=q->rear=(QueuePtr)malloc(sizeof(QNode));
if (!q->front) exit (OVERFLOW);
q->front->next=NULL;
printf("Queue has been created!\n");
return 1;
}

int DestroyQueue(LinkQueue *q){
while(q->front){
q->rear=q->front->next;
free(q->front);
q->front=q->rear;
}
printf("Queue has been Delete!\n");
return 1;
}

int EnQueue(LinkQueue *q){
QueuePtr p;
int e;
p=(QueuePtr)malloc(sizeof(QNode));
if(!p) exit (OVERFLOW);
printf("\nInput the data:");
scanf("%d",&e);
p->data=e;
p->n