文章

54

粉丝

0

获赞

12

访问

1.1k

头像
单链表 题解:
P1015 贵州大学机试题
发布于2026年1月25日 20:58
阅读数 36

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

vector<int> a;
struct Node{
	int x;
	struct Node *next;
};

Node *l;

int main()
{
	l=new Node;
	l->next=nullptr;
	for(int i=0;i<5;i++)
	{
		int t;
		cin>>t;
		a.push_back(t);
	}
	sort(a.begin(),a.end(),greater<int>());
	for(int i=0;i<a.size();i++)
	{
		Node *node=new Node;
		node->x=a[i];
		node->next=l->next;
		l->next=node;	
	}
	for(Node *p=l->next;p!=nullptr;p=p->next)
		 cout<<p->x<<" ";
	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发