![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
|
Ok, we just started learning seraches and sorts and I already finished the lesson set (collection of labs we have to do after each chapter) but I'm stuck on this one problem at the beginning of the lesson set. It says:
"Modify the program to search an array that is in ascending order. Make sure to alter the array initialization." This is how the array is initialized, originally, in descending order. int array[] = {34, 19, 17, 12};So are they asking us to sort the array in ascending order, for which you won't need to change the array initialization like they're asking us to; or just put the array elements in different order manually e.g. int array[] = {12, 17, 19, 34};The problem is in this lab they're only testing us on the searches, the NEXT lab is on sorting. So this really frustrates me. This lab book has a lot of typos and stuff but this - I'm just all confused. ![]()
__________________
Страшнее человека-паука только человек-тапок. |
|
|
|
|
|
#2 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
My guess would be to sort the arrays.
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
|
|
#3 |
|
Programming Guru
![]() |
There are many many sort algorithms, the quickest being "quick sort". But the fastest to type being "bubble sort" demonstrated below...
void sort(int nums[]) {
int len = sizeof(nums) / sizeof(nums[0]);
for(int i=0;i<len-1;i++)
for(int j=0;j<len-1-i;j++)
if(nums[j + 1] < nums[j]) {
int temp = nums[j];
nums[j] = nums[j + 1];
nums[j + 1] = temp;
}
}
__________________
|
|
|
|
|
|
#4 |
|
Programming Guru
![]() |
Here is a link to something on the quick sort algorithm if you want to try it. But i cant vouch on its accuracy, i havent read it.
__________________
|
|
|
|
|
|
#5 |
|
Newbie
|
No, the point of my post was - do I use a sorting algorithm or do I just change the numbers in the array manually. The latter is actually what they wanted. I just got an email from my TA (surprisingly!) and she said that's what they want. That book has a lot of problems with confusing wording of their exercise directions. Thank you though! I appreciate your help, guys
![]()
__________________
Страшнее человека-паука только человек-тапок. |
|
|
|
|
|
#6 |
|
Programming Guru
![]() |
Pssh.. my way was easier...
__________________
|
|
|
|
|
|
#7 | |
|
Newbie
|
Quote:
The TAs are very picky about those things and I don't wanna get anything lower than an A+ in that class ![]()
__________________
Страшнее человека-паука только человек-тапок. |
|
|
|
|
|
|
#8 |
|
Programming Guru
![]() |
Show some programming enthusiasm and put in concepts that havent been taught yet :-P
My high school programming teacher hates me for that.
__________________
|
|
|
|
|
|
#9 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Really? My teacher loves it... but then, he's a computer nut. And I mean NUT.
|
|
|
|
|
|
#10 | |
|
Newbie
|
Quote:
__________________
Страшнее человека-паука только человек-тапок. |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|