| | |
Please can anybody give me an example
![]() |
C Syntax (Toggle Plain Text)
#include <algorithm> #include <iostream> #include <iterator> using namespace std; int main() { int a[] = {5,7,4,6,3,8,0,1,9,2}; sort ( a, a + 10 ); copy ( a, a + 10, ostream_iterator<int> ( cout, " " ) ); }
I'm here to prove you wrong.
•
•
Join Date: Apr 2005
Posts: 15
Reputation:
Solved Threads: 0
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:
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:
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?
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
•
•
•
•
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?
"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
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]
[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!
![]() |
Similar Threads
- We only give homework help to those who show effort (Computer Science)
- YAHOO DSL w/NETGEAR router wont give me connection (Networking Hardware Configuration)
- Tic-Tac-Toe (C++)
- Can anybody give answers for these 2 queries ??!!?? (Visual Basic 4 / 5 / 6)
- YAHOO DSL w/NETGEAR router wont give me connection (Networking Hardware Configuration)
- Please give me reviews of my site (Website Reviews)
- I GIVE UP, how do I modify this code to call from one form to the other and back (C++)
Other Threads in the C Forum
- Previous Thread: File Processing 2
- Next Thread: Using sprites...
| Thread Tools | Search this Thread |
#include adobe ansi api array asterisks binarysearch changingto char character cm copyimagefile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax database directory dynamic execv feet fgets file fork forloop frequency function getlasterror givemetehcodez global grade graphics gtkgcurlcompiling hacking hardware highest histogram i/o include incrementoperators infiniteloop input interest kernel keyboard kilometer license linked linkedlist linux linuxsegmentationfault list locate logical_drives looping loopinsideloop. lowest match matrix meter microsoft motherboard mqqueue mysql number odf opensource owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv repetition research reversing scanf segmentationfault sequential shape socket socketprograming standard string systemcall threads turboc unix user voidmain() wab windows.h windowsapi






