Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- struct listNode{
- int val;
- struct listNode* next;
- };
- int main() {
- struct listNode* root;
- size_t size = 0;
- int x;
- scanf("%d", &x);
- struct listNode* now = root;
- while (x != 0) {
- now->val = x;
- struct listNode* nd = (struct listNode*)malloc(size + 1);
- now->next = nd;
- now = nd;
- size++;
- scanf("%d", &x);
- }
- for (int i = 0; i < size - 1; ++i) {
- now = root;
- for (int j = 0; j < size - i - 1; ++j) {
- if (now->val > now->next->val) {
- int t = now->val;
- now->val = now->next->val;
- now->next->val = t;
- }
- now = now->next;
- }
- }
- now = root;
- for (int i = 0; i < size; ++i) {
- printf("%d ", now->val);
- now = now->next;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment