#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <conio.h>

struct addr_list
{
 char stnum[10];
 char name[12];
 char idnum[13];
 char addr[30];
 char hp[12];
 char homehp[12];
 struct addr_list *next;
};

struct addr_list *head =NULL;

int count()
{
 struct addr_list *cur =head;
 int num=0;
 while(1)
 {
  if (cur==NULL)
   return num;
  else
  {   num++;
  cur=cur->next;
  }
 }
}

void list()
{
 struct addr_list *cur = head;
 printf("The resulting List is ");
 while(1)
 {
  printf("\n학번 %s\n",  cur->stnum);
  printf("이름 %s\n", cur->name);
  printf("주민번호 %s\n", cur->idnum);
  printf("주소 %s\n",cur->addr);
  printf("휴대전화 %s\n",cur->hp);
  printf("집번화 %s\n",cur->homehp);
  printf("----->");
  if(cur->next ==NULL)
  {
   printf("NULL\n");
   break;
  }
  else cur=cur->next;
 }
}

void create_nodes()
{
 struct addr_list *list, *pre_list;
 while(1)
 { list=(struct addr_list *) malloc (sizeof(struct addr_list));
   if (head ==NULL)
    head=list;
   else pre_list->next =list;

   printf("\n학번을 입력하시오 : , 입력의 끝은 Enter를 누리스오!");
   gets(list->stnum);
   if(*(list->stnum) =='\0')
   {
    free (list);
    pre_list->next =NULL;
    break;
   }
   printf("이름을 입력하시오 : ");
   gets(list->name);
   printf("주민번호를 입력하시오 :");
   gets(list->idnum);
   printf("주소를 입력하시오 :");
   gets(list->addr);
   printf("휴대폰 번호를 입력하시오 :");
   gets(list->hp);
   printf("집 전화번호를 입력하시오 :");
   gets(list->homehp);
   list->next=NULL;
   pre_list=list;
 }
}

void update_node()
{
 char stnum[10], yesno, sw='n';
 struct addr_list *cur;
 printf("\n 변경할 학번을 입력하시오 :");
 gets(stnum);
 if(head==NULL)
 {
  printf("연결 리스트가 없음\n");
  exit(0);
 }
 cur=head;
 while(cur)
 {
  if(strcmp(cur->stnum,stnum)==0)
  { printf("\n학번 %s\n",cur->stnum);
   printf("이름 %s\n", cur->name);
   printf("주민번호 %s\n", cur->addr);
 
   printf("w주소 %s  ",cur->idnum);
   printf("주소를 변경하십니까? (y/n) :");
  if(yesno=getche() =='y')
   { printf("주소를 입력하시오 ! :");
   gets(cur->addr);
  }
  
   printf("휴대전화%s\n",cur->hp);
   printf("휴대전화를 변경하십니까?(y/n) :");
    if (yesno=getche() =='y')
  { printf("휴대전화를 입력하시오! :");
   gets(cur->hp);
  }
 
   printf("집전화 %s\n",cur->homehp);
   printf("집전화를 변경하시겠습니다? (y/n) :");
  if(yesno=getche() =='y')
  {
   printf("집전화를 입력하시오! :");
   gets(cur->homehp);
  }
   sw='y';
   break;
  }
  else cur=cur->next;
 }
 if(sw=='n') printf("\n변경할 학번이 없습니다.");
}

void insert_node()
{
 struct addr_list *list, *pre_list, *cur;
 list=(struct addr_list*) malloc(sizeof(struct addr_list));

 if(list==NULL)
 { printf("memory overflow\n");
  exit(0);
 }

 printf("\n학번을 입력하시오 :");
 gets(list->stnum);
 printf("이름을 입력하시오 :");
 gets(list->name);
 printf("주민번호를 입력하시오 :");
 gets(list->idnum);
 printf("핸드폰 번호를 입력하시오 :");
 gets(list->hp);
 printf("집 전화번호를 입력하시오 :");
 gets(list->homehp);

 list->next =NULL;
  if(head==NULL)
  { head=list;
   list->next=NULL;
   printf("0000");
  }
  else
  { if(strcmp(head->stnum, list->stnum) >=0)
   { list->next=head;
    head=list;
   }
  else
  { pre_list = head;
    while(1)
    {
     cur=pre_list->next;
     if(strcmp(cur->stnum, list->stnum) >=0)
     {
      list->next =cur;
      pre_list->next =list;
      break;
     }
     else if (strcmp(cur->stnum,list->stnum)==0)
     { printf("Same data duplicated");
    exit(0);
     }
     else if (cur->next ==NULL)
     { cur->next =list;
    list->next =NULL;
    break;
     }
     pre_list=cur;
    }
  }
  }
  printf("*************** 학번 %s 삽입되었습니다.\n",list->stnum);
}

void remove_node()
{
 struct addr_list *pre_list, *cur;
 
 char stnum[10];
 printf("\n삭제할 학번을 입력하시오 :");
 gets(stnum);
 if(head==NULL);
 {
  printf("연결 리스트가 없음\n");
  exit(0);
 }
 cur=head;
 if(strcmp(cur->stnum,stnum)==0)
 { head=cur->next;
  printf("*************** 학번 %s 삭제되었습니다. \n", stnum);
  free(cur);
 }
 else
 {
  pre_list =cur;
  while(1)
  {
   cur=pre_list->next;
   if (strcmp (cur->stnum,stnum)==0)
   { pre_list->next =cur->next;
    printf("************** 학번 %s 삭제되었습니다.\n",stnum);
    free(cur);
    break;
   }

   if(cur->next ==NULL)
   {
    printf("삭제할 학번 %s이 존재하지않습니다.\n",stnum);
    break;
   }
   pre_list =cur;
  }
 }
}

int main(void)
{
 char s[10];
 while(1)
 {
  printf("\n*****************************************************************\n");
  printf("생성(creat), 변경(update), 추가(insert), 삭제(Delect), 출력(List), 종료(Quit) : ");
  gets(s);
 *s =toupper(*s);
 
 switch (*s) {
 case 'C' : create_nodes(); break;
 case 'U' : update_node(); break;
 case 'D' : remove_node(); break;
 case 'I' : insert_node(); break;
 case 'L' : list();
    printf("THIS list has %d elements\n",count());break;
 case 'Q' : exit(0);
 }
 }
 free(head);
}

이올린에 북마크하기(0) 이올린에 추천하기(0)
크리에이티브 커먼즈 라이선스
Creative Commons License



Trackback URL : http://trustnoone.tistory.com/trackback/424 관련글 쓰기

Leave a comment

« Previous : 1 : ... 359 : 360 : 361 : 362 : 363 : 364 : 365 : 366 : 367 : ... 747 : Next »

Blog Owner : MULDER。



TO FIND THE TRUTH,
YOU MUST BELIEVE。

I WANT TO BELIEVE。

http://trustnoone.tistory.com 。



now playing...



Artist : K-ci & JoJo
Album : THEIR GREATEST HITS (2005)
Title : 04. All My Life ♪ (5:26)






Calendar

«   2008/11   »
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30            

Recent Posts

  1. 마지막 여정.
  2. 돌아이~
  3. 烈火戰車
  4. YAMAHA MAJESTY 125 Fi 인증샷!
  5. 이런..... -_-;;;
  6. 지난 결혼식.
  7. 바이크 명칭(?)이랄까요 저처럼 잘모르시..
  8. Majesty 125 Fi
  9. 인생 뭐 없더라...
  10. Down... Down.

Recent Comments

  1. 저같으면 '아즈메고마쎼리 다리몽댕이 뿌.. 동래마제 11/10
  2. 전 그냥 택시나 초딩이나 김여사나 아무.. 메탈릭 11/10
  3. 휴...간혹있는일이긴 하지만 너무 위기일.. 달인 11/10
  4. 여사님들은 타도 문제고 걸어다녀도 문제.. 토돌이 11/10
  5. 그런 사람 평소에도 욕 많이 먹고 살겁니.. 구들등호 11/10
  6. 그런 사람한텐 욕해도 됩니다. 무단횡단.. 불족발 11/10
  7. 일단 버스정차하면 무조건 서행이 예방이.. 동래마제 11/10
  8. 다행입니다... 탱굴 11/10
  9. 헐.. 다행이네요 슬립도 안하시고..ㅋ 부천마제 11/10
  10. 자처하지 말라구.. lhy 11/05

Recent Trackbacks

  1. 최고의 처세술은 실력이다 - 식객 23회 당신은 '그 무엇'을 찾았나요? - 사용인 09/10
  2. ssh 접속은 터미널? 탐색기처럼 탐색한다.. 무엇을 구하려거든 전부가 그것이게 하라 06/24
  3. 윤동주의 서시. 엔즐군의 다이어리::Spring Edition 05/06
  4. 시끄러운 Superfetch Rommance - Daniel's 04/23
  5. 고향의 소리 말하자면 03/14
  6. 비스타 보안의 핵, 사용자 계정 컨트롤(U.. 아크비스타 :: 아크몬드의 비스타블로그 01/17
  7. [커프뮤비] 나는 사랑이 뭔지 모르나봐요.. 커프마왕 2007
  8. Spider-man 1,2,3 구손랜드® 2007
  9. 비스타 구매 전에 따져 봐야 한다 소프트웨어로 행복한 삶을 꿈꾸다 2007

Bookmarks

  1. .Πet S.W.A.T's Blog
  2. Cisco Systems, Inc
  3. Click Blog
  4. D.Blog v5.0
  5. Daydream
  6. EnTER_ThE_Ciyne ~~
  7. ky`s notebook
  8. LUKE CHUEH
  9. Microsoft Corporation
  10. Mininova The ultimate BitTorrent sour..
  11. nagafuji
  12. Nepion Community
  13. PARKOZ HARDWARE 2007
  14. Seoby@Blog R&B 리믹스
  15. sonchul
  16. YouTube - Broadcast Yourself.
  17. 마로-_ -;@ 겔러리
  18. 베타뉴스
  19. 숙희
  20. 인생무상
  21. 지식아 모여라!
  22. 포포 Blog
  23. 플라잉 디스크
  24. 필승의 다짐으로


Online Messenger



ID : taewoong7@netsgo.com



Address : taewoong7@hotmail.com



Site Stats

TOTAL 250,410 HIT
TODAY 589 HIT
YESTERDAY 703 HIT


online casino Counters