디시인사이드 갤러리

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

갤러리 본문 영역

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

초보.ㅡㅜ(202.31) 2010.10.20 15:22:14
조회 179 추천 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 - -
공지 프로그래밍 갤러리 이용 안내 [88] 운영자 20.09.28 45306 65
2870689 GPT랑 gemini 조련 중 아스카영원히사랑해갤로그로 이동합니다. 16:33 3 0
2870688 클로드도 코드좀 치지 않음? [3] 프갤러(175.208) 16:05 16 0
2870687 애플 디벨로퍼 아카데미? [1] 프갤러(118.235) 15:52 26 0
2870684 하 씨발 1차 납품했는데 버그 원인을 못찾겠어 [5] ㅆㅇㅆ(124.216) 15:14 45 0
2870682 정좌불능증 [3] 재현갤로그로 이동합니다. 14:53 24 0
2870680 덥다 [3] 루도그담당(211.235) 14:31 30 0
2870675 제미니 글쓰기 좋다. 수백 페이지 입력 가능 [3] 루비갤로그로 이동합니다. 12:58 36 0
2870673 [대한민국] 모스탄 대사 그라운드 씨에 출현 예정- [1] 프갤러(121.172) 12:37 21 0
2870672 코드 가장 잘 짜는 AI 뭐냐? [13] 아스카영원히사랑해갤로그로 이동합니다. 12:18 105 0
2870671 종종 끌올되는 픎 자컨팀 빼앗겼다는 날조선동 ㅇㅇ(110.70) 12:01 35 0
2870670 지피티 씨발 존나 답답하네 [1] 아스카영원히사랑해갤로그로 이동합니다. 11:38 57 0
2870669 한국에 과학수사 포렌식 이런직업이 많은이유는 뒷통수한방(1.213) 11:14 48 0
2870668 저커버거 빌게이츠 머스크 이런애들 좇센에서태어났으면 뒷통수한방(1.213) 11:02 50 1
2870667 헬마님 질문이 있습니다 [7] 아스카영원히사랑해갤로그로 이동합니다. 09:59 65 0
2870666 짱깨폭염 짱깨들 전부 좇센으로 물들었네 뒷통수한방(1.213) 09:55 22 0
2870664 자러 간다~ ㅇㅅㅇ 헤르 미온느갤로그로 이동합니다. 09:29 13 0
2870662 흑흑.. 내컴이 내 선풍기 가져갔다.. ㅇㅅㅇ [5] 헤르 미온느갤로그로 이동합니다. 09:21 39 0
2870658 게임엔진개발자 맥북 [7] 미니애폴리스갤로그로 이동합니다. 07:30 69 0
2870655 완결) 러스트 담론을 해체하다 루비갤로그로 이동합니다. 06:36 44 1
2870653 나팔 ㅇㅅㅇ 헤르 미온느갤로그로 이동합니다. 04:24 25 0
2870652 태연 ㅇㅅㅇ 헤르 미온느갤로그로 이동합니다. 03:44 27 0
2870651 하루 한 번 헤르미온느 찬양 헤르 미온느갤로그로 이동합니다. 03:41 30 0
2870649 백신맞고 몸 망가진 2찍들은 국짐당 원망해야지 [8] 야옹아저씨갤로그로 이동합니다. 02:42 149 5
2870648 1일 1딸 멈추라고 하시면 멈추겠습니다. [3] 도리스아(121.139) 02:32 46 0
2870647 나는 기후위기를 걱정한 적이 없었는데 [9] 아스카영원히사랑해갤로그로 이동합니다. 01:34 76 0
2870646 MCP 에이전트로 코딩하면서 나는 프로그래밍 책 읽고 있는데 ㅆㅇㅆ(124.216) 01:24 43 0
2870644 그러고보니 예전 프갤러들 싹 사라졌네 [4] 박민준갤로그로 이동합니다. 00:48 124 1
2870643 울산에서 일하는 31살 공장충인데 지금 입문 어떻게 생각해 [6] ㅇㅇ(118.235) 00:25 121 0
2870642 바탕화면에 공룡 키워 보세요.... 프갤러(118.41) 07.08 90 2
2870641 프갤하는거 들켰다 프갤러(220.65) 07.08 39 0
2870639 성추행해서 미안해 너무 아파서 그랬어... 넥도리아(223.38) 07.08 38 0
2870638 고1 프로그래밍에 손을 대보려합니다 [9] 프갤러(218.239) 07.08 117 0
2870636 가끔 나 따라 다니는 유동 저거 냥덩이 아닐까 한다 [1] ㅆㅇㅆ(124.216) 07.08 56 0
2870635 조루디 ㅆㅇㅆ 잘어울려 ㅇㅇ(211.235) 07.08 44 3
2870633 R 뭐 배우는데 OLD R베이스 문법? [2] ㅆㅇㅆ(124.216) 07.08 56 0
2870632 결혼하면 프갤러들 축의금 줘 [4] 조루디(110.35) 07.08 63 0
2870631 R은 대학원 갈 거 아니면 뭐 쓸 일 거의 없을텐데 ㅆㅇㅆ(124.216) 07.08 33 0
2870630 제발 한숨쉬지마세요 노처녀드라 [1] 조루디(110.35) 07.08 61 0
2870629 문관데 제발 도와주세요 제발 제발제발 [15] 프갤러(118.47) 07.08 100 0
2870627 주식대박났다 [2] 조루디(110.35) 07.08 95 0
2870624 면접보면서 당황했던 경험 ㅇㅇ(112.169) 07.08 33 0
2870622 17일 도쿄 여행인데 아스카영원히사랑해갤로그로 이동합니다. 07.08 56 0
2870620 PC-6001 페이지용 Contiki 발명도둑잡기(118.216) 07.08 26 0
2870618 국비들으면 쉽게 취업하는시대일때 국비 짤린거면 얼마나 병신새끼인거임?? 뒷.통수한방(1.213) 07.08 95 1
2870617 좆같은 기술스택을 쓰고있다 <- 탈출해야함 프갤러(59.14) 07.08 49 0
2870615 어우 일나가기 실타..ㅇㅅㅇ 헤르 미온느갤로그로 이동합니다. 07.08 21 0
2870613 러스트 비판서 거의 다 썼다. 루비갤로그로 이동합니다. 07.08 35 0
2870610 냥덩이는 그냥 귀척하는 윤서인이라봐야 [2] 류류(115.136) 07.08 51 0
2870609 윤석열 무능한건 맞지않나 ㅇㅅㅇ 류류(115.136) 07.08 28 0
뉴스 최고의 성형은 다이어트? 박수홍 아내 30kg 감량으로 예전 모습 되찾아...같은 옷 다른 느낌 디시트렌드 10:00
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

뉴스

디시미디어

디시이슈

1/2