文章
55
粉丝
100
获赞
12
访问
33.1k
#include <iostream>
#include <vector>
#include<string>
#include<malloc.h>
#include<algorithm>
using namespace std;
typedef struct LinkNode{
int data;
struct LinkNode *next;
}LinkNode,*LinkList;
//采用头插法,因为头插法会逆置原始数组,则将arr先按从大大小排序后再传进来
LinkList create(LinkList &L,int arr[],int n){
L = (LinkList) malloc(sizeof(LinkNode));
L->data = 0;
L->next = NULL;
LinkNode *p;
int j = 0;
while(j < n){
p = (LinkNode*) malloc(sizeof(LinkNode));
p->data = arr[j];
p->next = L->next;
L->next = p;
j++;
}
return L;
}
bool cmp(int a, int b){
return a>b;
}
void PrintList(LinkList L){
LinkNode *p = L->next;
while(p != NULL){
cout<<p->data<<" ";
p = p->next;
}
cout<<endl;
}
int main() {
int n;
while(cin>>n){
int arr[1000] = {0};
for(int i = 0; i<n; i++){
cin>>arr[i];
}
sort(arr,arr+n,cmp);
LinkList L;
create...
登录后发布评论
暂无评论,来抢沙发