Implement the following function, without using any data structure or #include /* Given two vectors of chars, check if the two vectors are permutations of each other, i.e., they contains same values, in same or different order. e.g., V1=[‘a’,’b’,’a’] and V2=[‘b’,’a’,’a’] stores same multi-set of data points: i.e., both contains two ‘a’, and one ‘b’. e.g., V3=[‘a’,’c’,’t’,’a’] and V4=[‘a’,’c’,’t’] are not same multi-set. V3 contains two ‘a’s, while V4 has only one ‘a’. Note: when considering multiset, the number of occurrences matters. @param list1, list2: two vectors of chars @pre: list1, list2 have been initialized @post: return true if list1 and list2 stores same values (in same or different order); return false, if not. */ bool SameMultiSet (vector list1, vector list2) THIS IS NOT THE CORRECT SOLUTION / include headers #include // deinfe the namespace using namespace std; // function fo rchecking same bool checkSame(vector arr,vector arr1) { // define a flag variables int flag=0; // loop from 0 to size of arr for(int i=0;i::iterator it; it = arr1.begin()+j; arr1.erase(it); // break and move to next element
Implement the following function, without using any data structure or #include <bits/stdc++.h>
/* Given two
e.g., V1=[‘a’,’b’,’a’] and V2=[‘b’,’a’,’a’] stores same multi-set of data points: i.e., both contains two ‘a’, and one ‘b’.
e.g., V3=[‘a’,’c’,’t’,’a’] and V4=[‘a’,’c’,’t’] are not same multi-set. V3 contains two ‘a’s, while V4 has only one ‘a’.
Note: when considering multiset, the number of occurrences matters. @param list1, list2: two vectors of chars
@pre: list1, list2 have been initialized
@post: return true if list1 and list2 stores same values (in same or different order); return false, if not. */
bool SameMultiSet (vector<char> list1, vector<char> list2)
THIS IS NOT THE CORRECT SOLUTION
/ include headers
#include <bits/stdc++.h>
// deinfe the namespace
using namespace std;
// function fo rchecking same
bool checkSame(vector<int> arr,vector<int> arr1)
{
// define a flag variables
int flag=0;
// loop from 0 to size of arr
for(int i=0;i<arr.size();i++)
{
// initialize flag=0
flag=0;
// loop from 0 to size of arr1
for(int j=0;j<arr1.size();j++)
{
// if arr[i] is equal to arr[j]
if(arr[i]==arr1[j])
{
// make flag as 1
flag=1;
// remove arr1[j] from arr1
vector<int>::iterator it;
it = arr1.begin()+j;
arr1.erase(it);
// break and move to next element
break;
}
}
// if flag is still 0
// return 0
if(flag==0)
{
return 0;
}
}
// return 1 after comparing
return 1;
}
// main function for testing
int main()
{
// call function and print answer accordinly
checkSame({1,2,3,4,5},{5,4,3,2,1})?cout<<The vectors are same:cout<<The vectors are not same;
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 4 steps