^334 2022-02-03 23:14 采纳率: 88.5%

###### 我想要达到的结果
``````
``````
``````
#include<stdio.h>
#include<stdlib.h>
typedef struct listnode{
int date;
struct listnode* next;

}list;
int main()
{
struct listnode* p;
int x;
int a;
int b;
int count;
list node1 = { 10,NULL };
list node2 = { 20,NULL };
list node3 = { 30,NULL };
list node4 = { 40,NULL };
node1.next = &node2;
node2.next = &node3;
node3.next = &node4;
p = &node1;
while (p != NULL)
{
printf("%d\n", p->date);
p = p->next;

}

printf("请输入需要查找的数");
scanf_s("%d", &x);
p = &node1;
while (p != NULL)
{
if (x == p->date)
{
printf("    找到啦      %d\n", p->date);
}
p = p->next;
}
printf("请增加一个数\n");
scanf_s("%d", &a);
printf("增加到第几个数后面\n");
scanf_s("%d", &b);
p = &node1;
while (p != NULL && b <= 4)
{
count = 0;
if (p != NULL&&count<=b)
{
count++;
p = p->next;
}
list* h;
h =  (list *) malloc(sizeof(list));
h->date = a;
h->next = p->next;
p->next = h;
}
while (p != NULL)
{
printf("%d\n", p->date);
p = p->next;

}

}
``````
``````
``````
• 写回答

#### 1条回答默认 最新

• qzjhjxj 2022-02-04 00:54
关注

改动处见注释，供参考：

``````#include<stdio.h>
#include<stdlib.h>
typedef struct listnode{
int date;
struct listnode* next;

}list;
int main()
{
struct listnode* p;
int x;
int a;
int b;
int count;
list node1 = { 10,NULL };
list node2 = { 20,NULL };
list node3 = { 30,NULL };
list node4 = { 40,NULL };
node1.next = &node2;
node2.next = &node3;
node3.next = &node4;
p = &node1;
while (p != NULL)
{
printf("%d\n", p->date);
p = p->next;

}
printf("请输入需要查找的数");
scanf("%d", &x);
p = &node1;
while (p != NULL)
{
if (x == p->date)
{
printf("    找到啦      %d\n", p->date);
break;                    //修改
}
p = p->next;
}
if(p==NULL)                       //修改
printf("未找到\n");           //修改
printf("请增加一个数\n");
scanf("%d", &a);
do{                                 //修改
printf("增加到第几个数后面\n");
scanf("%d", &b);
}while(b < 1 || b > 4);             //修改
p = &node1;
count = 1;           //修改
while (p != NULL && count < b) //while (p != NULL && b <= 4)
{
//if (p != NULL&&count<=b)
//{
count++;
p = p->next;
//}
}
list* h;
h =  (list *) malloc(sizeof(list));
h->date = a;
h->next = p->next;
p->next = h;
//}
p = &node1;   //修改
while (p != NULL)
{
printf("%d\n", p->date);
p = p->next;
}
return 0;
}

``````
本回答被题主选为最佳回答 , 对您是否有帮助呢?
评论

• 系统已结题 2月16日
• 已采纳回答 2月8日
• 创建了问题 2月3日