Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 27th, 2004, 10:48 PM   #1
inko9nito
Newbie
 
Join Date: Oct 2004
Location: Wylie, TX
Posts: 11
Rep Power: 0 inko9nito is on a distinguished road
Send a message via AIM to inko9nito
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.
__________________
Страшнее человека-паука только человек-тапок.
inko9nito is offline   Reply With Quote
Old Oct 27th, 2004, 10:55 PM   #2
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
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
Mjordan2nd is offline   Reply With Quote
Old Oct 27th, 2004, 11:42 PM   #3
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 6 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
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;
      }
}
__________________

tempest is offline   Reply With Quote
Old Oct 27th, 2004, 11:48 PM   #4
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 6 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
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.
__________________

tempest is offline   Reply With Quote
Old Oct 28th, 2004, 12:07 AM   #5
inko9nito
Newbie
 
Join Date: Oct 2004
Location: Wylie, TX
Posts: 11
Rep Power: 0 inko9nito is on a distinguished road
Send a message via AIM to inko9nito
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
__________________
Страшнее человека-паука только человек-тапок.
inko9nito is offline   Reply With Quote
Old Oct 28th, 2004, 12:13 AM   #6
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 6 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
Pssh.. my way was easier...
__________________

tempest is offline   Reply With Quote
Old Oct 28th, 2004, 12:17 AM   #7
inko9nito
Newbie
 
Join Date: Oct 2004
Location: Wylie, TX
Posts: 11
Rep Power: 0 inko9nito is on a distinguished road
Send a message via AIM to inko9nito
Quote:
Originally posted by tempest@Oct 28 2004, 04:13 AM
Pssh.. my way was easier...
I know, but that's not what they're asking for, unfortunately The TAs are very picky about those things and I don't wanna get anything lower than an A+ in that class
__________________
Страшнее человека-паука только человек-тапок.
inko9nito is offline   Reply With Quote
Old Oct 28th, 2004, 1:14 AM   #8
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 6 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
Show some programming enthusiasm and put in concepts that havent been taught yet :-P

My high school programming teacher hates me for that.
__________________

tempest is offline   Reply With Quote
Old Oct 28th, 2004, 6:03 AM   #9
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Really? My teacher loves it... but then, he's a computer nut. And I mean NUT.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Oct 28th, 2004, 10:37 AM   #10
inko9nito
Newbie
 
Join Date: Oct 2004
Location: Wylie, TX
Posts: 11
Rep Power: 0 inko9nito is on a distinguished road
Send a message via AIM to inko9nito
Quote:
Originally posted by tempest@Oct 28 2004, 12:14 AM
Show some programming enthusiasm and put in concepts that havent been taught yet :-P

My high school programming teacher hates me for that.
Well, it's been taught but that's not the assignment. The next lab, right after it, asks us to sort and stuff. And I already did the sorting and came back to this one cause I didn't know what it meant.
__________________
Страшнее человека-паука только человек-тапок.
inko9nito is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:58 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC