1、带尾指针的循环链表表示队列,写出出队和入队算法:
#define MAXSIZE 50
typedef struct LNode{ //定义链表结点
int data;
struct LNode *next;
}LNode,*Linklist;
LinkList Head; //全局变量链表头
LinkList IniList() //构造链表
{
static LinkList head;
head *(LinkList)malloc(sizeof(Lnode));
if(!head)
exit (OVERFLOW);
head->next = NULL;
return head;
}
status CreatList(LinkList head,int m)
{
LinkList p,q;
int i;
p = head;
for(i=1;i<50;i++)
q -> next = NULL;
p -> next = q;
p = p -> next;
if(i==M){
p -> next = Head ->next;
}
return OK;
}
//入队
int EnterQueue(Linklist &Q,int x)
{
Node *s;
s = (Node*malloc(sizeof(Node)));
if(s!=NULL)
{
s -> data = x;
s -> next = Q -> rear -> next;
Q -> rear -> next = s;
Q -> rear = s;
return 1;
}
else
return -1;
}
//出队:
int DelQueue(LinkList &Q,int &x)
{
if(Q -> rear -> next != Q) //判断队列是否为空
{
Node *p;
p = Q->rear->next->next;
Q->rear->next->next=p->next;
x = p->data;
free(p);
return1;
}
else
return -1;
}
2、已知树采用孩子-兄弟的二叉链表存储,编写算法,按层次输出所有结点:
int layerorder(