Chào các bạn! Vì nhiều lý do từ nay Truyen2U chính thức đổi tên là Truyen247.Pro. Mong các bạn tiếp tục ủng hộ truy cập tên miền mới này nhé! Mãi yêu... ♥

code C cua Kec

#include<conio.h>

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

#define TRUE 1

struct sinhvien

{

            char ht[30];

            int ns;

};

struct node

{

            sinhvien info;

            node *netx;

};

typedef node *ctronode;

ctronode first;

int menu(int *m);

void duyetds(ctronode *first);

ctronode themnode(void);

void xoanode(ctronode p);

void khoitao(ctronode *first);

int rong(ctronode *first);

void xoahet(ctronode *first);

void nhapsinhvien(ctronode *first);

void themdau(ctronode *first,sinhvien info);

void xoadau(ctronode *first);

int  sonode(ctronode *first);

ctronode searname(ctronode *first,sinhvien info);

void insafter(ctronode *first,ctronode p,sinhvien info);

void delsau(ctronode *first,ctronode p,sinhvien infor);

int ctro(ctronode *first,ctronode p);

main()

{

            int m=1,i,vitri,soluong;

            sinhvien info;

            ctronode p;

            char x;

            khoitao(&first);

            while(m!=0)

            {

                        menu(&m);

                        switch(m)

                        {

                        case 0:break;   

                        case 1:duyetds(&first);break;

                        case 2:printf("

Nhap so luong sinh vien : ");

                               scanf("%d",&soluong);

                               for(i=0;i<soluong;i++)

                               {

               printf("

Ho ten : ");

                               fflush(stdin);gets(info.ht);

                               printf("

Nam sinh : ");

                               scanf("%d",&info.ns);

                               themdau(&first,info);

                               }

                               break;

                        case 3:printf("

Ho ten : ")       ;

                               fflush(stdin);  gets(info.ht);

                               printf("

Nam sinh : ");

                               scanf("%d",&info.ns);

                               themdau(&first,info);

                               printf("

DA THEM THANH CONG");

                               break;

                        case 4:xoadau(&first) ;

                               printf("

DA XOA THANH CONG MOT SINH VIEN KHOI DANH SACH");

                               break;

                        case 5:printf("

Ho ten can tim : ")       ;

                               fflush(stdin);  gets(info.ht);

                               p=searname(&first,info);

                               if(p==NULL)   printf("

Khong co ten trong danh sach");

                               else printf("

Tim duoc tai vi tri : %i",ctro(&first,p)+1);                                    

                        }

            }

}

int menu(int *m)

{

    printf("

  CHUONG TRINH QUAN LY DANH SACH SINH VIEN   ");

    printf("

          Tran Van Quang - 08CDTH1A          ");

            printf("

---------------------------------------------");

            printf("

1- Duyet danh sach");

            printf("

2- Them nhieu sinh vien vao danh sach");

            printf("

3- Them 1 sinh vien vao danh sach");

            printf("

4- Xoa sinh vien khoi danh sach");

            printf("

5- Tim theo ten mot sinh vien trong danh sach");

            printf("

0- Thoat chuong trinh");

            printf("

---------------------------------------------");

            printf("

Nhap lua chon cua ban : ")   ;

            scanf("%d",m);

            return  *m;

}

void khoitao(ctronode *first)

{

            *first=NULL;

}

ctronode themnode(void)

{

            ctronode p;

            p=(ctronode) malloc(sizeof(struct node));

            return p;

}

void xoanode(ctronode p)

{

            free(p);

}

int rong(ctronode *first)

{

            return *first==NULL?1:0;

}

//****************Hien thi danh sach sinh vien*******************

void duyetds(ctronode *first)

{

            int stt=0;

            ctronode p;

            if(*first==NULL)

            {

                        printf("

Danh sach trong ! ");

                        return;

            }

            else

            {

                        printf("

So sinh vien hien co la : %d ",sonode(first));

                        p=*first;

                        while(p!=NULL)

                        {

                                    printf("

%d\t%s\t%d",++stt,p->info.ht,p->info.ns);

                                    p=p->netx;

                        }

            }

}

// ****** Them sinh vien vao dau danh sach*********

void themdau(ctronode *first,sinhvien info)

{

            ctronode p;

            p=themnode();

            p->info=info;

            p->netx=*first;

            *first=p;

}

void xoahet(ctronode *first)

{

            *first=NULL;

}

void xoadau(ctronode *first)

{

            ctronode p;

            p=*first;

            *first=p->netx;

            xoanode(p);

}

ctronode searname(ctronode *first,sinhvien info)

{

            ctronode p;

            int vitri=0;

            p=*first;

            while((p!=NULL)&&(strcmp(p->info.ht,info.ht)!=0))

            {

                        vitri++;

                        p=p->netx;

            }

    return p;

}

int  sonode(ctronode *first)

{

            int i=0;

            ctronode p;

            p=*first;

            while(p!=NULL)

            {

                        i++;

                        p=p->netx;

            }

            return i;

}

int ctro(ctronode *first,ctronode p)

{

            int i=0;

            ctronode q;

            q=*first;

            while(q!=p&&q!=NULL)

            {

                        q=q->netx;

                        i++;

            }

            if(q==NULL) return -1;         

  else return i;

}

Bạn đang đọc truyện trên: Truyen247.Pro

Tags: #nam