디시인사이드 갤러리

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

갤러리 본문 영역

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

초보.ㅡㅜ(202.31) 2010.10.20 15:22:14
조회 178 추천 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
본문 보기

하단 갤러리 리스트 영역

왼쪽 컨텐츠 영역

갤러리 리스트 영역

갤러리 리스트
번호 제목 글쓴이 작성일 조회 추천
설문 끝까지 다 본 걸 후회하게 만든 용두사미 드라마는? 운영자 25/07/07 - -
344260 안드로이드에서 로그(log)읽는법 아는 형님 잇어??? ㅠㅠ [10] ㅋㅋㅋ(203.246) 13.01.28 163 0
344259 자바로 취직하려는데 [1] (211.234) 13.01.28 128 0
344258 액티브엑스 ㅅㅂ ㅠㅠ [2] 나리링갤로그로 이동합니다. 13.01.28 103 0
344257 형들중 회사에서 하는 사람들 있나? 대부분인가? [5] 공학관갤로그로 이동합니다. 13.01.28 184 0
344255 이거 왜 오류나는건가요? [1] 개초보(121.185) 13.01.28 54 0
344254 boost 이거 뭐임 시밸? [2] 부스타(175.197) 13.01.28 87 0
344252 it취업학원 다닌 사람들 조언좀.. [8] ㅁㅈㅇ(121.165) 13.01.28 769 0
344251 인생을 잘못살았는데 우회하기 힘드네 (211.234) 13.01.28 108 0
344250 꿀꿀해 [1] (211.234) 13.01.28 40 0
344249 java - jsp - html,javascript 글구 데이터베이스? [2] 상상(175.123) 13.01.28 163 0
344248 횽들 mfc로 창을 접었다 폈다 하는거 어떤식으로 프로그래밍한거야? [2] 김삼디(110.9) 13.01.28 128 0
344247 교수님한테 메일로 정중하게 질문하면 잘 받아주나?? [6] 삐쭊이(175.223) 13.01.28 162 0
344243 매미새끼들 다없어졌네 얼룩돼지갤로그로 이동합니다. 13.01.28 60 0
344242 ㄷㄷ 지금 입대하러가는중 [4] elwlwlwk(175.223) 13.01.28 157 0
344241 2차원 배열에서 배열의 이름이 가리키는게 첫번째 요소맞죠? [1] 2차원배열(202.30) 13.01.28 106 0
344239 국가가 나한테 주는게 머냐 [7] ?(123.142) 13.01.28 255 0
344238 원도우8로 액티브x 은행결제 전자거래 가능하나요? [2] 원도우8로 액(59.11) 13.01.28 126 0
344237 형들아 저 컴퓨터 잘 하고 싶어요 [2] 에어로홍갤로그로 이동합니다. 13.01.28 104 0
344236 신입입니다. [4] 와즈갤로그로 이동합니다. 13.01.28 202 0
344235 혹시대학다니는형들잇으면 무슨과? [3] ㅇㅇㄷㄱ(39.7) 13.01.28 159 0
344234 프로그램에 호출? 주는기능을 뭐라고합디까 [1] ㅂㅈㄷ(14.45) 13.01.28 120 0
344233 카페에서 커피하나시키면 최대몇시간?공부가능? [6] 염산.갤로그로 이동합니다. 13.01.28 190 0
344231 진로이 고민 전기공학과 vs 개발자 [3] 응응이(118.127) 13.01.28 225 1
344230 현업에계신분들이 대답을 안해주시네 그렇다면 다른질문.ㅠㅠ [2] 질문(221.155) 13.01.28 155 0
344229 아...... 비주얼 스튜디오 2010....에러가 왜나지?형들ㅠ 도와줘 [11] 소년사나이갤로그로 이동합니다. 13.01.27 197 0
344228 내 방에 귀신나온다 [1] dlbo갤로그로 이동합니다. 13.01.27 102 0
344226 프래임워크는 어떻게 공부해야함? [1] ㅇㅇ(58.229) 13.01.27 78 0
344225 현업에 종사하시는분들 질문있습니다. [2] 질문(221.155) 13.01.27 123 0
344224 나의 일요일을 반납한 에러...횽들아 한번만 봐줘.. [2] 신발샛길(121.169) 13.01.27 162 0
344223 방망이 깎던 노인 패러디 더 없음? 소년사나이갤로그로 이동합니다. 13.01.27 110 0
344222 횽들 fmod 짜증나요 노래가 한 채널에 중복되서 생성되여 이거 왜 이럼 [2] 우아앙(121.88) 13.01.27 543 0
344220 애플 할인 행사때 맥북 할인하는거 존나 눈에 띄더라 [4] 돌대갈(116.33) 13.01.27 150 0
344218 커피값 삼사천원 밖에 안 되는 커피점 동대문구에 있다 [3] 에어로홍갤로그로 이동합니다. 13.01.27 82 0
344217 오자마자 질문하나 합니다 [1] ㅇㅇ(1.250) 13.01.27 137 0
344216 차단 풀렸다 [5] 에어로홍갤로그로 이동합니다. 13.01.27 81 0
344213 자바indexof에서 [4] (14.138) 13.01.27 406 0
344211 암호화할 때 소수가 쓰여??? [12] dd(203.90) 13.01.27 179 0
344210 내 닉네임에 불만 있는 사람 있나? [8] 두정갑(121.167) 13.01.27 127 1
344209 형님들 파이썬 하나만 물어볼테니 제발 답해주세여 [6] Python잉여(221.161) 13.01.27 108 0
344208 이스라엘 개발자들은 프로그래밍을 어떻게 하지? [12] 경번갑(121.167) 13.01.27 336 2
344207 형들아까 카페제목 지어달라는 새낀데 [27] 털자털기갤로그로 이동합니다. 13.01.27 200 0
344206 노무현이 사망한 이유를 물리학적으로 분석한 알고리즘 좀 짜주세요. [7] VERISM갤로그로 이동합니다. 13.01.27 196 0
344205 성님들 mysql 쉘 스크립트랑 grep명령어 질문입니다 [8] 123(58.233) 13.01.27 102 0
344204 형들 프로그래밍 카페만들건데 [6] 털자털기갤로그로 이동합니다. 13.01.27 128 0
344203 형들 c 중간까지 하고 컴구조 다 배운뒤 웹 프로그래밍 하려면 어떻게.. [2] 상상(175.123) 13.01.27 96 0
344201 보안전문가 될건데 [3] dddx(58.232) 13.01.27 171 0
344200 형들이제 에펙을 할려하는데 말이야 [5] 초보(112.145) 13.01.27 98 0
344199 Python 질문 두개만 물어볼게요. [2] 왕초보(221.161) 13.01.27 77 0
344198 [C++]함수 객체에 대한 내용 [1] ssonacy갤로그로 이동합니다. 13.01.27 212 0
344197 [C++] 맴버템플릿 함수 [1] ssonacy갤로그로 이동합니다. 13.01.27 45 0
뉴스 '화려한 날들' 배우 이태란, ‘세련 미모’ 뽐내며 감각적인 재벌 안주인 고성희 役으로 완벽 변신! 디시트렌드 07.07
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

뉴스

디시미디어

디시이슈

1/2