473,320 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Quick sort

I have a quick sort that reads in data from a file. I know there is something wrong with the partition part of my quick sort and i know exactly what line of code it is. I keep getting the Error C2664: Cannot Convert Parameter 1 from 'x' to 'y'. now thats not exactly what is says but I will show the line of code that it occurs on.
Expand|Select|Wrap|Line Numbers
  1. swap(low,(low + high)/2);
  2.  
it tells me that it cannot convert pararmeter 2 from 'int' to 'int &'
Any help would be greatly appreciated, if you need more info just let me know
Dec 18 '07 #1
2 1670
scruggsy
147 100+
I have a quick sort that reads in data from a file. I know there is something wrong with the partition part of my quick sort and i know exactly what line of code it is. I keep getting the Error C2664: Cannot Convert Parameter 1 from 'x' to 'y'. now thats not exactly what is says but I will show the line of code that it occurs on.
Expand|Select|Wrap|Line Numbers
  1. swap(low,(low + high)/2);
  2.  
it tells me that it cannot convert pararmeter 2 from 'int' to 'int &'
Any help would be greatly appreciated, if you need more info just let me know
Your function expects a second parameter of type int&
By calculating the result of a division, you're trying to pass a value - of type int - not a reference of type int&, hence the error.
If you were to do:
Expand|Select|Wrap|Line Numbers
  1. int param2 = (low+high) / 2;
  2. swa0(low, param2);
....this would solve the problem. So would changing the function header to take a value instead of a reference.
Dec 18 '07 #2
weaknessforcats
9,208 Expert Mod 8TB
swap(low,(low + high)/2);
Fifty dollars says you are using namespace std.

That means you are tripping over std::swap.

Put your swap in tyour own namespace and call it with your namespace name.

(and stop using namespace std. Only teachers do that becuse they never get bit).
Dec 18 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Eva | last post by:
Hi, I try to implement quick sort. I sort vectors by their first value. 10 2 3 4 9 3 5 6 10 4 5 6 must be 9 3 5 6 10 2 3 4 10 4 5 6 The prog works great on maybe 500 vectors, but I have an...
0
by: Frank King | last post by:
Hi, I am using CArray and quick sort funciton to sort an array of double type of data points. I found an article in MSDN HOWTO: Quick Sorting Using MFC CArray-Derived Classes ID: Q216858 ...
5
by: Am | last post by:
hi i came to know that microsoft improved the efficiency of quick sort by using a cutoff of 8 elements and continuing with insertion sort then, do anybody have the details about it please...
11
by: Am | last post by:
hi i came to know that microsoft improved the efficiency of quick sort by using a cutoff of 8 elements and continuing with insertion sort then, do anybody have the details about it please...
1
by: AngelLopez1989 | last post by:
I need the complete C++ program/ algorithm of Quick Sort. Can you please help me out? No pseudocode please. Can you please also explain how to do the quick sort? Thank you!
5
by: neehakale | last post by:
I know that heap sort,quick sort and merg sort are the faster sorting algoritms than the bubble sort,selection sort,shell sort and selection sort. I got an idea,in which situation we can use...
10
by: sophia.agnes | last post by:
Dear all, The following is the quick sort function which i have seen in my note book how good is this function ? void sort(int a, int begin, int end) { int pivot,l,r;
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.