是的
建立单向循环链表的代码:
#include
#include
typedef struct _A{
int data;
struct _A *next;
}A;
typedef A* IA;
void createDoubleLink(IA *header) {
int data;
IA p;
printf("input data end with -1:");
scanf("%d", &data);
while(data != -1) {
p = (IA)malloc(sizeof(A));
p->data = data;
if(*header == NULL) {
*header = p;
(*header)->next = *header;
}
else{
IA q = *header;
while(q->next != *header) {
q = q->next;
}
q->next = p;
q->next->next = *header;
}
scanf("%d", &data);
}
}
void print(IA header) {
IA p = header;
if(header == NULL) return;
while(1){
printf("%d\t", p->data);
if(p->next == header) break;
p = p->next;
}
printf("\n");
}
int main()
{
IA header = NULL;
createDoubleLink(&header);
print(header);
return 0;
}
头结点的意思是链表的第一个节点,但这个节点不保存数据。
温馨提示:答案为网友推荐,仅供参考