#include <stdio.h>
#include <stdlib.h>

typedef struct listNode{
 struct listNode* link;
 int data;
}listNode;
typedef struct linkedList_h{
 listNode* head;
}linkedList_h;

linkedList_h* createLinkedList_h(){
 linkedList_h* L = (linkedList_h*)malloc(sizeof(linkedList_h));
 L->head = NULL;
 
 return L;
}

void insertLastNode(linkedList_h* L, int data){
 listNode* newNode = (listNode*)malloc(sizeof(listNode));
 newNode->link = NULL;
 newNode->> 
 if(L->head == NULL){
  L->head = newNode;
  return;
 }
 
 listNode* p = L->head;
 
 while(p->link != NULL)
  p = p->link;
  
 p->link = newNode;
}

void printList(linkedList_h* L){
 listNode* p = L->head;
 
 for(; p; p=p->link)
  printf("%d ", p->data);
}

void sortNode(linkedList_h* L){
 listNode* pre = L->head;
 listNode* current = L->head->link;
 
 while(current->link != NULL){
  if(pre->data > current->data){
   int t = pre->data;
   pre->>    current->>  }
  
  pre = current;
  current = current->link;
 }
}

void main(){
 linkedList_h* L = createLinkedList_h();
 insertLastNode(L, 20);
 insertLastNode(L, 10);
 insertLastNode(L, 50);
 insertLastNode(L, 30);
 insertLastNode(L, 40);
 
 sortNode(L);
 
 printList(L);
 
 system("pause");
}

 

sortNode 부분에서 마지막노드가 정렬이 안됨. 왜안되는지는 알겠는데

어떻게해야 깔끔하게 고칠 수 있을까?