文章
79
粉丝
0
获赞
508
访问
20.1k
#include<iostream>
using namespace std;
struct Node {
int val;
struct Node *next;
Node(int x): val(x), next(NULL) { }
};
int main() {
Node *node = new Node(-1);
Node *head = node;
head->next = NULL;
for (int i = 0; i < 5; i ++ ) {
int x;
cin >> x;
Node *s = new Node(x);
s->next = head->next;
head->next = s;
}
for (Node *p = head->next; p ; p = p->next) {
for (Node *q = head->next; q ; q = q->next) {
if (q->next && q->val > q->next->val)
swap(q->val, q->next->val);
}
}
Node *p = head->next;
while (p) {
cout << p->val << ' ';
p = p->next;
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发