| | |
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, " " ) ); }
In case you were wondering, yes, I do hate you.
•
•
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
- Tic-Tac-Toe (C++)
- We only give homework help to those who show effort (Computer Science)
- YAHOO DSL w/NETGEAR router wont give me connection (Networking Hardware Configuration)
- 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...
Views: 2946 | Replies: 14
| Thread Tools | Search this Thread |
Tag cloud for C
api array arrays bash behaviour binary binarysearch c++ calculator char code coke command conversion convert copyanyfile copypdffile createprocess() database decimal directory dude dynamic error exec fflush(stdout) fgets file files fork function functions getlogicaldrivestrin givemetehcodez grade graphics homework i/o ide input int integer interest kilometer lazy library line linked linkedlist linux list locate loop malloc matrix memory meter mysql no-code no-effort operator output path pause pointer pointers problem process program programming read recursion recursive recv refresh reverse roman scanf segmentationfault sms_speak socketprograming socketprogramming spoonfeeding strchr string strings strtok structures student suggestions syntax system test turbo-c turboc unix user variable win32api windows






