• #include<stdio.h>
• #include<conio.h>
• #include<ctype.h>
• #include<string.h>
• typedef struct SINHVIEN
• { char ten[20];
• int msv;
• typedef struct SinhvienNode
•
SV Info;
• SinhvienNode *pNext;
• typedef struct SinhvienList
•
SinhvienNode *pHead;
• SinhvienNode *pTail;
• void makenull(LIST*L)
•
L->pHead=L->pTail=NULL;
•
void nhapsv(SV *x);
• void nhapds(LIST *L)
• { SV x; SinhvienNode *p;
• char tl;
• do {p=new SinhvienNode;
• p->pNext=NULL;
• nhapsv(&x);
• strcpy(p->Info.ten,x.ten);
• p->Info.msv=x.msv;
• if(L->pTail==NULL)
• else
• printf("\nban co tiep tuc khong(c/k)?");
• tl=getch();tl=toupper(tl);
• }while(tl=='C');
•
void nhapsv(SV *x)
• { int ma;
• printf("\nnhapSV X\n");
• printf("hoten: ");gets(x->ten);
• printf("ma:");scanf("%d",&ma);
•
void hienthids(LIST L)
• { SinhvienNode *p;
• p=L.pHead;int i=0;
• while(p!=NULL)
• printf("\n%3d %-20s %3d",++i,p->Info.ten,p->Info.msv);
• p=p->pNext;
•
void AddTail(LIST *L,SV x)
• { SinhvienNode *p;p=new SinhvienNode;
• p->pNext=NULL;
• p->Info=x;
• if(L->pHead==NULL)
• L->pHead=L->pTail=p;
• {//1 noi duoi cua pTail vao p
• //2 chuyen pTail ve p
• }
•
void AddHead(LIST *L,SV x)
• { SinhvienNode *p;p=new SinhvienNode;
• p->pNext=NULL;
• p->Info=x;
• if(L->pHead==NULL)
• L->pHead=L->pTail=p;
• {//1 noi duoi cua pTail vao p
• //2 chuyen pTail ve p
• }
•
void InsertAfter(LIST *L,SinhvienNode *q,SV x)
•
SinhvienNode *p;
• p=new SinhvienNode;p->Info=x;
• p->pNext=NULL;
• if(q==NULL)
• if(L->pTail==NULL)
• else{
• }
• else{//tim thay nut co ma n vao
• p->pNext=q->pNext; //chen vao L phan tu co
•
SinhvienNode *findNode(LIST L,int ma)
•
SinhvienNode *p;
• p=L.pHead;
• while(p!=NULL)
• return(p);
•
void main()
•
LIST L; SV x; int ma;
• makenull(&L); SinhvienNode *q;
• nhapds(&L);
• hienthids(L);
• nhapsv(&x);
• printf("\nnhap ma cua q:");scanf("%d",&ma);
• q=findNode(L,ma); //tra lai dia chi cua nut
• InsertAfter(&L,q,x);
• hienthids(L);
• /*nhapsv(&x);
• AddTail(&L,x);
• hienthids(L);nhapsv(&x);
• AddHead(&L,x);
• hienthids(L);nhapsv(&x);
• printf("\n nhap ma sv q:");scanf("%d",&ma);
• AddAfter(&q,ma,x);
•