| | |
Sorting
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2004
Posts: 43
Reputation:
Solved Threads: 0
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
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <iomanip> using namespace std; void sort(); const int LIMIT = 50; int MYARRAY[LIMIT]; int value,i; int x = 0; int print = 0; int j,temp,min,minx; int main() { bool exit = false; while(!exit && x < LIMIT) { cout<<"Enter a number or 999 to quit "; cin>>value; if(value != 999) { MYARRAY[x] = value; x++; } else { exit = true;//if value equals 999 exit the loop } while(print < x) { cout<<MYARRAY[print]<<endl;//print out the number as long as it is less than i print++; } } sort(); return 0; } void sort() { min=MYARRAY[x]; minx=i; for(j=i+1;j<x;j++) if(MYARRAY[j]<min) { min=MYARRAY[j]; minx=j; } if(min<MYARRAY[x]) { MYARRAY[x]=min; MYARRAY[minx]=temp; } for(int a=0;a<x;a++) cout <<setw(4) << MYARRAY[x]<< endl; }
![]() |
Similar Threads
- Need Help for identify the Sorting Action (VB.NET)
- sorting stl::map (C++)
- counting comparisons when sorting (C++)
- sorting an array of string (C)
- help by sorting a simply linked list (C)
- sorting file (C)
- sorting 2d arrays (C)
- re: Sorting Algorithms (C++)
Other Threads in the C++ Forum
- Previous Thread: Passing Arrays to function in Visual C++
- Next Thread: nid help in using dialog box
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelp homeworkhelper iamthwee ifstream input int java lib list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





