69,382
社区成员
发帖
与我相关
我的任务
分享
/*
,%%%%%%%%,
,%%/\%%%%/\%%
,%%%\c "" J/%%%
%. %%%%/ o o \%%%
`%%. %%%% _ |%%%
`%% `%%%%(__Y__)%%'
// ;%%%%`\-/%%%'
(( / `%%%%%%%'
\\ .' |
\\ / \ | |
\\/ ) | |
\ /_ | |__
(___________)))))))
*/
#include<stdio.h>
#include<stdlib.h>
int SortStr(unsigned long int* str,unsigned long int n)
{
int i,j,temp = 0;
for(i =0;i<n;i++)
for(j = i+1;j<n;j++)
if(str[j] <str[i] )
{
temp = str[j];
str[j] = str[i];
str[i] = temp;
}
for(i = 0;i<n;i++)
{
printf("%d ",str[i]);
}
return 0;
}
int main()
{
unsigned long int i,n,*str;
scanf("%d",&n);
str = (unsigned long int*)malloc(sizeof(unsigned long int)*n);
for(i = 0;i<n;i++)
scanf("%d",&str[i]);
SortStr(str,n);
return 0;
}
/*
,%%%%%%%%,
,%%/\%%%%/\%%
,%%%\c "" J/%%%
%. %%%%/ o o \%%%
`%%. %%%% _ |%%%
`%% `%%%%(__Y__)%%'
// ;%%%%`\-/%%%'
(( / `%%%%%%%'
\\ .' |
\\ / \ | |
\\/ ) | |
\ /_ | |__
(___________)))))))
*/
#include<stdio.h>
#include<stdlib.h>
void quiksort(unsigned long int a[],int low,int high)
{
int i = low;
int j = high;
unsigned long int temp = a[i];
if( low < high)
{
while(i < j)
{
while((a[j] >= temp) && (i < j))
{
j--;
}
a[i] = a[j];
while((a[i] <= temp) && (i < j))
{
i++;
}
a[j]= a[i];
}
a[i] = temp;
quiksort(a,low,i-1);
quiksort(a,j+1,high);
}
else
{
return;
}
}
int main()
{
unsigned long int i,n,*str;
scanf("%d",&n);
str = (unsigned long int*)malloc(sizeof(unsigned long int)*n);
for(i = 0;i<n;i++)
scanf("%d",&str[i]);
quiksort(str,0,n-1);
for( i = 0;i<n;i++)
printf("%d ",str[i]);
return 0;
}
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int num;
cin >> num;
vector<int> ivec;
ivec.reserve(num);
int temp;
for (int i = 0; i != num; ++i)
{
cin >> temp;
ivec.push_back(temp);
}
sort(ivec.begin(), ivec.end());
for (auto &i : ivec)
{
cout << i << " ";
}
cout << endl;
}