⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1154.cpp

📁 这是一个简单的排序。给你一个有N个值的数组
💻 CPP
字号:
#include<iostream.h>
//#include<iomanip>
//using namespace std;
struct t
{
	int data;
	struct t *next;
}*q, *p,*head;


void sort(int array[],int n)
{
	int j,i,t,k;
	for(i=0;i<n-1;i++)
	{
		k=i;
		for(j=i+1;j<n;j++)
			if(array[j]<array[k])
			k=j;
			t=array[k];
			array[k]=array[i];
			array[i]=t;
	}
		
}

int main()
{
	int T, N;
	cin>>T;
	head=NULL;
	p=new t;
	q=p;
	for(int i=0;i<T;i++)
	{
		cin>>N;
		while(N<1||N>1000)
		{
			cout<<"Input error!"<<endl;
			cin>>N;
		}
		int *n=new int[N];
		for(int j=0;j<N;j++)
			cin>>n[j];
         sort(n,N);
		 p=new t;
		 /*if(!p)
		 {
			 cout<<"\nApplition Memory falied\n";
			 exit(-1);
		 }*/
		 for(int s=0;s<N;s++)
		 { 
			 p->data=n[s];
			 if(!head)
				 head=p;
			 else 
				 q->next=p;
			 q=p;
			 p=new t;
		 }
	}
		 q->next=NULL;
		 t *m=head;
	     while(m!=NULL)
		 {
			 cout<<m->data<<endl;
			 m=m->next;
		 }
		 
		 return 0;
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -