How sort a Dynamic Array?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2007
Posts: 59
Reputation: kako13 is an unknown quantity at this point 
Solved Threads: 1
kako13's Avatar
kako13 kako13 is offline Offline
Junior Poster in Training

How sort a Dynamic Array?

 
0
  #1
Jan 20th, 2008
Hi, I have been searching in google for an algorithm for sort a dynamic array. I must said that the information in the Internet for sort dynamic array is very limited. However, I found bubble sort for dynamic array, but it don't wanna work. It is inside a class definition and I'm calling it from a function inside the same class.

Here is how a'm calling it: arrSort (arrayOfList, listSize);

Declaration in Public:
void arrSort(int*, int);

  1. void file::arrSort(int* pDonate[], int s)
  2. {
  3. bool swap;
  4. int* temp;
  5. do
  6. {
  7. swap = false;
  8. for (int count = 0; count < (s-1); count++)
  9. {
  10. if ((*pDonate[count]) > (*pDonate[count+1]))
  11. {
  12. temp = pDonate[count];
  13. pDonate[count] = pDonate[count+1];
  14. pDonate[count+1] = temp;
  15. }
  16. swap = true;
  17. }
  18. }
  19. while(swap);
  20. }

Here is the error:
C:\Users\xxx\Desktop\file.h prototype for `void file::arrSort(int**, int)' does not match any in class `file'
C:\Users\xxx\Desktop\file.h void file::arrSort(int*, int)
I'm using Dev C++.

Any suggestion will be appreciate.
Last edited by kako13; Jan 20th, 2008 at 10:06 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,951
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: How sort a Dynamic Array?

 
0
  #2
Jan 20th, 2008
You've got a type problem. Always make sure you are handling the same type of things.

An
int *foo;
is the same as an
int foo[];

But it is very different from an
int *foo[];
(which is the same as an
int **foo;
)

Hope this helps.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 59
Reputation: kako13 is an unknown quantity at this point 
Solved Threads: 1
kako13's Avatar
kako13 kako13 is offline Offline
Junior Poster in Training

Re: How sort a Dynamic Array?

 
0
  #3
Jan 21st, 2008
Hi, if I'm right my array is int* arrayName, while the algorithm is for sort an array of type int* arrayName[]? I'm a little confused with that, then I don't be will be able to sort the dynamic array with that algorithm?

Thanks...


Originally Posted by Duoas View Post
You've got a type problem. Always make sure you are handling the same type of things.

An
int *foo;
is the same as an
int foo[];

But it is very different from an
int *foo[];
(which is the same as an
int **foo;
)

Hope this helps.
Last edited by kako13; Jan 21st, 2008 at 2:14 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 59
Reputation: kako13 is an unknown quantity at this point 
Solved Threads: 1
kako13's Avatar
kako13 kako13 is offline Offline
Junior Poster in Training

Re: How sort a Dynamic Array?

 
0
  #4
Jan 22nd, 2008
Solved! Now I understand an array is an address. For that reason I don't need to have int* x [], because only with int x [] I'm pointing to a direction.

Originally Posted by kako13 View Post
Hi, if I'm right my array is int* arrayName, while the algorithm is for sort an array of type int* arrayName[]? I'm a little confused with that, then I don't be will be able to sort the dynamic array with that algorithm?

Thanks...
Computer Science Student @ www.upra.edu
Camuy, PR USA
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