디시인사이드 갤러리

갤러리 이슈박스, 최근방문 갤러리

갤러리 본문 영역

오빠들..!! 프로그램 복잡도가 넘 궁금해요..ㅡㅜ

초보.ㅡㅜ(202.31) 2010.10.20 15:22:14
조회 171 추천 0 댓글 8

과제때문에 작성은 겨우 했는데..

교수님이 시간복잡도를 구하라고 하시네요.ㅠ_ㅠ

으잉.. 프로그램이 너무 길어져서 복잡도가 어떻게 되는지

감조차 오질 않아요.. ㅡㅜ

도와주세요..T_T

단순연결리스트를 활용해서 학번이랑 각종정보를 저장, 수정하는 프로그램인데

길긴 긴데 복잡하진 않아요 ㅠ.





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

//번호, 이름, 주소, 전공을
typedef struct address_list {
 char student_no[12];
 char name[12];
 char korean_no[15];
 char address[30];
 char cell_phone[15];
 char home_phone[15];
 struct address_list *next;
}LIST;

 

address_list* create_list(char* student_no,char *name,char* korean_no, char* address,char* cell_phone,char* home_phone){
 address_list* temp;
 temp=(address_list*)malloc(sizeof(address_list));

 strcpy(temp->student_no,student_no);
 strcpy(temp->name,name);
 strcpy(temp->korean_no,korean_no);
 strcpy(temp->address,address);
 strcpy(temp->cell_phone,cell_phone);
 strcpy(temp->home_phone,home_phone);

 temp->next=NULL;
 return temp;
}

address_list* find_element_by_student_no(address_list *top,char* student_no){
 address_list* temp;

 temp=top->next;

 while(temp!=NULL){
  if (strcmp(temp->student_no,student_no)==0){
   return temp;
  }
  temp=temp->next; /* 다음으로 이동 합니다 */
 }

 return NULL;
}

address_list* find_element_by_name(address_list *top,char* name){
 address_list* temp;

 temp=top->next;

 while(temp!=NULL){
  if (strcmp(temp->name,name)==0){
   return temp;
  }
  temp=temp->next; /* 다음으로 이동 합니다 */
 }

 return NULL;
}

address_list* find_next(address_list *top){
 if (top==NULL){
  return NULL;
 }
 return top->next;
}

address_list* find_parent(address_list *top,address_list* node){
 address_list* temp;
 if (top==NULL){
  return NULL;
 }
 temp=top;
 while(temp){
  if (temp->next==node){
   return temp;
  }
 }
 return NULL;
}

void disp_list(FILE *fp,char *deion,address_list *top){
 if (top==NULL){
  fprintf(fp,"empty matix\\n");
 }

 fprintf(fp,"%s 학번=%s\\n이름=%s\\n주민번호=%s\\n주소=%s\\n휴대폰번호=%s\\n집전화번호=%s\\n",
  deion?"":deion,
  top->student_no,
  top->name,
  top->korean_no,
  top->address,
  top->cell_phone,
  top->home_phone
  );

}

int insert_element(address_list *top,char* student_no,char *name,char* korean_no, char* address,char* cell_phone,char* home_phone){
 address_list* temp;
 address_list* data;
 /* top의 첫번째 칸은 행렬의 row와 column의 개수가 있습니다 */
 if (top==NULL){
  return 0;
 }

 //먼저 num으로 데이타가 있는지 확인합니다.
 temp=find_element_by_student_no(top,student_no);
 if (temp!=NULL){
  printf("학번=%s는 이미 존재합니다 \\n",student_no);
  return 0;
 }

 temp=top;
 while(temp->next!=NULL){
  temp=temp->next; /* Linked List의끝까지 이동합니다 */
 }

 data=create_list(student_no,name,korean_no, address,cell_phone,home_phone);
 temp->next=data;

 return 1;
}

int modify_list(address_list* node,char* student_no,char *name,char* korean_no, char* address,char* cell_phone,char* home_phone){
 if (node==NULL){
  return 0;
 }

 strcpy(node->student_no,student_no);
 strcpy(node->name,name);
 strcpy(node->korean_no,korean_no);
 strcpy(node->address,address);
 strcpy(node->cell_phone,cell_phone);
 strcpy(node->home_phone,home_phone);
 return 1;
}

void clear_list(address_list *top){
 if (top==NULL){
  return;
 }

 free(top);
 return;
}

void clear_all(address_list *top){
 if (top==NULL){
  return;
 }

 if (top->next!=NULL){
  clear_list(top->next);
 }
 free(top);

 return;
}

void Insert(address_list* top){
 address_list* temp;
 char student_no[15];
 char name[15];
 char korean_no[15];
 char address[30];
 char cell_phone[15];
 char home_phone[15];

 char c;

 while(1){
  printf("[데이타 입력 ]\\n");
  fflush(stdin);
  printf("학번: ");
  gets(student_no);
  fflush(stdin);
  printf("이름: ");
  gets(name);
  printf("주민번호: ");
  gets(korean_no);
  printf("주소: ");
  fflush(stdin);
  gets(address);
  printf("휴대전화: ");
  fflush(stdin);
  gets(cell_phone);
  printf("집전화: ");
  fflush(stdin);
  gets(home_phone);
  temp=find_element_by_student_no(top,student_no);
  if (temp!=NULL){
   printf("학번 %d 가 이미 존재합니다\\n");
  }
  else{
   insert_element(top,student_no,name,korean_no, address,cell_phone,home_phone);
  }

  printf("계속 입력하시겠습니가(Y/N)?");
  scanf("%c",&c);
  if (c==\'Y\'||c==\'y\'){
   continue;
  }
  break;
 }

}

void retrieve_num(address_list* top){
 address_list* temp;
 char student_no[10];

 printf("학번: ");
 fflush(stdin);
 gets(student_no);
 temp=find_element_by_student_no(top,student_no);
 if (temp==NULL){
  printf("데이타가 없습니다\\n");
 }
 else{
  disp_list(stdout,"",temp);

  printf("[데이타 수정 ]\\n");
  fflush(stdin);
  printf("이름: ");
  gets(temp->name);
  printf("주민번호: ");
  gets(temp->korean_no);
  printf("주소: ");
  fflush(stdin);
  gets(temp->address);
  printf("휴대전화: ");
  fflush(stdin);
  gets(temp->cell_phone);
  printf("집전화: ");
  fflush(stdin);
  gets(temp->home_phone);
 }
}

void retrieve_name(address_list* top){
 address_list* temp;
 char name[30];

 printf("이름입력: ");
 scanf("%s",name);
 temp=find_element_by_name(top,name);
 if (temp==NULL){
  printf("데이타가 없습니다\\n");
 }
 else{
  disp_list(stdout,"",temp);
 }
}

void Update(address_list* top){
 retrieve_num(top);
}

void Delete(address_list* top){
 address_list* temp;
 address_list* parent;
 char student_no[15];
 printf("삭제할 학번을 입력하세요> ");
 fflush(stdin);
 gets(student_no);
 temp=find_element_by_student_no(top,student_no);
 if (temp==NULL){
  printf("지울 데이타가 없습니다\\n");
  
 }

 parent=find_parent(top,temp);
 parent->next=temp->next;
 clear_list(temp);
 printf("학번 %s 데이타 삭제완료 \\n",student_no);
}

void Print(address_list* top){
 address_list* temp;

 temp=top->next;
 while(temp){
  disp_list(stdout,"",temp);
  temp=temp->next;
 }
}


void main(){
 address_list* top=create_list("","","","","","");

 int menu;

 while(1){
  printf("1. 입력 2. 변경 3. 삭제 4. 모두보기 5.종료 > ");
  fflush(stdin);
  scanf("%d",&menu);
  switch(menu){
  case 1:
   Insert(top);
   break;
  case 2:
   Update(top);
   break;
  case 3:
   Delete(top);
   break;
  case 4:
   Print(top);
   break;
  case 5:
   return;
   break;
  default:
   printf("잘못 눌럿습니다 \\n");
   continue;
   break;
  }
 }
}

추천 비추천

0

고정닉 0

0

댓글 영역

전체 댓글 0
등록순정렬 기준선택
본문 보기

하단 갤러리 리스트 영역

왼쪽 컨텐츠 영역

갤러리 리스트 영역

갤러리 리스트
번호 제목 글쓴이 작성일 조회 추천
설문 힘들게 성공한 만큼 절대 논란 안 만들 것 같은 스타는? 운영자 24/06/10 - -
이슈 [디시人터뷰] 웃는 모습이 예쁜 누나, 아나운서 김나정 운영자 24/06/11 - -
225558 오늘 시발 오픈을 했어. [7] 물속의다이아갤로그로 이동합니다. 10.12.18 140 0
225557 프갤러들은 너무 똑똑해서 문제임 [2] 개쉛기갤로그로 이동합니다. 10.12.18 128 0
225555 좀 도와주실수 있으신가요 ? [4] 장선애(180.67) 10.12.18 61 0
225552 아침에도 썼던글인데, 알고리즘,C++,디비 독학하기 좋은 책 추천좀(조공 [13] 프갤(125.129) 10.12.17 275 0
225551 후배에게 조언좀 부탁드립니다...ㅠ [4] ㅎㅅㅎ(112.144) 10.12.17 64 0
225550 글은 왜 처 지우고 지랄이냐 [3] 이단아갤로그로 이동합니다. 10.12.17 66 0
225549 형들 미안한대 이 코드좀 봐줘여 [6] 시그란♬갤로그로 이동합니다. 10.12.17 75 0
225546 치킨은 치킨치킨함여 [3] DMW(125.138) 10.12.17 109 0
225542 프로그래밍 하는거 가르쳐달라고 하는데 귀찮을때 방법 [2] BTTTS!갤로그로 이동합니다. 10.12.17 120 0
225541 c말인데... [2] 이벵(112.173) 10.12.17 61 0
225540 글삭제가 안된다. BTTTS!갤로그로 이동합니다. 10.12.17 30 0
225539 c말인데... [1] 이벵(112.173) 10.12.17 50 0
225538 xna 3.0에서 작성한 프로그램이 xna 4.0에서 컴파일이 안되네 [4] *&^(*(189.76) 10.12.17 101 0
225537 출장갔다가 방금 복귀 [3] Rei@디씨갤로그로 이동합니다. 10.12.17 74 0
225536 횽들아 질문좀 할게요 ㅠㅠㅠ(최적화 관련 ㅠㅠ) [5] dreambreaker(121.169) 10.12.17 51 0
225535 0/1 배낭 [2] 이단아갤로그로 이동합니다. 10.12.17 50 0
225534 현대사회에서의 프로그래밍은 이미 정점을 달했다고 본다. [3] 켁큇갤로그로 이동합니다. 10.12.17 162 0
225533 php GET 받아올때 &가 들어 가면 도중에 끈기는 현상 [20] 준치◕‿◕갤로그로 이동합니다. 10.12.17 139 0
225532 스피드 퀴즈 [3] qqq(119.196) 10.12.17 98 0
225527 고급레스토랑용 주문 어플어떠냐? [9] 홍어(58.180) 10.12.17 170 0
225526 Hello World [1] 뿌우(61.72) 10.12.17 63 0
225525 전세계에 스마트 열풍이 불어닥치고 있다 [3] DMW(125.138) 10.12.17 150 0
225524 야 안드로이드에 자료구조로 컬렉션 쓰면 개객끼냐? [6] 홍어(58.180) 10.12.17 155 0
225523 자바소켓통신 원래 어려운거임? [4] 시크한훈남갤로그로 이동합니다. 10.12.17 146 0
225522 횽들 visual c++ 파일 열기 하니깐 메모리를 참조 할 수 업다? [6] 123(114.206) 10.12.17 109 0
225521 팩알고리즘 짜봤음 [2] elwlwlwk갤로그로 이동합니다. 10.12.17 113 0
225518 math.h에 거듭제곱 함수 있나요? [5] elwlwlwk갤로그로 이동합니다. 10.12.17 191 0
225517 원래 언어는 기계어 부터 배워야 되는건데 [9] 홍어(58.180) 10.12.17 204 0
225516 도와줘~!~ [5] 잡대생(218.50) 10.12.17 73 0
225515 할껀많은데 심심하다.. [4] 꿀레갤로그로 이동합니다. 10.12.17 120 0
225514 아 나는 머리가 돌인가 -_-;; 방향 좀... [1] 썬잡아갤로그로 이동합니다. 10.12.17 104 0
225513 ↓지뢰지대 삼치맛우유(110.15) 10.12.17 50 0
225512 하악하악 아이유 [4] 유리한갤로그로 이동합니다. 10.12.17 174 0
225511 CRC 코드 아는 님들 있나요???? [3] fdfd(119.196) 10.12.17 255 0
225509 초짜에겐 10000! 프로그램이 너무 어렵습네다 [1] 컴맹늅늅이(121.135) 10.12.17 120 0
225506 그깟 irc밴당했다고 아쉬워 할필요없음 [1] 르하소갤로그로 이동합니다. 10.12.17 107 0
225503 스마트폰을 위한 무선충전 시스템 같은거 가능하냐? [3] 홍어(58.180) 10.12.17 73 0
225501 버스안에서 자다가 정류장 지나침ㅠ- 꿀레갤로그로 이동합니다. 10.12.17 72 0
225498 2000만 팩 [1] 이단아갤로그로 이동합니다. 10.12.17 89 0
225493 오브ㅈㅌㅂ씨 진짜 초보임.. ㅠㅠ 도와주셈 ㅠㅠ [3] fdfd(119.196) 10.12.17 56 0
225492 방학때 공수나 파야지 [4] 이단아갤로그로 이동합니다. 10.12.17 87 0
225491 아 휘밤 방금 종나 엄청난 사업아이디어가 떠올랐다. [2] 홍어(58.180) 10.12.17 112 0
225489 그리드 팩토리얼 구현해봐. 홍어(58.180) 10.12.17 81 0
225488 니네 내가 누군지 모르나본데, [3] new gay[max](183.105) 10.12.17 116 0
225486 야 요즘엔 멀티코어가 일반화되었는데 팩떡밥도 진화되야지 [5] 홍어(58.180) 10.12.17 102 0
225485 프로그래머 수준별 팩토리얼 프로그램 짜는법은 어떨까? [5] 컴맹늅늅이(121.135) 10.12.17 173 0
225483 c에서 1000000! 출력하려면 자료형이 뭐여야되죠??? [12] 컴돌이(58.77) 10.12.17 213 0
225482 소프트웨어 갤이랑 프갤이랑 뭔차이임? [4] SebasT갤로그로 이동합니다. 10.12.17 127 0
225481 인셉션을 봤는데 이해 안되는점 Vita500갤로그로 이동합니다. 10.12.17 162 0
225479 신종플루의 위엄 nRST갤로그로 이동합니다. 10.12.17 63 0
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

뉴스

디시미디어

디시이슈

1/2