文章
5
粉丝
84
获赞
2
访问
4.2k
#include<stdio.h>
#include<string>
#include <stdlib.h>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
int s[10];
struct node {
int element;
struct node *next;
};
struct node* create() {
struct node* head, *now, *pre;
for (int i = 1; i <= 5; i++) {
now = (struct node*)malloc(sizeof(node));
now->element = s[i];
if (i == 1)
{
head = now;
pre = now;
continue;
}
pre = now;
}
return head;
}
void print(struct node *head) {
struct node *p;
p = head;
while (p != NULL){
cout << p->element << endl;
p = p->next;
}
}
int main() {
for (int i = 1; i <= 5; i++)
cin >> s[i];
sort(s, s + 5);
struct node* head;
head = create();
print(head);
return 0;
}
登录后发布评论
排序是s+1,s+6
还少了两句
now->next=NULL;
pre->next=now;