
用c语言描述数据结构编写一个能输出学生学号,年龄 性别的源代码?还有顺序表的删除与插入源代码
1个回答
展开全部
1、结构体
struct std{
int num;
int age;
char sex;
};
2、顺序表
#include<stdio.h>
#include<stdlib.h>
#define maxsize 1024
typedef int datatype;
typedef struct{
datatype data[maxsize];
int last;
}sequenlist;
sequenlist* InitList()
{
sequenlist *L=(sequenlist*)malloc(sizeof(sequenlist));
L->last=0;
return L;
}
int InsertList(sequenlist* L,datatype x,int i)
{
int j;
if(L->last>=maxsize-1)
{
printf("List Overflow!\n");
return 0;
}
else if(i<1||i>L->last+1)
{
printf("Error Insert Place!\n");
return 0;
}
else
{
for(j=L->last;j>=i;--j)
L->data[j+1]=L->data[j];
L->data[i]=x;
++L->last;
return 1;
}
}
int DeleteList(sequenlist* L,int i)
{
int j;
if((i<1)||(i>L->last))
{
printf("Error Delete Place!\n");
return 0;
}
else
{
for(j=i;j<L->last;++j)
L->data[j]=L->data[j+1];
--L->last;
return 1;
}
}
int PrintList(sequenlist* L)
{
int i;
if(L->last<0||L->last>maxsize-1)
{
printf("Error List!\n");
return 0;
}
else if(L->last==0)
{
printf("Empty List!\n");
return 0;
}
else
{
printf("/****Now Printing List...****/\n");
for(i=1;i<=L->last;++i)
printf("data(%d)\t%d\n",i,L->data[i]);
printf("/****Printing Ended!****/\n");
return 1;
}
}
int LengthList(sequenlist* L)
{
return L->last;
}
int LocateList(sequenlist* L,datatype x)
{
int i=1;
for(;i<=L->last;++i)
if(L->data[i]==x) return i;
return 0;
}
void DelNodeList(sequenlist* L,datatype x)
{
int i;
i=LocateList(L,x);
while(i)
{
if(DeleteList(L,i)==0) break;
i=LocateList(L,x);
}
}
struct std{
int num;
int age;
char sex;
};
2、顺序表
#include<stdio.h>
#include<stdlib.h>
#define maxsize 1024
typedef int datatype;
typedef struct{
datatype data[maxsize];
int last;
}sequenlist;
sequenlist* InitList()
{
sequenlist *L=(sequenlist*)malloc(sizeof(sequenlist));
L->last=0;
return L;
}
int InsertList(sequenlist* L,datatype x,int i)
{
int j;
if(L->last>=maxsize-1)
{
printf("List Overflow!\n");
return 0;
}
else if(i<1||i>L->last+1)
{
printf("Error Insert Place!\n");
return 0;
}
else
{
for(j=L->last;j>=i;--j)
L->data[j+1]=L->data[j];
L->data[i]=x;
++L->last;
return 1;
}
}
int DeleteList(sequenlist* L,int i)
{
int j;
if((i<1)||(i>L->last))
{
printf("Error Delete Place!\n");
return 0;
}
else
{
for(j=i;j<L->last;++j)
L->data[j]=L->data[j+1];
--L->last;
return 1;
}
}
int PrintList(sequenlist* L)
{
int i;
if(L->last<0||L->last>maxsize-1)
{
printf("Error List!\n");
return 0;
}
else if(L->last==0)
{
printf("Empty List!\n");
return 0;
}
else
{
printf("/****Now Printing List...****/\n");
for(i=1;i<=L->last;++i)
printf("data(%d)\t%d\n",i,L->data[i]);
printf("/****Printing Ended!****/\n");
return 1;
}
}
int LengthList(sequenlist* L)
{
return L->last;
}
int LocateList(sequenlist* L,datatype x)
{
int i=1;
for(;i<=L->last;++i)
if(L->data[i]==x) return i;
return 0;
}
void DelNodeList(sequenlist* L,datatype x)
{
int i;
i=LocateList(L,x);
while(i)
{
if(DeleteList(L,i)==0) break;
i=LocateList(L,x);
}
}
追问
我能加你QQ吗?
追答
736900871

2023-08-15 广告
通常情况下,我们会按照结构模型把系统产生的数据分为三种类型:结构化数据、半结构化数据和非结构化数据。结构化数据,即行数据,是存储在数据库里,可以用二维表结构来逻辑表达实现的数据。最常见的就是数字数据和文本数据,它们可以某种标准格式存在于文件...
点击进入详情页
本回答由光点科技提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询