Welcome! Log In Create A New Profile

Advanced

Assignment 3: Question 7

Posted by rezrovs 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Assignment 3: Question 7
June 14, 2009 01:26PM
I am quite stumped by this question.

I tried to code it up so that I could see what it was doing, but I get an error

swap(first+2, last); //this is the first swap line in the partition function in the tut letter.
main.cpp(9) : error C2440: 'initializing' : cannot convert from 'int' to 'int &'

So because I have no idea how to make this int a reference I decided to go through the code logically.

I started with looking at the quickSort method in the tut letter and I'm confused.
If I take the example array of {5,8,0,2,5,3,7,2,6} and start applying the algorithm, after the sortFirstThree, the array looks like {0,5,8,2,5,3,7,2,6}. But then, first+2 (which is 8 if I'm not mistaken) is not less than last (which is 6). Then the code inside the if statement will not execute and the list will not be sorted.

Can anyone tell me what I'm missing here?


****** NOTE
I'm sorry - it seems I have the dumb today. I see now that first+2 is the INDEX and not the VALUE of the array at first+2. I knew I'd get it once I asked. Why can't we delete posts here anymore?
Sorry, only registered users may post in this forum.

Click here to login