欢迎各种大侠进
程序代码:/*
*单循环链表的基本操作
*/
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
};
struct node *temp;
//初始化链表
struct node *initList_link()
{
struct node *head;
head=(struct node *)malloc(sizeof(struct node));
if(NULL==head)
{
exit(-1);
}
head->next=head;
return head;
}
//添加结点
void add(struct node *head,struct node *pCurrent)
{
pCurrent->next=head->next;
head->next=pCurrent;
}
//向链表中添加结点
void add_node(struct node *head,struct node *pCurrent)
{
add(head,pCurrent);
}
//删除结点 返回被删的上一个结点
struct node *delet(struct node *p,struct node *pCurrent )//???????????看看是不是有逻辑错误
{
temp=pCurrent->next;
pCurrent->next=temp->next;
p=temp->next->next;
return p;
}
//从链表中删除某结点 与data数值相同的
void delet_node(struct node *head,int data)
{
struct node *p;
temp=head->next;
while(temp!=head)
{
if(data==temp->data)
{
p=delet(temp->next,temp->next->next);
free(temp);
temp=p;
}
temp=temp->next;
}
}
//修改链表中结点与data值相同的数据
void change_node(struct node *head,int data,int newValue)
{
temp=head->next;
while(temp!=head)
{
if(data==temp->data)
{
temp->data=newValue;
}
temp=temp->next;
}
}
//删除整个链表
void delet_list(struct node *head)
{
//struct node *p;
temp=head->next;
while(temp!=head)
{
delet(temp->next,temp->next->next);
free(temp);
temp=head->next;
}
free(head);
head=NULL;
printf("删除成功!\n");
}
void print_list(struct node *head)
{
temp=head->next;
while(temp!=head)
{
printf("%d ",temp->data);
temp=temp->next;
}
printf("\n");
}
void function()
{
struct node *head=NULL;
struct node *temp=NULL;
int index=10;
printf("初始化链表\n");
head=initList_link();
printf("打印该循环链表:");
print_list(head);
printf("向链表中连续插入%d个元素\n",index);
while(index)
{
temp=(struct node *)malloc(sizeof(struct node));
temp->data=index--;
add_node(head,temp);//向链表中添加结点
}
printf("打印循环链表:");
print_list(head);
printf("\n\n删除数据为3的结点\n");
delet_node(head,3);
printf("打印循环链表:");
print_list(head);
printf("\n\n修改数据为3的结点 新值为18\n");
change_node(head,3,18);
printf("打印循环链表");
print_list(head);
printf("\n\n删除整个链表\n");
//delet_list(head);
}
int main()
{
function();
return 0;
}
申明下这是模仿别人的,



这个好像木有问题,咋执行不了呢
