#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct student
{
int score;
struct student*next;
}L;
L*create(int data)
{
L*p=(L*)malloc(sizeof(L));
if(p==NULL)
{
printf("malloc fair!");
return NULL;
}
memset(p,0,sizeof(L));
p->score=data;
p->next=NULL;
}
void tailinsert( L *ph,L *c)
{
L*p=ph;
while(p->next!=NULL)
{
p=p->next;
}
p->next=c;
}
void print(L*ph)
{
L*p=ph;
p=p->next;
while(p!=NULL)
{
printf("%d,\n",p->score);
p=p->next;
}
printf("\n");
printf("%d",p->score);
}
L*Find(L*List,int data)
{
L* ptr = List->next;
if (ptr == NULL) {
printf("链表为空\n");
return NULL;
}
while (ptr != NULL && ptr->score != data) {
ptr = ptr->next;
}
if (ptr != NULL) {
printf("找到 %d 了\n", data);
}
else
{
printf("没有找到 %d\n", data);
}
return ptr;
}
int detele(L * pH , int data)
{
L *p = pH ;
L *prev = NULL;
while(NULL != p->next)
{
prev = p ;
p = p->next ;
if(p->score == data)
{
if(p->next != NULL)
{
prev->next = p->next ;
free(p);
}
else
{
prev->next = NULL ;
free(p);
}
return 0 ;
}
}
printf("没有要删除的节点\n");
return -1 ;
}
void DeleteList(L* List)
{
L* position;
L*tmpNode;
position = List->next;
List->next = NULL;
while (position != NULL) {
tmpNode = position->next;
free(position);
position = tmpNode;
}
}
int main()
{
L*m=create(0);
L*infor;
while(1)
{
printf("请输入您想要的数据\n");
infor = (L*)malloc(sizeof(L));
infor->next = NULL;
scanf("%d",&infor->score);
setbuf(stdin,NULL);
tailinsert(m,infor);
printf("要继续吗?1.yes\t2.no?\n");
int choice=getchar();
setbuf(stdin,NULL);
if(choice=='2')
{
break;
}
}
printf("请输入要删除的数据\n");
scanf("%d",&infor->score);
detele(m,infor->score);
setbuf(stdin,NULL);
printf("请输入想要查找的数据\n");
printf("如果有请按2\n");
int choice3=getchar();
setbuf(stdin,NULL);
if(choice3=='2');
{
Find(m);
}
printf("要删除整个链表吗? 1.yes 2.no");
printf("\n");
int choice2=getchar();
setbuf(stdin,NULL);
if(choice2=='1')
{
DeleteList(m);
}
print(m);
system("pause");
return 0;
}
不知道为什么这个程序一直出现错误D:\mingw64\c语言库\333\main.cpp|139|error: too few arguments to function 'L* Find(L*, int)'|
求求大佬们帮帮孩子吧,我实在是不知道怎么弄了,感觉和下面的detele函数一样啊,就是不知道为啥无法通过