디시인사이드 갤러리

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

갤러리 본문 영역

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

초보.ㅡㅜ(202.31) 2010.10.20 15:22:14
조회 170 추천 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 - -
225738 오늘 시험보고와서 할일. [9] Minryu갤로그로 이동합니다. 10.12.19 224 0
225737 내일은 기말고사 유리한갤로그로 이동합니다. 10.12.19 77 0
225736 징징짜지 말고 차라리 어그로를 올려라. ㅁㄴㅇㄹ(175.200) 10.12.19 102 0
225733 c++에서도 memset써? [3] 르하소갤로그로 이동합니다. 10.12.19 170 0
225731 디시에 악성코드 심어졌음? [2] ㅇㅇㅇ(211.198) 10.12.19 142 0
225730 신난다! [3] 꿀레갤로그로 이동합니다. 10.12.19 98 0
225729 형아들 되고싶어 [1] 미클갤로그로 이동합니다. 10.12.19 120 0
225728 형아들 살고싶어 [3] 아주아슬갤로그로 이동합니다. 10.12.19 123 0
225727 형아들 죽고싶어 [12] 르하소갤로그로 이동합니다. 10.12.19 221 0
225726 먹튀하는 새끼 개새끼 아주아슬갤로그로 이동합니다. 10.12.19 128 0
225725 횽아들 MEECL < 그냥 이 단어 보면 뭐가 떠올라? [6] 미클갤로그로 이동합니다. 10.12.19 101 0
225722 아 씨발 프로젝트 먹튀 [30] 일광면(119.198) 10.12.19 584 0
225721 좋다.. 15000원에 착불한다. 신청바람. [16] ㅇㅇ(112.159) 10.12.19 188 0
225720 혹시 패킷에서 User-Agent 값 볼 줄 아는형들 답변좀 줘 ㅠㅠ [4] 김좆밥갤로그로 이동합니다. 10.12.19 67 0
225719 에이좋다, 그럼 2만원에 착불로하자. [9] ㅇㅇ(112.159) 10.12.18 153 0
225718 좋다 이거 3권 다해서 2만5천에 착불어떠냐? [8] ㅇㅇ(112.159) 10.12.18 172 0
225717 아꺼 오후에 무료 강의하고 싶다고 했잖습니까 [9] nRST갤로그로 이동합니다. 10.12.18 126 0
225716 C++ 에서 생성자 파괴자 이거 왜쓰는거에엿? [7] ㅇㅇ(211.169) 10.12.18 158 0
225713 오래간만에 어려운 떡밥을 뿌림 [4] 116.44(116.44) 10.12.18 95 0
225712 컴퓨터 관련 책팝니다. [6] ㅇㅇ(112.159) 10.12.18 163 0
225710 C++ 소수점을 그냥 버리는 방법 어떤게 있을까요? [2] 꼬비갤로그로 이동합니다. 10.12.18 252 0
225709 자신만의 참고자료, 정보 관리 방법을 공유해 보자~~ [9] (121.159) 10.12.18 115 0
225708 또왔슴다 [2] Grand갤로그로 이동합니다. 10.12.18 76 0
225707 형들 opengl에서말야 [2] 주시미갤로그로 이동합니다. 10.12.18 62 0
225706 작업환경 인증 [5] 미클갤로그로 이동합니다. 10.12.18 152 0
225704 해시함수 관련 공부하는데 좀 도와줄분 안계신가요;? [5] 늅늅이(220.69) 10.12.18 207 0
225703 visual c++ 6좀 보내주세요 부탁드립니다. [5] 123(114.206) 10.12.18 93 0
225701 횽들 visual c++에서 파일 열기 하면 ....... [3] 123(114.206) 10.12.18 128 0
225700 점심먹구 잠시 책을 보구 있었는데 [1] DMW갤로그로 이동합니다. 10.12.18 60 0
225698 아놔 망할 경전차들 elwlwlwk갤로그로 이동합니다. 10.12.18 53 0
225697 디씨 바이러스 최트루같은데 ■이기철갤로그로 이동합니다. 10.12.18 130 0
225696 obj c ㅆㅂ 1212(122.45) 10.12.18 56 0
225695 시발 디씨 바이러스 먹었네 [1] ㄴㄴㄴㄴ(189.76) 10.12.18 158 0
225694 이구아인생인데 물리선택하고 수리는병신이라 나형..으으 적응할수있을까 [2] ■이기철갤로그로 이동합니다. 10.12.18 57 0
225693 이것 좀 봐주라 [1] 지지(112.151) 10.12.18 40 0
225692 프로그래밍갤러들은 수학,물리도 잘할듯 [3] ■이기철갤로그로 이동합니다. 10.12.18 155 0
225691 횽들 포인터좀 도와주세요 [3] ㅇㅇ(112.149) 10.12.18 60 0
225690 횽들 jsp 연봉 공유좀... [4] jsp(121.140) 10.12.18 328 0
225689 후킹 연습중인데 이거 왜 인젝션 시키면 프로그램 오류나져 [4] 준치◕‿◕갤로그로 이동합니다. 10.12.18 213 0
225688 asp는 뭐고 닷넷은 뭐야? [11] 1111(121.169) 10.12.18 136 0
225687 웹페이지 이동할대마다 아바스트가 스크립트에 trojan 숨어있다고 차단 [1] ㅎㅎㅎㅎㅎ(122.35) 10.12.18 122 0
225686 1시간 동안 뻘짓해서 만든거. [4] 우쿨렐렝갤로그로 이동합니다. 10.12.18 187 0
225684 내가 살려는 의자 [2] 이단아갤로그로 이동합니다. 10.12.18 95 0
225682 내가 연구소 과장한테 MFC가 왜 안 사라지냐고 질문했음. [1] 116.44(116.44) 10.12.18 156 0
225681 뭔 글 들어갈때마다 바이러스 있다고 뜨네 [5] 오토잇코더갤로그로 이동합니다. 10.12.18 131 0
225680 api 들은 대체 누가 만드는 건가요??? [6] 컴돌이(58.77) 10.12.18 143 0
225679 이펙티브 자바 왔쪄염. 뿌우 머그컵갤로그로 이동합니다. 10.12.18 51 0
225678 홍어형 보셈 -홍어형전문짤빵있음- 유리한추종자(118.91) 10.12.18 64 0
225677 형들 자바 궁금한거<존 나 쉬움> [14] 유리한추종자(118.91) 10.12.18 179 0
225676 SAX파싱질문 있습니다 [8] valenciak갤로그로 이동합니다. 10.12.18 97 0
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

뉴스

디시미디어

디시이슈

1/2