Help with vector search


I do not know what to do from here i keep getting errors in visual studio
Also i am ignoring the multiplicities part at the moment

Write a predicate function
bool same_set(vector<int> a, vector<int> b)
that checks whether two vectors have the same elements in some order, ignoring
multiplicities. For example, the two vectors

1 4 9 16 9 7 4 9 11
11 11 7 9 16 4 1

would be considered identical. You will probably need one or more helper
functions.


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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <string>
#include <vector>
using namespace std;

vector<int> same_set(vector<int> , vector<int> );
int values(vector<int>, vector<int>, int&,  bool);




int main()
{
	vector<int>a{ 1,2,4 };
	vector <int>b{1,5,6,4 };
	
	vector<int> c;
	c = same_set(a, b);

	cout << c[0];
	cout << c[1];
	
	
	
	return 0;
}

vector<int> same_set(vector<int> a, vector<int> b)
{
	vector<int> c(1);

	int startpoint = 0;
	bool isNum = false;
	int counter = 0;

do{
    
	if (isNum)
	{
		c[counter] = values(a, b, startpoint, isNum);
        counter++;
        isNum =false;
        c.push_back(1);
        }
}while (counter < a.size());

		return c;
}

int values(vector<int> a, vector<int> b, int& startpoint,  bool& isNum)
{
	vector<int> c;
	int answer;
	for (int i = 0; i < b.size(); i++)
	{

		if (a[startpoint] == b[i])
		{
			c[startpoint] = b[i];
			answer = c[startpoint];
			isNum = true;
	    	startpoint++;
	    	break;
		}	
	}
	return answer;
}
Last edited on
closed account (48bpfSEw)
isNum is always "false" -> your code is entrappt in an eternal loop!

one of the simplest debugging techniques is to log information!

cout << _FUNC_ << " " << _LINE_ << " : " << "counter: " << counter << endl;

The lack of information is the problem which makes one unable to solve it.

Last edited on
Topic archived. No new replies allowed.