게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
아까 퀵소트 질문 올렸엇는데 논리 오류가 난거 같에요 뭐가 문젠
게시물ID : computer_91530짧은주소 복사하기
작성자 : 블루코크와인
추천 : 0
조회수 : 446회
댓글수 : 4개
등록시간 : 2013/06/09 00:00:29

지 모르겟어요 ㅠㅠ 이름을 퀵소트로 정렬 하는 프로그램을 짯는데 어느 부분이 문제인지 말해주십사 글을 올리옵니다 ㅠ

 

#include <stdio.h>
#include <string.h>
#define MAX_SIZE 10
#define SWAP(x, y, t) (strcpy(t, x), strcpy(x, y), strcpy(y, t))

typedef struct student {
 char name[20];
} student;

student stu[10] = {
  {"김지헌"}, {"권태희"}, {"김승현"},
  {"김동현"}, {"김연우"}, {"서보준"},
  {"정홍석"}, {"정홍철"}, {"이혜란"},
  {"김영광"} };

int partition(student list[], int left, int right)
{
 char pivot[20];
 char temp[20];
 int low, high;
 low = left;
 high = right+1;
 strcpy(pivot, list[left].name);
 do {
  do low++;
  while(low <= right && (strcmp(list[low].name, pivot) == -1));
  do high;
  while(high >= left && (strcmp(list[high].name, pivot) == 1));
  if(low < high) SWAP(list[low].name, list[high].name, temp);
 } while(low < high);

 SWAP(list[left].name, list[high].name, temp);
 return high;
}

void quick_sort(student list[], int left, int right)
{
 if(left < right) {
  int q = partition(list, left, right);
  quick_sort(list, left, q-1);
  quick_sort(list, q+1, right);
 }
}

int main(void)
{
 int i, n =10;
 
 printf("<퀵소트하기 전 상태>\n");

 for(i = 0; i < 10; i++)
 {
  printf("     %s\n", stu[i].name);
 }
 quick_sort(stu, 0, n-1);

 printf("<퀵소트를 한 후 상태>\n");

 for(i = 0; i < 10; i++)
 {
  printf("     %s\n", stu[i].name);
 }

 return 0;
}

전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호