Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <fstream>
- #include <ctime>
- using namespace std;
- struct ladica{
- unsigned short broj;
- ladica*next;
- };
- int main(){
- srand(time(0));
- unsigned short N;
- cin>>N;
- //N=100;
- ladica *head=NULL;
- ladica *tail=NULL;
- ladica *current=NULL;
- for(int i=0;i<N;i++){
- current=new ladica();
- (*current).broj=rand()%32768;
- if(head==NULL){
- head=current;
- }
- if(tail!=NULL){
- (*tail).next=current;
- }
- tail=current;
- }
- unsigned short foi[N+1];
- current=head;
- int br=0;
- while(current!=NULL){
- foi[br++]=(*current).broj;
- current=(*current).next;
- }
- for(int i=N-1;i>=0;i--){
- unsigned short tmp;
- for(int j=0;j<i;j++){
- if(foi[j]>foi[i]){
- tmp=foi[i];
- foi[i]=foi[j];
- foi[j]=tmp;
- }
- }
- }
- current=head;
- br=0;
- while(current!=NULL){
- (*current).broj=foi[br++];
- cout<<(*current).broj<<"\n";
- current=(*current).next;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement