Sorting

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

Join Date: Oct 2004
Posts: 43
Reputation: hopeolicious is an unknown quantity at this point 
Solved Threads: 0
hopeolicious hopeolicious is offline Offline
Light Poster

Sorting

 
0
  #1
Mar 15th, 2005
can someone help me to get my program to sort i have the logic but this is my first time doing a sort program and i cant get it to work can some tell me what i'm doing wrong


  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. void sort();
  6.  
  7. const int LIMIT = 50;
  8. int MYARRAY[LIMIT];
  9. int value,i;
  10. int x = 0;
  11. int print = 0;
  12. int j,temp,min,minx;
  13.  
  14. int main()
  15. {
  16.  
  17. bool exit = false;
  18.  
  19.  
  20. while(!exit && x < LIMIT)
  21. {
  22. cout<<"Enter a number or 999 to quit ";
  23. cin>>value;
  24.  
  25. if(value != 999)
  26. {
  27. MYARRAY[x] = value;
  28. x++;
  29. }
  30. else
  31. {
  32. exit = true;//if value equals 999 exit the loop
  33. }
  34. while(print < x)
  35. {
  36. cout<<MYARRAY[print]<<endl;//print out the number as long as it is less than i
  37. print++;
  38. }
  39. }
  40. sort();
  41. return 0;
  42. }
  43.  
  44. void sort()
  45. {
  46.  
  47. min=MYARRAY[x];
  48. minx=i;
  49. for(j=i+1;j<x;j++)
  50. if(MYARRAY[j]<min)
  51. {
  52. min=MYARRAY[j];
  53. minx=j;
  54. }
  55. if(min<MYARRAY[x])
  56. {
  57. MYARRAY[x]=min;
  58. MYARRAY[minx]=temp;
  59. }
  60. for(int a=0;a<x;a++)
  61. cout <<setw(4) << MYARRAY[x]<< endl;
  62.  
  63. }
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 27
Reputation: Gnome_101 is an unknown quantity at this point 
Solved Threads: 0
Gnome_101 Gnome_101 is offline Offline
Light Poster

Re: Sorting

 
0
  #2
Mar 15th, 2005
What is the inital value of i?

If you have it set to nothing, try setting it to a value mabye 0(I think that'll work), then try it.
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC