Last active
May 18, 2024 04:30
-
-
Save shitu13/370fb39be3c934eae682e659b3572911 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
map<int,int> mapInsert(int arr[],int n){ | |
map<int,int>mp; | |
//Insert arr[i] as key and i as value | |
for(int i=0; i<n; i++){ | |
mp[arr[i]] = i; | |
} | |
return mp; | |
} | |
void mapDisplay(map<int,int>mp){ | |
//Print every key and value pair in a new line | |
for(auto &it: mp){ | |
cout << it.first <<" "<<it.second <<endl; | |
} | |
} | |
void mapErase(map<int,int>&mp,int x){ | |
//Write the if and else condition to erase x from map | |
auto it = mp.find(x); | |
if(it!=mp.end()){ | |
mp.erase(it); | |
cout<<"erased "<<x; | |
}else{ | |
cout<<"not found"; | |
} | |
cout<<endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment