help

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2007
Posts: 15
Reputation: Nidaa87 is an unknown quantity at this point 
Solved Threads: 0
Nidaa87 Nidaa87 is offline Offline
Newbie Poster

help

 
0
  #1
Dec 11th, 2007
radix sort:
an example :

Original, unsorted list:
170, 45, 75, 90, 2, 24, 802, 66

Sorting by least significant digit (1s place) gives:
170, 90, 2, 802, 24, 45, 75, 66

Notice that we keep 2 before 802, because 2 occurred before 802 in the original list, and similarly for 170 and 90.

Sorting by next digit (10s place) gives:
2, 802, 24, 45, 66, 170, 75, 90

Sorting by most significant digit (100s place) gives:
2, 24, 45, 66, 75, 90, 170, 802

your program should do the following:
1.write a function which implements the LCD radix sort
2.generate 1000 random numbers and store it in a arry, the numbers should be consist from 4 digits at least
3.choose any other sorting algorithm and implement it
4.compute the number of swapping which made by radix sort and compute the number of swapping made by the selected algorithm
5.compute the time of radix sort and compare it with the time of the selected algorithm
6.the two algorithms should be applied on the same data which mean that the original array cannot be changed
7.your program must have a menu
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,365
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1464
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: help

 
0
  #2
Dec 11th, 2007
Which part of that assignment do you need help on? What don't you understand ? Have you even tried yet ?
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 15
Reputation: Nidaa87 is an unknown quantity at this point 
Solved Threads: 0
Nidaa87 Nidaa87 is offline Offline
Newbie Poster

Re: help

 
0
  #3
Dec 11th, 2007
I wrote this code and there is not a mistake, I want code calculation time radix sort, compare with the time of the selection algorithm
  1. #define NUMELTS 100
  2. # include<stdio.h>
  3. #include<iostream>
  4. #include<conio.h>
  5. #include<math.h>
  6. using namespace std;
  7. void radixsort(int a[],int);
  8. void main()
  9. {
  10. int n,a[20],i;
  11. //clrscr();
  12.  
  13. cout<<"enter the number :";
  14. scanf("%d",&n);
  15. cout<<("ENTER THE DATA");
  16. for(i=0;i<n;i++)
  17. {
  18. cout<<("%d. ",i+1);
  19. scanf("%d",&a[i]);
  20. }
  21. radixsort(a,n);
  22. getch();
  23. }
  24. void radixsort(int a[],int n)
  25. {
  26. int rear[10],front[10],first,p,q,exp,k,i,y,j;
  27. struct
  28. {
  29. int info;
  30. int next;
  31. }node[NUMELTS];
  32. for(i=0;i<n-1;i++)
  33. {
  34. node[i].info=a[i];
  35. node[i].next=i+1;
  36. }
  37. node[n-1].info=a[n-1];
  38. node[n-1].next=-1;
  39. first=0;
  40.  
  41. for(k=1;k<=2;k++) //consider only 2 digit number
  42. {
  43. for(i=0;i<10;i++)
  44. {
  45. front[i]=-1;
  46. rear[i]=-1;
  47. }
  48.  
  49. while(first!=-1)
  50. {
  51. p=first;
  52. first=node[first].next;
  53. y=node[p].info;
  54. exp=pow(10,k-1);
  55. j=(y/exp)%10;
  56. q=rear[j];
  57. if(q==-1)
  58. front[j]=p;
  59. else
  60. node[q].next=p;
  61. rear[j]=p;
  62. }
  63. for(j=0;j<10&&front[j]==-1;j++)
  64. ;
  65. first=front[j];
  66. while(j<=9)
  67. {
  68. for(i=j+1;i<10&&front[i]==-1;i++)
  69. ;
  70. if(i<=9)
  71. {
  72. p=i;
  73. node[rear[j]].next=front[i];
  74. }
  75. j=i;
  76. }
  77. node[rear[p]].next=-1;
  78. }
  79. //copy into original array
  80. for(i=0;i<n;i++)
  81. {
  82. a[i]=node[first].info;
  83. first=node[first].next;
  84.  
  85. }
  86. //clrscr();
  87. //textcolor(YELLOW);
  88. cout<<"\nDATA AFTER SORTING:\n";
  89. for(i=0;i<n;i++)
  90. cout<<i+1<<"\t\t\t"<<a[i]<<"\n";
  91. }
Last edited by cscgal; Dec 11th, 2007 at 4:12 pm. Reason: Added code tags
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 15
Reputation: Nidaa87 is an unknown quantity at this point 
Solved Threads: 0
Nidaa87 Nidaa87 is offline Offline
Newbie Poster

Re: help

 
0
  #4
Dec 11th, 2007
I would be grateful to you in your assistance in resolving this program
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1,675
Reputation: vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold 
Solved Threads: 193
vmanes's Avatar
vmanes vmanes is offline Offline
Posting Virtuoso

Re: help

 
0
  #5
Dec 11th, 2007
to do any realistic comparisons of sorts functions, you'll need to use a larger data array. Even then, on a modern PC, the time to sort will be so quick, you may have to run the sorts many times in succession to see a difference.

Access the system time before starting a run of one sort, run it, then get system time again. Subtract. Note that C++ does not natively give you any resolution better than 1 second increments.

Also be sure to account for the overhead time of just calling the functions repeatedly, and of resetting your array back to its initial state.
"We Americans got so tired of being thought of as dumb by the rest of the world that we went to the polls last November and removed all doubt."
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 15
Reputation: Nidaa87 is an unknown quantity at this point 
Solved Threads: 0
Nidaa87 Nidaa87 is offline Offline
Newbie Poster

Re: help

 
0
  #6
Dec 12th, 2007
Dr. demanded resolution of this question to the data structure
Please clarify what
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,826
Reputation: ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all 
Solved Threads: 117
ithelp's Avatar
ithelp ithelp is offline Offline
Posting Virtuoso

Re: help

 
0
  #7
Dec 12th, 2007
Use time to measure number of miliseconds passed in radixsort for huge arrays.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 15
Reputation: Nidaa87 is an unknown quantity at this point 
Solved Threads: 0
Nidaa87 Nidaa87 is offline Offline
Newbie Poster

Re: help

 
0
  #8
Dec 12th, 2007
The expense and time radixsort comparable another type of the sort
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC