단일연결리스트 버블정렬 질문드립니다.
재넘이
#include stdio.h
#include stdlib.htypedef struct list
{
struct list* link;
int data;}List;List *createNode(){
List *h;
h=(List*)malloc(sizeof(List));
h-data=0;
h-link = NULL;
return h;}void printNode(List *);
void addNode(List*,int );
List* sortNode(List* );int main(int argc, char *argv[])
{
int i;
int copy;
List* L;
L=createNode();
srand((unsigned int)time(NULL));
for(i=1; i9; i++)
{
copy = rand() % 33 + 1;
addNode(L,copy);
}
printNode(L);
L=sortNode(L);
printNode(L);
system(PAUSE);
return 0;
}void printNode(List *L)
{
List *p;
p=L;
while(p-link != NULL)
{
p=p-link;
printf(%3d,p-data);
}printf(\n);
}void addNode(List*L, int data)
{
List *p;
List *newNode;
newNode = createNode();
newNode-data=data;
p=L;
while(p-link != NULL)
{
p=p-link;
}
p-link = newNode;
}List* sortNode(List *L)
{
List *current, *before;
List *search, *ago;
current=L;
ago=L;
search=L-link;
while(search != NULL)
{
if(current-data search-data)
{
before=ago;
current=search;
}
ago=search
search=L-link;
}
if(current != NULL)
{
before-link = search;
current-link = L;
L=current;
}
L-link=sortNode(L-link);
}
------------------------------------------------------현재 위 소스처럼 버블정렬 단일연결리스트로 구현해놨습니다..허나 오류가 뜨고 안되는 부분들이 많습니다..ㅠㅠ한번만 그대로 옮기셔서 컴파일러 해보시고.. 정상적으로 컴파일 작동이 될수있도록...!.. 한번 부탁드리겠습니다.