单向循环链表
数据类型
typedef int DataType;
typedef struct node
{
DataType data;
struct node *next;
}LoopNode;
常用操作
1.创建空循环链表,只有头结点,头结点指针域指向自己
LoopNode *create_empty_looplist()
{
}
2.头插法
int insert_head_looplist(LoopNode *head,DataType data)
{
}
3.输出循环链表所有结点数据
int print_looplist(LoopNode *head)
{
注意循环结束条件
数据类型
typedef int DataType;
typedef struct node
{
DataType data;
struct node *next;
}LoopNode;
常用操作
1.创建空循环链表,只有头结点,头结点指针域指向自己
LoopNode *create_empty_looplist()
{
}
2.头插法
int insert_head_looplist(LoopNode *head,DataType data)
{
}
3.输出循环链表所有结点数据
int print_looplist(LoopNode *head)
{
注意循环结束条件
}
#include <stdio.h>
#include <stdlib.h>
typedef int DataType;
typedef struct node
{
DataType data;
struct node *next;
}LoopNode;
LoopNode *create_empty_looplist()
{
LoopNode *head = NULL;
head = (LoopNode *)malloc(sizeof(LoopNode));
head->next = head;
return head;
}
int is_empty_looplist(LoopNode *head)
{
return head->next == head;
}
int insert_head_looplist(LoopNode *head,DataType data)
{
LoopNode *temp = NULL;
temp = (LoopNode *)malloc(sizeof(LoopNode));
temp->data = data;
temp->next = head->next;
head->next = temp;
return 0;
}
int print_looplist(LoopNode *head)
{
LoopNode *p = head->next;
while(p != head)
{
printf("%d ",p->data);
p = p->next;
}
putchar('\n');
return 0;
}
int main()
{
LoopNode *head = NULL;
int i = 0;
head = create_empty_looplist();
if(is_empty_looplist(head))
{
printf("The looplist is empty.\n");
}
for(i = 0;i < 9;i++)
{
insert_head_looplist(head,i);
}
print_looplist(head);
return 0;
}