Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Neerajpathak07 patch 1 #2399

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions Hashmapping.C++
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <iostream>
#include <map>
#include <unordered_map>
using namespace std;

int main(int argc, char const *argv[])
{
//creation of map
map<string,int>m;

//insertion
//1
pair<string,int> p= make_pair("Neeraj",7);
m.insert(p);

//2
pair<string,int> pair2("love",2);
m.insert(pair2);

//3
m["Neeraj"]=1;

//search
cout <<m["Neeraj"] <<endl;
cout <<m.at("love") <<endl;

//to cheack presence
cout <<m.count("love") <<endl;

//erase
m.erase("love");
cout<<m.size() << endl;

for(auto i:m){
cout<<i.first << " " << i.second << endl;
}

//itereator
map<string,int> :: iterator it = m.begin();

while(it!=m.end()){
cout << it->first <<" " << it->second <<endl;

}
return 0;
}
84 changes: 84 additions & 0 deletions MergeSort.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#include <iostream>
using namespace std;


void merge(int *arr,int s,int e){
int len1= mid-s+1;
int len2= e-mid;

int *first=new int(len1);
int *second=new int(len2);

//copy values into new array
int mainArrayIndex=s;
for (int i = 0; i < len1; i++)
{
first[i]=arr[k++];
}

int mainArrayIndex = mid+1;
for (int i = 0; i < len2; i++)
{
second[i]=arr[k++];

}
//merge both the sorted arrays into final array
int index1=0;
int index2=0;
mainArrayIndex=0;

while(index1 < len1 && index2 < len2){
if(first(index1) < second(index2)){
arr[mainArrayIndex++]=frist[index1++];
}
else
{
arr[mainArrayIndex++]=second[index2++];

}

}
//adding the remaining elements of the first array into the final output array

while (index1 < len1){
arr[mainArrayIndex++]=first[index1++];

}
//adding the remaining elements of the second array into the final output array

while (index2<len2)
{
arr[mainArrayIndex++]= second[index2++];
}



}

void mergeSort(int *arr,int s,int e){
//base case
if(s>e)
return ;
int mid=(s+e)/2;


//sort left part
mergeSort(arr,s,mid);

//right part sorting
mergeSort(arr,mid+1,e);

//merge the two sub-divided arrays
merge(arr,s,e);


}

int main(int argc, char const *argv[])
{
int arr[5]={1,24,2,35,23};
int n=5;

mergeSort(arr,0,n-1);
return 0;
}