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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Implement the following function, without using any data structure or #include <bits/stdc++.h>

/* 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<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;

}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Potential Method of Analysis
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education