| | |
bubble sort
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Sep 2008
Posts: 3
Reputation:
Solved Threads: 0
I have the code below and I keep getting an error saying that swap isnt a function. Just wondering if anyone had any idea why. Thanks
[code]
void swap(double *x, double *y ){
double temp;
temp = *x;
*x = *y;
*y = temp;
void sort(double h[], int size){
int i, j;
for (i=(size-1); i>=0; i--){
for(j=1; j<=i; j++){
if (h[j-1] > h[j]){
swap(*(h+(j-1)),*(h+j);
}
}
}
}
[code=C]
[code]
void swap(double *x, double *y ){
double temp;
temp = *x;
*x = *y;
*y = temp;
void sort(double h[], int size){
int i, j;
for (i=(size-1); i>=0; i--){
for(j=1; j<=i; j++){
if (h[j-1] > h[j]){
swap(*(h+(j-1)),*(h+j);
}
}
}
}
[code=C]
1. Where is the closed brace terminated swap function body?
2. Use code tag properly:
[code=c]
... snippet ...
[/code]
3. Keep it simpler (avoid index minus offset where possible):
4. Think about swap call arguments: pass pointers, not values...
2. Use code tag properly:
[code=c]
... snippet ...
[/code]
3. Keep it simpler (avoid index minus offset where possible):
c Syntax (Toggle Plain Text)
for (j=0; j<i; j++) { if (h[j] > h[j+1]) {
![]() |
Similar Threads
- bubble sort function w/ array (C++)
- How do i change this JAVA Insertion sort object to Bubble Sort object (Java)
- Bubble Sort of a file of records in Pascal pls (Pascal and Delphi)
- simplified bubble sort c++ (C++)
- Bubble sort & File output jibrish errors??? (C)
Other Threads in the C Forum
- Previous Thread: o s development in c. how?
- Next Thread: Cache mapping
| Thread Tools | Search this Thread |
adobe ansi api array arrays bash binarysearch centimeter char convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic feet fflush file floatingpointvalidation fork frequency getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling hardware highest homework i/o ide inches infiniteloop initialization interest kilometer km linked linkedlist linux linuxsegmentationfault list locate logical_drives match matrix meter microsoft motherboard multi mysql odf open opendocumentformat opensource openwebfoundation owf pattern pdf performance pointer pointers posix power probleminc program programming pyramidusingturboccodes read recursion recv repetition scanf scheduling segmentationfault send shape single socketprograming socketprogramming stack standard strchr string strings suggestions systemcall test testautomation unix urboc user voidmain() wab win32api windows.h






