How do I decrease time, especially in sorting?
Given a list of numbers, you are to sort them in non-decreasing order.
Input
t
– the number of numbers in list, then t lines follow [\$t \le 10^6\$].Each line contains one integer: N [\$0 \le N \le 10^6\$]
Output
Given numbers in non-decreasing order.
Example
Input:
5 5 3 6 7 1
Output:
1 3 5 6 7
struct sort_list{
int num;
struct sort_list *next;
};
typedef struct sort_list node;
void enter();
void sort();
void print();
int main()
{
node *head;
int tot_num;
scanf("%d",&tot_num); //asking for entering total numbers
head=(node*)malloc(sizeof(node));
enter(head,tot_num);
sort(head,tot_num);
print(head);
return 0;
}
void enter(node *list,int tot_num)
{
int i=0;
while(i!=tot_num)
{
scanf("%d",&list->num);
if(i==tot_num-1)
{
list->next=0;
//break;
}
else
{
list->next=(node*)malloc(sizeof(node));
list=list->next;
}
i++;
}
}
void print(node *list)
{
int i=0;
while(list->next!=0)
{
printf("%d\n",list->num);
list=list->next;
i++;
}
if(list->next==0)
{
printf("%d\n",list->num);
}
}
void sort(node *list,int tot_num)
{
node *new=list;
int i,j,t;
for(i=0;i<tot_num;i++)
{
for(j=i+1;j<tot_num;j++)
{
if(list->num > list->next->num)
{
t=list->num;
list->num=list->next->num;
list->next->num=t;
}
list=list->next;
}
list=new;
}
}