Skip to content

Commit

Permalink
Code uploaded
Browse files Browse the repository at this point in the history
  • Loading branch information
WaderManasi committed Jun 20, 2020
0 parents commit fb9fda9
Show file tree
Hide file tree
Showing 29 changed files with 3,697 additions and 0 deletions.
53 changes: 53 additions & 0 deletions Array/LeftRotation_Array.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
///////////////////////////////////////////////////////////////////////////////////
//Name :Manasi Mohan Wader . //
//Program :Rotate array elements through Left . //
//Language :C++ //
///////////////////////////////////////////////////////////////////////////////////

#include<iostream>
#define MAX 50
using namespace std;

///////////////////////////////////////////////////////////////////////////////////
void Rotateleft(int arr[],int size,int freq)
{
int rotation=1;
while(freq>0)
{
int temp=arr[size-1];
for(int i=size-1;i>=0;i--)
{
arr[i]=arr[i-1];
}
arr[0]=temp;
freq--;
cout<<"\nFor "<<rotation<<" rotation: ";
for(int j=0;j<size;j++)
{
cout<<arr[j]<<" ";
}
cout<<"\n";
rotation++;
}
}

///////////////////////////////////////////////////////////////////////////////////
int main()
{
int freq,size;
int arr[MAX];
cout<<"\nEnter array size: ";
cin>>size;
cout<<"\nEnter elements: ";
for(int i=0;i<size;i++)
{
cin>>arr[i];
}
cout<<"\nFrequency of rotating elements through left: ";
cin>>freq;
Rotateleft(arr,size,freq);
return 0;
}
///////////////////////////////////////////////////////////////////////////////////
//End of program
///////////////////////////////////////////////////////////////////////////////////
38 changes: 38 additions & 0 deletions Array/RemoveDuplicates_Array.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
///////////////////////////////////////////////////////////////////////////////////
//Name :Manasi Mohan Wader. //
//Program :Removing all the duplicate/same elements from Array //
//Language :C++ //
///////////////////////////////////////////////////////////////////////////////////

#include<iostream>
#define MAX 50
using namespace std;

///////////////////////////////////////////////////////////////////////////////////
void RemoveDuplicates(int arr[],int size)
{
for(int i=0;i<size;i++)
{

}
}

///////////////////////////////////////////////////////////////////////////////////
int main()
{
int size;
int arr[MAX];
cout<<"\nEnter array size: ";
cin>>size;
cout<<"\nEnter elements: ";
for(int i=0;i<size;i++)
{
cin>>arr[i];
}
RemoveDuplicates(arr,size);
return 0;
}

///////////////////////////////////////////////////////////////////////////////////
//End of program
///////////////////////////////////////////////////////////////////////////////////
53 changes: 53 additions & 0 deletions Array/RightRotation_Array.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
///////////////////////////////////////////////////////////////////////////////////
//Name :Manasi Mohan Wader. //
//Program :Rotate array elements through Right . //
//Language :C++ //
///////////////////////////////////////////////////////////////////////////////////

#include<iostream>
#define MAX 50
using namespace std;

///////////////////////////////////////////////////////////////////////////////////
void RotateRight(int arr[],int size,int freq)
{
int rotation=1;
while(freq>0)
{
int temp=arr[0];
for(int i=0;i<size-1;i++)
{
arr[i]=arr[i+1];
}
arr[size-1]=temp;
freq--;
cout<<"\nFor "<<rotation<<" rotation: ";
for(int j=0;j<size;j++)
{
cout<<arr[j]<<" ";
}
cout<<"\n";
rotation++;
}
}

///////////////////////////////////////////////////////////////////////////////////
int main()
{
int freq,size;
int arr[MAX];
cout<<"\nEnter array size: ";
cin>>size;
cout<<"\nEnter elements: ";
for(int i=0;i<size;i++)
{
cin>>arr[i];
}
cout<<"\nFrequency of rotating elements through left: ";
cin>>freq;
RotateRight(arr,size,freq);
return 0;
}
///////////////////////////////////////////////////////////////////////////////////
//End of program
///////////////////////////////////////////////////////////////////////////////////
107 changes: 107 additions & 0 deletions Graph/DirectedAdjacencyList_Graph.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
///////////////////////////////////////////////////////////////////////////////////
//Name :Manasi Mohan Wader //
//Program :Graph: Directed Adjacency List //
//Language :C++ (Object Oriented Approach) //
///////////////////////////////////////////////////////////////////////////////////

#include<bits/stdc++.h>
#define MAX 30
using namespace std;

///////////////////////////////////////////////////////////////////////////////////
class node
{
public:
int data;
node* next;
}*arr[MAX];

///////////////////////////////////////////////////////////////////////////////////
class DirAdj_List:public node
{
int v,v1,v2;
public:
DirAdj_List()
{
v=v1=v2=0;
}
void CreateList();
void DisplayList();
};
///////////////////////////////////////////////////////////////////////////////////
void DirAdj_List::CreateList()
{
int choice;
cout<<"\nEnter total vertices: ";
cin>>v;
do{
cout<<"\nEnter both vertices and cost: ";
cin>>v1>>v2;
if(v1>=v || v2>=v)
{
cout<<"\nEdge not present in graph!";
continue;
}
node* ptr1=new node;
ptr1->data=v2;
ptr1->next=NULL;

if(arr[v1]==NULL)
{
arr[v1]=ptr1;
}
else
{
node* temp=arr[v1];
while(temp->next!=NULL)
{
temp=temp->next;
}
temp->next=ptr1;
}
cout<<"\nWant to continue?[y/Y]";
cin>>choice;
}while(choice=='Y' || choice=='y');
}
///////////////////////////////////////////////////////////////////////////////////
void DirAdj_List::DisplayList()
{
for(int i=0;i<v;i++)
{
node* temp=arr[i];
cout<<"\nAdjacency List of vertex "<<i<<" is ";
while(temp)
{
cout<< "==>>"<<temp->data;
temp=temp->next;
}
}
}
///////////////////////////////////////////////////////////////////////////////////
int main()
{
DirAdj_List obj;
int ch;
do{
cout<<"\n\nSelect: \n1] Create Adjacency List of Directed graph\n2] Display Adjacency List of Directed graph\n3] Exit\n";
cin>>ch;
switch(ch)
{
case 1:
obj.CreateList();
break;
case 2:
obj.DisplayList();
break;
case 3:
return 0;
default:
cout<<"\nPlease enter correct choice!!";
break;
}
}while(1);
}

///////////////////////////////////////////////////////////////////////////////////
//End of program //
///////////////////////////////////////////////////////////////////////////////////
96 changes: 96 additions & 0 deletions Graph/DirectedAdjacencyMatrix_Graph.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
///////////////////////////////////////////////////////////////////////////////////
//Name :Manasi Mohan Wader //
//Program :Graph: Directed Adjacency Matrix //
//Language :C++ (Object Oriented Approach) //
///////////////////////////////////////////////////////////////////////////////////

#include<iostream>
#define MAX 50
using namespace std;

///////////////////////////////////////////////////////////////////////////////////
class DirAdj_Matrix
{
int v,v1,v2,flag,cost;
int G[MAX][MAX];
public:
//constructor: initializing the member variables
DirAdj_Matrix()
{
v=v1=v2=0;

for(int i=0;i<MAX;i++)
{
for(int j=0;j<MAX;j++)
{
G[i][j]=0;
}
}
}
void CreateMatrix();
void DisplayMatrix();
};

///////////////////////////////////////////////////////////////////////////////////
void DirAdj_Matrix::CreateMatrix()
{
char choice;
cout<<"\nEnter total number of vertices: ";
cin>>v;
do{
cout<<"\nEnter edges: (both vertices): ";
cin>>v1>>v2;
cout<<"\nEnter cost: ";
cin>>cost;
if(v1>= v|| v2>=v)
{
cout<<"\nEdge not Valid";
continue;
}
G[v1][v2]=cost;

cout<<"\nWant to continue? [y/Y]";
cin>>choice;

}while(choice=='y' || choice=='Y');
}
///////////////////////////////////////////////////////////////////////////////////
void DirAdj_Matrix::DisplayMatrix()
{
for(int i=0;i<v;i++)
{
for(int j=0;j<v;j++)
{
cout<<G[i][j]<<"\t";
}
cout<<"\n";
}
}
///////////////////////////////////////////////////////////////////////////////////
int main()
{
DirAdj_Matrix obj;
int ch;
do{
cout<<"\n\nSelect: \n1] Create Adjacency Matrix of Undirected graph\n2] Display Adjacency Matrix of Undirected graph\n3] Exit\n";
cin>>ch;
switch(ch)
{
case 1:
obj.CreateMatrix();
break;
case 2:
obj.DisplayMatrix();
break;
case 3:
return 0;
default:
cout<<"\nPlease enter correct choice!!";
break;
}
}while(1);
}

///////////////////////////////////////////////////////////////////////////////////
//End of program
///////////////////////////////////////////////////////////////////////////////////1
Loading

0 comments on commit fb9fda9

Please sign in to comment.