Thursday, July 9, 2009

C++ Array HELP!?

Here's what I'm trying to do...


I have an array with 50 lines and I want to grab every ten lines and throw them into a few functions.


Here are my prototypes


void BubbleSort(int [],int);


void ShowArray(int [],int);





my array:


int Unsorted[50];


int A[10];





Here's my for loop


inFile.open("input.txt");


if (inFile.fail())


cout %26lt;%26lt; "Unable to read from file...";


else


{





//ShowArray(Unsorted,AllData);


//input data from array...all of it...


for (int count = 0; count %26lt; 50; count++)


{


inFile %26gt;%26gt; Unsorted[count];





cout %26lt;%26lt; Unsorted[count] %26lt;%26lt; endl;


}


}


}


How can I create a for loop that will capture ten lines of numbers from the [50], pass them into a function that will sort them and then toss them into another function that will print out the sorted list, and then repeat the process another four times? A[10] will hold the ten lines.


Any ideas...please help


thanks...

C++ Array HELP!?
for(int i = 0; i %26lt; 5; i++)


{


int arraytemp[10];


for(int j = 0; j %26lt; 10; j++)


{


//move values into a new array


arraytemp[j] = Unsorted[i*10+j];


}


//sort the array


sort(arraytemp);


//print the array


print(arraytemp);


}





below is links to how to bubble sort (with code, c++)
Reply:use a nested for loop.








for(int i = 0; i %26lt; 4; i++)


{


for(int j = 0 + 10*i; j %26lt; 10*i + 10; j++)


//add Array[j] to A[j - 10*i]





//now sort and output the current A[].


}
Reply:Just hardcode every multiple of 10 into the for loop, like this.





for(init;test;iter)


{


if(line==10 || line==20...etc)


//add it in here


}


No comments:

Post a Comment