#ifndef _LINLIST_H_
#define _LINLIST_H_
#endif
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
typedef int status;
typedef int DataType;
typedef int status;
typedef int DataType;
typedef struct Node
{
// DataType data;
char name[10];
long number;
int grade;
struct Node *next;
}LNode,*LinList;
status ListInit(LNode **L)
{
*L=(LNode*)malloc(sizeof(LNode));
(*L)->next=NULL;
}
status ListLength (LNode *L)
{
LNode *p;
int num=0 ;
p=L;
while (p->next!=NULL)
{
p=p->next;
num++;
}
return (num);
}
status ListDestory(LNode **L)
{
LNode *p,*q;
p=(*L)->next;
while (p!=NULL)
{
q=p;
p=p->next;
free (q);
}
*L=NULL;
}
status ListInsert(LNode *L,int i)
{
LNode *p,*q,*p1;
int j=0;
p=L;
while (j<i-1&&p!=NULL)
{
p=p->next;
j++;
}
q=(LNode*)malloc(sizeof(LNode));
printf ("\n请输入学生信息: "); scanf ("%ld%s%d",&q->number,q->name,&q->grade);
//q->data=x;
q->next=p->next;
p->next=q;
}
status ListGet(LNode *L,int i)
{
LNode *p,*q;
p=L;
int j=0;
while (j<i&&p->next!=NULL)
{
p=p->next;
j++;
}
printf ("\n学生信息为: %ld--- %s ----%d\n",p->number,p->name,p->grade);
// q=p;
//*x=q->data;
}
status ListDelete(LNode *L,int i)
{
LNode *p,*q;
p=L;
int j=-1;
while (j<i-2&&p->next!=NULL&&p->next->next!=NULL)
{
p=p->next;
j++;
}
q=p->next;
p->next=p->next->next;
free(q);
}
status ListSearchName (LNode *L,char a[20])
{
LNode *p;
int flag=0 ;
p=L;
while (p->next!=NULL)
{
p=p->next;
if(strcmp(p->name, a) == 0)
{
flag=1;
printf ("\n学生信息为: %ld--- %s ----%d\n",p->number,p->name,p->grade);
}
}
if (flag==0)
printf ("\n查无此人!\n");
}
/*
status ListSq (LNode *L)
{
LNode *p,*q;
student *stu;
int num=0 ;
顺序表链表联合操作
最新推荐文章于 2022-07-15 11:11:35 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)