Advertisement
Guest User

Sri

a guest
Jun 19th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <fstream>
  4. #include <ctime>
  5. using namespace std;
  6. struct ladica{
  7. unsigned short broj;
  8. ladica*next;
  9. };
  10. int main(){
  11. srand(time(0));
  12. unsigned short N;
  13. cin>>N;
  14. //N=100;
  15.  
  16. ladica *head=NULL;
  17. ladica *tail=NULL;
  18. ladica *current=NULL;
  19. for(int i=0;i<N;i++){
  20. current=new ladica();
  21. (*current).broj=rand()%32768;
  22. if(head==NULL){
  23. head=current;
  24. }
  25. if(tail!=NULL){
  26. (*tail).next=current;
  27. }
  28. tail=current;
  29. }
  30. unsigned short foi[N+1];
  31. current=head;
  32. int br=0;
  33. while(current!=NULL){
  34. foi[br++]=(*current).broj;
  35. current=(*current).next;
  36. }
  37. for(int i=N-1;i>=0;i--){
  38. unsigned short tmp;
  39. for(int j=0;j<i;j++){
  40. if(foi[j]>foi[i]){
  41. tmp=foi[i];
  42. foi[i]=foi[j];
  43. foi[j]=tmp;
  44. }
  45. }
  46. }
  47. current=head;
  48. br=0;
  49. while(current!=NULL){
  50. (*current).broj=foi[br++];
  51. cout<<(*current).broj<<"\n";
  52. current=(*current).next;
  53. }
  54.  
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement