最近让交的实验内容:实验一

#include<stdio.h>
#include<stdlib.h>
#define MAXSIZE 1000
typedef int elemtype;
typedef struct sequlist
{
    elemtype data[MAXSIZE];
    int last;
}SequenList;
SequenList *l,*B;
SequenList *Init_SequenList()//初始化 
{
    SequenList *kjasdvh;
    kjasdvh=(SequenList*)malloc(sizeof(SequenList));
    kjasdvh->last=-1;
}
int mainF()
{
    puts("====================");
    puts("请选择:\n");
    puts("1创建\n");
    puts("2求长\n");
    puts("3顺序表遍历\n");
    puts("4顺序表插入\n");
    puts("5顺序表删除\n");
    puts("6顺序表查找位置\n");
    puts("0退出\n");
    puts("====================");
}
int mainM()
{
    char ck;
    while(1)
    {
        system("cls");
        mainF();
        ck=getch();
        switch(ck)
        {
            case'1':chuangjian(l);printf("按任意键继续!\n");getch();break;
            case'2':SequenList_Length(l);printf("按任意键继续!\n");getch();break;
            case'3':Print_SequenList(l);printf("按任意键继续!\n");getch();break;
            case'4':Insert_SequenList(l);printf("按任意键继续!\n");getch();break;
            case'5':Delete_SequenList(l);printf("按任意键继续!\n");getch();break;
            case'6':Search_SequenList(l);printf("按任意键继续!\n");getch();break;
            case'0':Exit();break;
        }
    }
}
int SequenList_Length(SequenList *l)//求长 
{
    system("cls");
    int a;
    a=l->last+1;
    printf("长度为%d",a);
}
int Insert_SequenList(SequenList *l)//插入 
{
    system("cls");
    int j,x,i;
    printf("请输入插入的值以及节点位置\n");
    scanf("%d %d",&x,&i);
    if(l->last>=MAXSIZE-1)
    {
        printf("表满!数据溢出\n");
    }
    if(i<1||i>l->last+2)
    {
        printf("非法位置!\n");
    }
    for(j=l->last;j>=i-1;j--)
        l->data[j+1]=l->data[j];
    l->data[i-1]=x;
    l->last=l->last+1;
}
int chuangjian(SequenList *l)//创建 
{
    system("cls");
    int n,b;
    printf("请输入数据长度!\n");
    scanf("%d",&n); 
    for(b=0;b<n;b++)
    {
        scanf("%d",&l->data[b]);
        l->last+=1;
    }
}
int Print_SequenList(SequenList *l)//遍历 
{
    system("cls");
    int i;
    for(i=0;i<=l->last;i++)
    {
        printf("%d\t",l->data[i]);
    }
}
int Delete_SequenList(SequenList *l)//删除 
{
    system("cls");
    int j,i;
    printf("请输入删除的节点\n");
    scanf("%d",&i);
    if(i<1||i>l->last+1)
    {
        printf("非法位置\n");
    }
    else
    {
        for(j=i;j<=l->last;j++)
        l->data[j-1]=l->data[j];
        l->last--;
    }
}
int Search_SequenList(SequenList *l)//查找位置 
{
    system("cls");
    int i,key;
    printf("请输入查找的值\n");
    scanf("%d",&key);
    for(i=0;i<l->last;i++)
    {
        if(l->data[i]==key)
        {
            printf("%d",i+1); 
        }
    }
}
int Exit()
{
    printf("欢迎下次再来!(按任意键退出)");
    getch();
    exit(0); 
}
int main()
{
    l=Init_SequenList();
    mainM(); 
}

这是实验一.1,接下来的是后面的实验内容,实验一比较简单就不在介绍了,希望对大家有帮助!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值