단일 체인 시트 의 응용 - 간단 한 주소록

4550 단어
        ,       ,      ,      。<img alt="  " src="http://static.blog.csdn.net/xheditor/xheditor_emot/default/struggle.gif" />
#include <stdio.h>//     
#include <stdlib.h>
#include <string.h>
typedef struct Node{
     char name[20];
	 char  Iphonedata[11];
	 int  qq;
	 struct Node *next;
}Node,*LinkList;
void CreatList(LinkList &L)
{ 
    int i;
	LinkList r,p;
	L=(LinkList)malloc(sizeof(Node));
	r=L;
	
	printf("        ,1 or 0?
"); scanf("%d",&i); getchar(); while(i) { p=(LinkList)malloc(sizeof(Node)); printf(" :
"); gets(p->name); //getchar(); printf(" :
"); gets(p->Iphonedata);// char ??? //getchar(); //scanf("%ld",&p->Iphonedata); printf(" qq :
"); //gets(p->qq); scanf("%d",&p->qq); r->next=p; r=p; scanf("%d",&i); getchar(); } r->next=NULL; } void OutPut(LinkList L) { LinkList p; p=L->next; while(p!=NULL) { printf(" :%s\t :%s\tQQ :%d\t
",p->name,p->Iphonedata,p->qq); p=p->next; } } void AddList(LinkList &L) { LinkList p,r; int number,j; r=L; while(r->next!=NULL)//cur->next!=NULL? r=r->next; int i; printf(" ,1 or 0?
"); scanf("%d",&i); getchar(); while(i) {p=(LinkList)malloc(sizeof(Node)); if(p!=NULL) { printf(" :
"); gets(p->name); //getchar(); printf(" :
"); gets(p->Iphonedata);// char ??? //getchar(); //scanf("%ld",&p->Iphonedata); printf(" qq :
"); //gets(p->qq); scanf("%d",&p->qq); p->next=NULL; r->next=p; scanf("%d",&i); getchar(); } } } /*int SearchList(LinkList L) { LinkList r; int QQ; char name[20]; char Iphone[11]; int sel; r=L; getchar(); printf(" 1--3 , ,qq :
"); scanf("%d",&sel); switch(sel) { case 1: getchar(); gets(name); while(r!=NULL) { if(strcmp(name,r->name)==0) break; else r=r->next; } if(r!=NULL) { printf(" :%s\t\t :%s\t\tQQ:%d
",r->name,r->Iphonedata,r->qq); } else printf(" !
"); break; case 2: getchar(); gets(Iphone); while(r!=NULL) { if(strcmp(Iphone,r->Iphonedata)==0) break; else r=r->next; } if(r!=NULL) { printf(" :%s\t\t :%s\t\tQQ:%d
",r->name,r->Iphonedata,r->qq); } else printf(" !
"); break; case 3: scanf("%d",&QQ); while(r!=NULL) { if(QQ==r->qq) break; else r=r->next; } if(r!=NULL) { printf(" :%s\t\t :%s\t\tQQ:%d
",r->name,r->Iphonedata,r->qq); } else printf(" !
"); break; } return 0; }*/ int SearchList(LinkList L) { LinkList r; char name[20]; r=L; getchar(); gets(name); while(r!=NULL) { if(strcmp(name,r->name)==0) break; else r=r->next; } if(r!=NULL) { printf(" :%s\t\t :%s\t\tQQ:%d
",r->name,r->Iphonedata,r->qq); } else printf(" !
"); return 0; } int DeleteList(LinkList &L) { LinkList r,p; char name[20]; r=L; getchar(); printf(" :"); gets(name); while(r->next!=NULL) { if(strcmp(name,r->next->name)==0) break; else r=r->next; } if(r->next!=NULL) { p=r->next; r->next=p->next; free(p); } printf(" !
"); return 0; } int main() { LinkList L; int sel;// while(1) { printf("\t
"); printf("1.
"); printf("2.
"); printf("3.
"); printf("4.
"); printf("5.
"); printf("0.
"); printf(" (0--5) :
"); scanf("%d",&sel); switch(sel) { case 1: CreatList(L);break; case 2: OutPut(L);break; case 3: AddList(L);break; case 4: DeleteList(L);break; case 5: SearchList(L);break; case 0: return 0;break; } } system("pause"); return 0; }

좋은 웹페이지 즐겨찾기