일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
- osaka
- 2858번
- 2025
- 10814번
- vscode
- 경로 찾기
- 11047번
- 레스트리s20
- insertion sort
- 동전0
- 나이순정렬
- 정렬알고리즘
- Algorithm
- Anaconda
- 헤브나인스파
- 서머싯몸
- python
- Baekjoon
- 리솜포레스트
- Beakjoon
- 민음사북클럽
- 정대건
- 인생의베일
- 민음사
- 11403번
- bubble sort
- Sort Algorithm
- 기숙사 바닥
- Selction Sort
- 리솜리조트
- Today
- Total
JIyeon's life
[Data structure] linked list sort하기! 본문
자료구조
linked list sort
linked list sort
<소스코드>
#include <iostream> #include <cstdio> #include <stdlib.h> using namespace std; typedef struct node { int data; node *link; } node; int main() { node *head = NULL; node *tmp, *prev, *p; int n, x; printf("갯수 입력:"); scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &x); tmp = (node *)malloc(sizeof(node)); tmp->data = x; tmp->link = NULL; if (head == NULL) head = tmp; else { if (x < head->data) { tmp->link = head; head = tmp; } else { p = head; while (p != NULL && x > p->data) { prev = p; p = p->link; } tmp->link = prev->link; prev->link = tmp; } } } p = head; while (p != NULL) { printf("%d-> ", p->data); p = p->link; } while (head != NULL) { p = head->link; free(head); head = p; } return 0; } |