Need a little help on this.

The error keep giving me initial value of reference to non-const must be an lvalue.The error comes when i am trying to pass a function into the parameter. Any help will be wonderful


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
int ChoosingPivot(vector<int> &tempList){
	int pivotPoint = 0;

	pivotPoint = rand()%tempList.size();

	return pivotPoint;
}

void Partitioning(vector<int> &tempList, int &pivot, int sizeOfList){
	vector<int> lessNumberList;
	vector<int> moreNumberList;

	if(ListSize(tempList) <= 1){
		return;
	}

	for(int i = 0; i < tempList.size(); i++){
		if(tempList[i] < tempList[pivot]){
			lessNumberList.push_back(tempList[i]);
		}

		else if(tempList[i] > tempList[pivot]){
			moreNumberList.push_back(tempList[i]);
		}
	}
	
	cout<<endl<<endl<<" LESS : ";
	DisplayNumbers(lessNumberList);

	cout<<endl<<endl<<" MORE : ";
	DisplayNumbers(moreNumberList);

	Partitioning(lessNumberList, ChoosingPivot(tempList), ListSize(lessNumberList));
	Partitioning(moreNumberList, ChoosingPivot(tempList), ListSize(moreNumberList));

}
Last edited on
one possible error that i can see is that your ChoosingPivot function returns an int by value. However, you are providing that as an input to your Partitioning function that expects a reference.
is there anyway to fix this?
well first you will have to check whether this IS the problem.

remove all references (&s) from the function paramters and check whether your program compiles.

Then you can think of which parameter you want to input as reference and why. is it the speed issue or is it that you want to keep only one copy during recursion or what?
Topic archived. No new replies allowed.