c++ 자료구조 삽입정렬 질문
-
게시물 수정 , 삭제는 로그인 필요
#include<stdio.h>
int Q[]={40,10,20,50,30};
int p, n, j, i;
int insert(int K, int i);
void main()
{
n=10;
printf("insert sort\n\n");
printf("원본 데이터");
for(i=0; i<=n; i++)
printf("%4d", Q[i]);
printf("\n\n");
for(j=0; j<=n; j++)
{
p=Q[j];
insert(p,j-1);
printf("단계 = %2d", j);
for(i=0; i<=n ; i++)
printf("%4d", Q[i]);
printf("\n\n");
}
}
int insert(int K, int i)
{
int j;
j=i;
while(K<Q[j])
{
Q[j+i]=Q[j];
j=j-1;
}
Q[j+1]=K;
}
--------------------Configuration: 15_IS - Win32 Debug--------------------
Compiling...
15_IS.CPP
E:\C++\15_IS\15_IS.CPP(35) : error C2561: 'insert' : function must return a value
E:\C++\15_IS\15_IS.CPP(4) : see declaration of 'insert'
Error executing cl.exe.
15_IS.exe - 1 error(s), 0 warning(s)
오류 질문이요.. 어떻게 고쳐야 하죠??
int insert도 이해가 잘안가는데 이것도 좀 알려주시면 ㄳ
#include<stdio.h>
int Q[]={40,10,20,50,30};
int p, n, j, i;
int insert(int K, int i);
void main()
{
n=10;
printf("insert sort\n\n");
printf("원본 데이터");
for(i=0; i<=n; i++)
printf("%4d", Q[i]);
printf("\n\n");
for(j=0; j<=n; j++)
{
p=Q[j];
insert(p,j-1);
printf("단계 = %2d", j);
for(i=0; i<=n ; i++)
printf("%4d", Q[i]);
printf("\n\n");
}
}
int insert(int K, int i)
{
int j;
j=i;
while(K<Q[j])
{
Q[j+i]=Q[j];
j=j-1;
}
Q[j+1]=K;
}
--------------------Configuration: 15_IS - Win32 Debug--------------------
Compiling...
15_IS.CPP
E:\C++\15_IS\15_IS.CPP(35) : error C2561: 'insert' : function must return a value
E:\C++\15_IS\15_IS.CPP(4) : see declaration of 'insert'
Error executing cl.exe.
15_IS.exe - 1 error(s), 0 warning(s)
오류 질문이요.. 어떻게 고쳐야 하죠??
int insert도 이해가 잘안가는데 이것도 좀 알려주시면 ㄳ
#c++ 자료구조 #c++ 자료구조 책 추천 #c++ 자료구조론 #c++ 자료구조 책 #c++ 자료구조 pdf #c++ 자료구조 강의 #c++ 자료구조론 pdf #c++ 자료구조론 2판 pdf #c++ 자료구조 알고리즘 #c++ 자료구조 종류