⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 63.c

📁 推荐刚刚开始学C语言的同志们看下
💻 C
字号:
    #include <stdlib.h> 
    #include <stdio.h>
    #include <malloc.h>
    #include <string.h>
    #include <conio.h>
    #define N 10

    typedef struct node
    {
        char name[20];
        struct node *link;
    }stud;

    stud * creat(int n)
    {
        stud *p,*h,*s;
        int i;
        if((h=(stud *)malloc(sizeof(stud)))==NULL)
        {
            printf("cannot find space!");
            exit(0);
        }
        h->name[0]='\0';
        h->link=NULL;
        p=h;
        for(i=0;i<n;i++)
        {
            if((s= (stud *) malloc(sizeof(stud)))==NULL)
            {
                printf("cannot find space!");
                exit(0);
            }
            p->link=s;
            printf("please input %d student's name:",i+1);
            scanf("%s",s->name);
            s->link=NULL;
            p=s;
        }
        return(h);
    }

    stud * search(stud *h,char *x)
    {
        stud *p;
        char *y;
        p=h->link;
        while(p!=NULL)
        {
            y=p->name;
            if(strcmp(y,x)==0)
            return(p);
            else p=p->link;
        }
        if(p==NULL)
        printf("data not find!");
		return 0;
    }

    stud * search2(stud *h,char *x)
    {
        stud *p,*s;
        char *y;
        p=h->link;
        s=h;
        while(p!=NULL)
        {
            y=p->name;
            if(strcmp(y,x)==0)
                return(s);
            else
            {
                p=p->link;
                s=s->link;
            }
        }
        if(p==NULL)
        printf("data not find!");
		return 0;
    }

    void insert(stud *p)
    {
        char stuname[20];
        stud *s;
        if((s= (stud *) malloc(sizeof(stud)))==NULL)
        {
            printf("cannot find space!");
            exit(0);
        }
        printf("\nplease input the student's name:");
        scanf("%s",stuname);
        strcpy(s->name,stuname);
        s->link=p->link;
        p->link=s;
    }

    void del(stud *x,stud *y)
    {
        stud *s;
        s=y;
    x->link=y->link;
        free(s);
    }

    void print(stud *h)
    {
        stud *p;
        p=h->link;
        printf("data information:\n");
        while(p!=NULL)
        {
            printf("%s ",&*(p->name));
            p=p->link;
        }
    }

    void quit()
    {
        exit(0);
    }

    void menu(void)
    {
        clrscr();
        printf("\t\t\t simple linklise realization of c\n");
        printf("\t\t|————————————————-----|\n");
        printf("\t\t|                                     |\n");
        printf("\t\t| [1]  create linklist                |\n");
        printf("\t\t| [2]  seach                          |\n");
        printf("\t\t| [3]  insert                         |\n");
        printf("\t\t| [4]  delete                         |\n");
        printf("\t\t| [5]  print                          |\n");
        printf("\t\t| [6]  exit                           |\n");
        printf("\t\t|                                     |\n");
        printf("\t\t| if no list exist,create first       |\n");
        printf("\t\t|                                     |\n");
        printf("\t\t|————————————————-----|\n");
        printf("\t\t please input your choose(1-6):");
    }

    main()
    {
        int choose;
        stud *head,*searchpoint,*forepoint;
        char fullname[20];


        while(1)
        {
            menu();
            scanf("%d",&choose);
            switch(choose)
            {
                case 1:head=creat(N);
                break;
                case 2:printf("input the student's name which you want to find:");
                    scanf("%s",fullname);
                    searchpoint=search(head,fullname);
                    printf("the stud name you want to find is:%s",*&searchpoint->name);
                    printf("\n push returen to main menu.");
		    getchar();
		    getchar();
                    break;
                case 3: printf("input the insert position:");
                    scanf("%s",fullname);
                    searchpoint=search(head,fullname);
                    printf("the stud name you want to find is:%s",*&searchpoint->name);
                    insert(searchpoint);
                    print(head);
                    printf("\npush returen to main menu.");
                    getchar();getchar();
                    break;
                case 4:print(head);
                    printf("\ninput the student's name which you want to delete:");
                    scanf("%s",fullname);
                    searchpoint=search(head,fullname);
                    forepoint=search2(head,fullname);
                    del(forepoint,searchpoint);
                    break;
                case 5:print(head);
                    printf("\npush returen to main menu.");
                    getchar();getchar();
                    break;
                case 6:quit();
                    break;
                default:printf("illegal letter!push returen to main menu.。");
                    clrscr();
                    menu();
                    getchar();
            }
        }
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -