Please can anybody give me an example

Reply

Join Date: Apr 2005
Posts: 15
Reputation: nizar4445 is an unknown quantity at this point 
Solved Threads: 0
nizar4445 nizar4445 is offline Offline
Newbie Poster

Please can anybody give me an example

 
0
  #1
Apr 4th, 2005
Please could you give me an example of sorting an array and how to call the function at the main

thanks a lot :o :rolleyes: :rolleyes:
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

Re: Please can anybody give me an example

 
0
  #2
Apr 4th, 2005
how do you wish to sort it?
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,625
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 717
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Please can anybody give me an example

 
0
  #3
Apr 4th, 2005
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <iterator>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. int a[] = {5,7,4,6,3,8,0,1,9,2};
  10.  
  11. sort ( a, a + 10 );
  12. copy ( a, a + 10, ostream_iterator<int> ( cout, " " ) );
  13. }
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 15
Reputation: nizar4445 is an unknown quantity at this point 
Solved Threads: 0
nizar4445 nizar4445 is offline Offline
Newbie Poster

Re: Please can anybody give me an example

 
0
  #4
Apr 4th, 2005
thanks alot for helping me but could you please give me an easier example (a more basic one) im new to programming

thank you :lol: :lol: :cry: :cry: :cry:
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,625
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 717
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Please can anybody give me an example

 
0
  #5
Apr 4th, 2005
>please give me an easier example
That's as easy as it gets. If you want something more basic then you're looking at writing a sort function manually, and that's decidedly not basic compared to just calling std::sort.

Is this a homework assignment?
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

Re: Please can anybody give me an example

 
0
  #6
Apr 4th, 2005
you didnt tell us how you want the array sorting! Perhaps highest value to lowest if its int?
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 15
Reputation: nizar4445 is an unknown quantity at this point 
Solved Threads: 0
nizar4445 nizar4445 is offline Offline
Newbie Poster

Re: Please can anybody give me an example

 
0
  #7
Apr 5th, 2005
thanks all for helping me

i want to sort the array from the lowest to the highest

its a part of my assignment

i've had a look in some books and i found a sorting function, the problem is that i don't know how to call it at the void main(). I think i need somehow to call the sorted array, any body can help pleazzzzzz!!

thanks again :cry: :cry: :cry:
Reply With Quote Quick reply to this message  
Join Date: Dec 2003
Posts: 2,414
Reputation: alc6379 has a spectacular aura about alc6379 has a spectacular aura about alc6379 has a spectacular aura about 
Solved Threads: 123
Team Colleague
alc6379's Avatar
alc6379 alc6379 is offline Offline
Cookie... That's it

Re: Please can anybody give me an example

 
0
  #8
Apr 6th, 2005
Wouldn't you just define the function and then call it from within main()? I think you might want to review your textbook some more on functions. I'm not worth my salt as a programmer, and I could tell you this much.

Also, I'm sure Narue might mention this, but I know you're not supposed to use void main(). I'm not entirely sure why, and I don't want to guess, but I have an idea why. Care to elaborate further on this, Narue?
Alex Cavnar, aka alc6379
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,358
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Please can anybody give me an example

 
0
  #9
Apr 6th, 2005
Originally Posted by alc6379
Also, I'm sure Narue might mention this, but I know you're not supposed to use void main(). I'm not entirely sure why, and I don't want to guess, but I have an idea why. Care to elaborate further on this, Narue?
I'm not Narue, but I try to be that good. I merely have this to offer.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,009
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 929
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Please can anybody give me an example

 
0
  #10
Apr 6th, 2005
An example in C, sorry but venerable old C was all I could find in a hurry!
[PHP]// sort of an array of random integers using shell-sort
// an optimized insertion sort developed by Donald Shell
// Pelles C

#include <stdio.h>
#include <stdlib.h> // rand()

#define NUM_ITEMS 100

void shellSort(int numbers[], int array_size);

int numbers[NUM_ITEMS];

int main()
{
int k;

//fill array with random integers
for (k = 0; k < NUM_ITEMS; k++)
numbers[k] = rand() % NUM_ITEMS;

//perform shell sort on array
shellSort(numbers, NUM_ITEMS);

// show the sorted numbers
for (k = 0; k < NUM_ITEMS; k++)
printf("%8d ", numbers[k]);
getchar();
return 0;
}

// shell sort routine of n items in array[n]
void shellSort(int numbers[], int array_size)
{
int i, j, increment, temp;

increment = 3;
while (increment > 0)
{
for (i = 0; i < array_size; i++)
{
j = i;
temp = numbers[i];
while ((j >= increment) && (numbers[j-increment] > temp))
{
numbers[j] = numbers[j - increment];
j = j - increment;
}
numbers[j] = temp;
}
if (increment/2 != 0)
increment = increment/2;
else if (increment == 1)
increment = 0;
else
increment = 1;
}
}
[/PHP]
May 'the Google' be with you!
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