디시인사이드 갤러리

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

갤러리 본문 영역

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

초보.ㅡㅜ(202.31) 2010.10.20 15:22:14
조회 172 추천 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 - -
225969 형들 return ; 가 의미하는게 뭐죠? [7] ㅇㅇ(125.132) 10.12.20 168 0
225966 우왕 넷빈즈 자동으로 코드도 생성해주고 자바 존나좋다 [3] 개쉛기갤로그로 이동합니다. 10.12.20 151 0
225965 달팽이 더 간단하게 해봤삼. [1] 늅늅(202.136) 10.12.20 125 0
225962 16진수 표현좀.... [4] ㄷㅈㅁㄴ(183.109) 10.12.20 139 0
225961 C 언어 질문 있습니다 ㅠ.ㅠ 컴파일은 되는데 실행하면 에러 [4] 드록신(121.88) 10.12.20 105 0
225959 오잉 박찬호 오릭스행?? 시불라미갤로그로 이동합니다. 10.12.20 48 0
225957 달팽이 함 해봤삼. 자바로. 늅늅(202.136) 10.12.20 97 0
225956 자바하는 형들, 넷빈즈랑 이클립스 머가 더 좋음? [2] ㅂㅂ(112.221) 10.12.20 114 0
225955 effective시리즈는 진리입니다 [1] 아잉따잉갤로그로 이동합니다. 10.12.20 105 0
225954 갑자기 꿈 한 부분의 내용이 기억났는데 aszx(211.206) 10.12.20 46 0
225953 이제 대학생되는데 질문좀 [13] sd(203.130) 10.12.20 223 0
225952 이펙티브 자바 괜히 샀다. [5] 머그컵갤로그로 이동합니다. 10.12.20 204 0
225951 친구놈이 자꾸 포격드립치는데 [4] aszx(211.206) 10.12.20 126 0
225950 피파 하는횽들 없음메? [1] 캐꼬꼬닭(112.216) 10.12.20 56 0
225949 사격 게시됨 ㄷㄷㄷ 2:30분 정도 부터래 [2] 시불라미갤로그로 이동합니다. 10.12.20 101 0
225948 C++로 사용한 MFC 질문좀 할께요 ㅠㅠㅠ [4] 늅뉴빙(121.174) 10.12.20 165 0
225947 자바로 타로카드 보는 프로그램.. [2] 에휴휴휴휴(112.186) 10.12.20 94 0
225946 프로젝트 먹튀;; 진행상황 [15] 일광면(119.198) 10.12.20 427 0
225945 미국가서 성공하는법 [3] 꿀레갤로그로 이동합니다. 10.12.20 170 0
225944 정신이 혼미해진다 [3] 개쉛기갤로그로 이동합니다. 10.12.20 103 0
225943 일어난지 2시간째 [5] elwlwlwk갤로그로 이동합니다. 10.12.20 92 0
225942 미쿡가서 성공하려면 어떻게 해야함여? [6] SebasT갤로그로 이동합니다. 10.12.20 115 0
225941 군복들은 다려 놓으셨슴까? [4] SebasT갤로그로 이동합니다. 10.12.20 140 0
225940 부칸 핵사찰단 다시 복귀하라고 어쩌고 뉴스 나왔넹 [3] 시불라미갤로그로 이동합니다. 10.12.20 82 0
225939 시펄 결정한 치타후치타횽 글에 리플 보니까 궁금해서 그러는데 [15] aszx(211.206) 10.12.20 136 0
225938 자바에서 vector 사용중인데요 [4] ㅇㅇ(180.224) 10.12.20 132 0
225936 안드로이드 오류좀 봐주실분? [7] 안드로이드(58.145) 10.12.20 173 0
225933 아흨 VirtualBox에 Debian 깔고 통신좀 하려 했더니 [4] foriequal0갤로그로 이동합니다. 10.12.20 173 0
225931 형님들.. 전졸예정 컴정과학생인데 좀 상담좀요 [2] 뉴비(203.229) 10.12.20 139 0
225929 이 불쌍한 중생에게 가르침을 주십시오 [2] (118.131) 10.12.20 66 0
225928 미국에선 컴싸전공 한다고 하면 진짜 미래의 엘리트 취급받는데 [2] ㅇㅇ(74.60) 10.12.20 321 0
225926 opengl 질문 좀~ [3] 헬푸미(112.146) 10.12.20 141 0
225925 님들아 어디로 도망가면 무사할까염? [2] 스몰마인드(121.182) 10.12.20 91 0
225923 Assist 좀 도와줘 [3] ㅇㅅ(110.15) 10.12.20 57 0
225922 랜덤함수를 사용못하면?? [12] asfdafdsafsd(121.65) 10.12.20 165 0
225921 마소의 노예가 된 이유? [2] 훗쇼갤로그로 이동합니다. 10.12.20 159 0
225920 시펄 그래 결정했어! [19] 치타후치타갤로그로 이동합니다. 10.12.20 274 0
225919 덕후 까지 마라... [4] SebasT갤로그로 이동합니다. 10.12.20 147 0
225918 [이지스원] 군특기병(병역특례) 정보보안교육과정 [5] 이지스원교육부갤로그로 이동합니다. 10.12.20 163 0
225917 대학가면 유초중고딩때부터 컴터하더놈 얼마나있어? [27] 치타후치타갤로그로 이동합니다. 10.12.20 235 0
225916 2주일째 똑같은짓 반복중 [2] SebasT갤로그로 이동합니다. 10.12.20 67 0
225914 왠지 프로그래밍하면 졸라 멋있어보임 [7] 치타후치타갤로그로 이동합니다. 10.12.20 160 0
225913 해일리는 또 봅니다. [6] iljeomobolt갤로그로 이동합니다. 10.12.20 110 0
225912 해일리는 봅니다. [6] iljeomobolt갤로그로 이동합니다. 10.12.20 162 0
225910 string 입력과 예외처리 질문좀 [3] 전설의기타리스트갤로그로 이동합니다. 10.12.20 87 0
225909 북한 개객기들.. [3] 꿀레갤로그로 이동합니다. 10.12.20 103 0
225908 안드로이드 좀 이상해.. [7] sdf(119.193) 10.12.20 114 0
225907 곧 연평도사격훈련할듯... [2] 꿀레갤로그로 이동합니다. 10.12.20 77 0
225906 [이지스원] 해킹보안실무교육, 이지스원교육센터 찾아오시는길 [8] 이지스원교육부갤로그로 이동합니다. 10.12.20 155 0
225903 지들이 뭘 원하는지도 모르면서 [5] 해일리갤로그로 이동합니다. 10.12.20 109 0
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

뉴스

디시미디어

디시이슈

1/2