diff --git a/Algorithms/Algorithms for Competitive Programming/BitwiseORofBinaryNumbers.py b/Algorithms/Algorithms for Competitive Programming/BitwiseORofBinaryNumbers.py index 0c91951..188a778 100644 --- a/Algorithms/Algorithms for Competitive Programming/BitwiseORofBinaryNumbers.py +++ b/Algorithms/Algorithms for Competitive Programming/BitwiseORofBinaryNumbers.py @@ -1,9 +1,9 @@ -from itertools import combinations -n,m=map(int,input().split()) -strings=[] -for i in range(n): - strings.append(input()) -combos=list(combinations(strings,2)) -or_res=[] -for i in combos: +from itertools import combinations +n,m=map(int,input().split()) +strings=[] +for i in range(n): + strings.append(input()) +combos=list(combinations(strings,2)) +or_res=[] +for i in combos: or_res.append(bin(int('0b' + i[0], 2) | int('0b' + i[1], 2)).count('1')) \ No newline at end of file diff --git a/Algorithms/Algorithms for Competitive Programming/Deletion.c b/Algorithms/Algorithms for Competitive Programming/Deletion.c index f12a142..966d50d 100644 --- a/Algorithms/Algorithms for Competitive Programming/Deletion.c +++ b/Algorithms/Algorithms for Competitive Programming/Deletion.c @@ -1,181 +1,181 @@ -#include -#include -#include -int item; -void insert_end(); -void delete_by_location(); -void delete_by_item(); -void display(void); -struct node -{ - int data; - struct node *next; -}; -struct node *start; -struct node *tail = NULL; -void main() -{ - int choice; - printf("PUSH ELEMENTS ONE BY ONE BEFORE DELETING INTO THE LINKED LIST:"); - int will; - while(will) - { - insert_end(); - printf("ENTER 1 TO CONTINUE INSERTING AND 0 TO STOP:"); - scanf("%d",&will); - } - while (1) - { - printf("\n LINKED LIST: \n 1. DELETE BY LOCATION\n 2. DELETE BY VALUE\n 3. DISPLAY\n 4. EXIT\n\n"); - printf("\nENTER YOUR CHOICE:\n"); - scanf("%d", &choice); - switch (choice) - { - case 1: - delete_by_location(); - break; - case 2: - delete_by_item(); - break; - case 3: - display(); - break; - case 4: - exit(0); - break; - default: - printf("\n YOU HAVE ENTERED A WRONG CHOICE\n"); - } - } - -} -void insert_end() -{ - struct node *p = start, *temp; - - temp = (struct node *)malloc(sizeof(struct node)); - printf("\n ENTER ITEM:\n"); - scanf("%d", &item); - temp->data = item; - if (start == NULL) - { - start = temp; - temp->next = NULL; - } - else - { - while (p->next != NULL) - { - p = p->next; - } - p->next = temp; - temp->next = NULL; - } -} -void delete_by_location() -{ - struct node *p = start, *old = start, *temp; - int loc, i; - if (start==NULL) - { - printf("NOTHING TO DELETE"); - return; - } - printf("\nENTER LOCATION:\n"); - scanf("%d", &loc); - for (i = 1; i < loc; i++) - { - p = p->next; - } - - if (p == NULL) - { - printf("LOCATION NOT FOUND\n"); - free(p); - return; - } - if (p == start) - { - start = start->next; - free(p); - } - else if (p->next == NULL) - { - for (i = 1; i < loc - 1; i++) - { - old = old->next; - } - old->next = NULL; - free(p); - } - - else - { - for (i = 1; i < loc - 1; i++) - { - old = old->next; - } - old->next = p->next; - free(p); - } -} -void delete_by_item() -{ - int value; - struct node *p = start, *old = start, *temp; - if (start == NULL) - { - printf("NOTHING TO DELETE\n"); - return; - } - printf("\nENTER DATA OF A NODE WHICH YOU WISH TO DELETE:\n"); - scanf("%d", &value); - while (p->data != value) - { - p = p->next; - if (p==NULL) - { - printf("VALUE ENTERED IS NOT FOUND"); - free(p); - return; - } - } - - if (p == start) - { - start = start->next; - free(p); - } - else if (p->next == NULL) - { - while (old->next->data != value) - { - old = old->next; - } - old->next = NULL; - free(p); - } - - - else - { - while (old->next->data != value) - { - old = old->next; - } - old->next = p->next; - free(p); - } -} -void display() -{ - struct node *p = start; - printf("\n YOUR LINKED LIST LOOKS LIKE :\n\n"); - printf("\n|_START"); - while (p != NULL) - { - printf(" |_%d_|_|->", p->data); - p = p->next; - } - printf("[NULL]\n"); -} +#include +#include +#include +int item; +void insert_end(); +void delete_by_location(); +void delete_by_item(); +void display(void); +struct node +{ + int data; + struct node *next; +}; +struct node *start; +struct node *tail = NULL; +void main() +{ + int choice; + printf("PUSH ELEMENTS ONE BY ONE BEFORE DELETING INTO THE LINKED LIST:"); + int will; + while(will) + { + insert_end(); + printf("ENTER 1 TO CONTINUE INSERTING AND 0 TO STOP:"); + scanf("%d",&will); + } + while (1) + { + printf("\n LINKED LIST: \n 1. DELETE BY LOCATION\n 2. DELETE BY VALUE\n 3. DISPLAY\n 4. EXIT\n\n"); + printf("\nENTER YOUR CHOICE:\n"); + scanf("%d", &choice); + switch (choice) + { + case 1: + delete_by_location(); + break; + case 2: + delete_by_item(); + break; + case 3: + display(); + break; + case 4: + exit(0); + break; + default: + printf("\n YOU HAVE ENTERED A WRONG CHOICE\n"); + } + } + +} +void insert_end() +{ + struct node *p = start, *temp; + + temp = (struct node *)malloc(sizeof(struct node)); + printf("\n ENTER ITEM:\n"); + scanf("%d", &item); + temp->data = item; + if (start == NULL) + { + start = temp; + temp->next = NULL; + } + else + { + while (p->next != NULL) + { + p = p->next; + } + p->next = temp; + temp->next = NULL; + } +} +void delete_by_location() +{ + struct node *p = start, *old = start, *temp; + int loc, i; + if (start==NULL) + { + printf("NOTHING TO DELETE"); + return; + } + printf("\nENTER LOCATION:\n"); + scanf("%d", &loc); + for (i = 1; i < loc; i++) + { + p = p->next; + } + + if (p == NULL) + { + printf("LOCATION NOT FOUND\n"); + free(p); + return; + } + if (p == start) + { + start = start->next; + free(p); + } + else if (p->next == NULL) + { + for (i = 1; i < loc - 1; i++) + { + old = old->next; + } + old->next = NULL; + free(p); + } + + else + { + for (i = 1; i < loc - 1; i++) + { + old = old->next; + } + old->next = p->next; + free(p); + } +} +void delete_by_item() +{ + int value; + struct node *p = start, *old = start, *temp; + if (start == NULL) + { + printf("NOTHING TO DELETE\n"); + return; + } + printf("\nENTER DATA OF A NODE WHICH YOU WISH TO DELETE:\n"); + scanf("%d", &value); + while (p->data != value) + { + p = p->next; + if (p==NULL) + { + printf("VALUE ENTERED IS NOT FOUND"); + free(p); + return; + } + } + + if (p == start) + { + start = start->next; + free(p); + } + else if (p->next == NULL) + { + while (old->next->data != value) + { + old = old->next; + } + old->next = NULL; + free(p); + } + + + else + { + while (old->next->data != value) + { + old = old->next; + } + old->next = p->next; + free(p); + } +} +void display() +{ + struct node *p = start; + printf("\n YOUR LINKED LIST LOOKS LIKE :\n\n"); + printf("\n|_START"); + while (p != NULL) + { + printf(" |_%d_|_|->", p->data); + p = p->next; + } + printf("[NULL]\n"); +} diff --git a/Algorithms/Algorithms for Competitive Programming/checkIfSameConsecutiveElements.py b/Algorithms/Algorithms for Competitive Programming/checkIfSameConsecutiveElements.py index ce6986b..17bc067 100644 --- a/Algorithms/Algorithms for Competitive Programming/checkIfSameConsecutiveElements.py +++ b/Algorithms/Algorithms for Competitive Programming/checkIfSameConsecutiveElements.py @@ -1,2 +1,2 @@ -l=[1,2,3,4,5,5] -print(any(i==j for i,j in zip(l,l[1:]))) +l=[1,2,3,4,5,5] +print(any(i==j for i,j in zip(l,l[1:]))) diff --git a/Algorithms/Algorithms for Competitive Programming/detectCycleDirectedTopological.cpp b/Algorithms/Algorithms for Competitive Programming/detectCycleDirectedTopological.cpp new file mode 100644 index 0000000..281c708 --- /dev/null +++ b/Algorithms/Algorithms for Competitive Programming/detectCycleDirectedTopological.cpp @@ -0,0 +1,53 @@ +#include +using namespace std; + +/* Function to check if the given graph contains cycle +* V: number of vertices +* adj[]: representation of graph +*/ +bool isCyclic(int V, vector adj[]) +{ + // Your code here + vector indegree(V,0); + for(int i = 0; i < V; i++){ + for(int j = 0; j < adj[i].size(); j++){ + indegree[adj[i][j]]++; + } + } + queue q; + for(int i = 0; i < V; i++){ + if(!indegree[i]) + q.push(i); + } + int processed = 0; + while(q.size()){ + int t = q.front(); + q.pop(); + for(int i = 0; i < adj[t].size(); i++){ + indegree[adj[t][i]]--; + if(indegree[adj[t][i]] == 0) + q.push(adj[t][i]); + } + processed++; + } + return processed < V; +} + + +int main() { + + int t; + cin >> t; + while(t--){ + int v, e; + cin >> v >> e; + vector adj[v]; + for(int i =0;i> u >> v; + adj[u].push_back(v); + } + cout << isCyclic(v, adj) << endl; + } + return 0; +} \ No newline at end of file diff --git a/Algorithms/Algorithms for Competitive Programming/gauss elimination.cpp b/Algorithms/Algorithms for Competitive Programming/gauss elimination.cpp index 8ebc61c..f22ce97 100644 --- a/Algorithms/Algorithms for Competitive Programming/gauss elimination.cpp +++ b/Algorithms/Algorithms for Competitive Programming/gauss elimination.cpp @@ -1,49 +1,49 @@ - -#include -int main() -{ - int i,j,k,n; - float A[20][20],c,x[10],sum=0.0; - printf("\nEnter the order of matrix: "); - scanf("%d",&n); - printf("\nEnter the elements of augmented matrix row-wise:\n\n"); - for(i=1; i<=n; i++) - { - for(j=1; j<=(n+1); j++) - { - printf("A[%d][%d] : ", i,j); - scanf("%f",&A[i][j]); - } - } - for(j=1; j<=n; j++) /* loop for the generation of upper triangular matrix*/ - { - for(i=1; i<=n; i++) - { - if(i>j) - { - c=A[i][j]/A[j][j]; - for(k=1; k<=n+1; k++) - { - A[i][k]=A[i][k]-c*A[j][k]; - } - } - } - } - x[n]=A[n][n+1]/A[n][n]; - /* this loop is for backward substitution*/ - for(i=n-1; i>=1; i--) - { - sum=0; - for(j=i+1; j<=n; j++) - { - sum=sum+A[i][j]*x[j]; - } - x[i]=(A[i][n+1]-sum)/A[i][i]; - } - printf("\nThe solution is: \n"); - for(i=1; i<=n; i++) - { - printf("\nx%d=%f\t",i,x[i]); /* x1, x2, x3 are the required solutions*/ - } - return(0); -} + +#include +int main() +{ + int i,j,k,n; + float A[20][20],c,x[10],sum=0.0; + printf("\nEnter the order of matrix: "); + scanf("%d",&n); + printf("\nEnter the elements of augmented matrix row-wise:\n\n"); + for(i=1; i<=n; i++) + { + for(j=1; j<=(n+1); j++) + { + printf("A[%d][%d] : ", i,j); + scanf("%f",&A[i][j]); + } + } + for(j=1; j<=n; j++) /* loop for the generation of upper triangular matrix*/ + { + for(i=1; i<=n; i++) + { + if(i>j) + { + c=A[i][j]/A[j][j]; + for(k=1; k<=n+1; k++) + { + A[i][k]=A[i][k]-c*A[j][k]; + } + } + } + } + x[n]=A[n][n+1]/A[n][n]; + /* this loop is for backward substitution*/ + for(i=n-1; i>=1; i--) + { + sum=0; + for(j=i+1; j<=n; j++) + { + sum=sum+A[i][j]*x[j]; + } + x[i]=(A[i][n+1]-sum)/A[i][i]; + } + printf("\nThe solution is: \n"); + for(i=1; i<=n; i++) + { + printf("\nx%d=%f\t",i,x[i]); /* x1, x2, x3 are the required solutions*/ + } + return(0); +} diff --git a/Algorithms/Dynamic programming on Graphs /BFS-Graph/run b/Algorithms/Dynamic programming on Graphs /BFS-Graph/run deleted file mode 100644 index 273ab92..0000000 Binary files a/Algorithms/Dynamic programming on Graphs /BFS-Graph/run and /dev/null differ diff --git a/Algorithms/Dynamic programming on Graphs /BFS-Graph/run.cpp b/Algorithms/Dynamic programming on Graphs /BFS-Graph/run.cpp deleted file mode 100644 index 494692f..0000000 --- a/Algorithms/Dynamic programming on Graphs /BFS-Graph/run.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* This is an algorithm to do breadth first traversal of a graph. - - Written by : Arnab Chanda - 01.09.2019 -*/ - -#include -using namespace std; - -class Graph{ - public: - int value; - list *edges; - - Graph(int val){ - - value = val; - edges = new list[val]; - } - void initialise_edges(int val1,int val2){ - - edges[val1].push_back(val2); - } - void bfs(int s){ - - listqueue; - bool visited[value]; - for(int i =0;i>n; - Graph g = Graph(n); - - cout<<"Enter the edges of the graph: "<>edges; - while(edges-->0){ - int x,y; - cin>>x>>y; - g.initialise_edges(x,y); - //for bidirected graph add the following line - //g.initialise_edges(y,x); - } - cout<<"Enter the starting element: "<>start; - - g.bfs(start); -} - diff --git a/Algorithms/Dynamic programming on Graphs /Bellman-Ford Algorithm/run b/Algorithms/Dynamic programming on Graphs /Bellman-Ford Algorithm/run deleted file mode 100644 index 4451914..0000000 Binary files a/Algorithms/Dynamic programming on Graphs /Bellman-Ford Algorithm/run and /dev/null differ diff --git a/Algorithms/Dynamic programming on Graphs /Bellman-Ford Algorithm/run.cpp b/Algorithms/Dynamic programming on Graphs /Bellman-Ford Algorithm/run.cpp deleted file mode 100644 index be080a9..0000000 --- a/Algorithms/Dynamic programming on Graphs /Bellman-Ford Algorithm/run.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/* - Bellman-Ford algorithm - -Bellman-Ford algorithm helps to find the shortest path from one point to all the points in a graph. -Below is the c++ implementation of the algorithm. - -Time complexity: O(n*e), where n is the number of nodes in the graph and e is the number of edges - -Created by: Arnab Chanda,17.08.2019 - -*/ - -#include - -using namespace std; - -int edgelist[10000][3]; -map nodevalues; - -//functiont o print the shortest path map -void print_shortest_paths(int nodes){ - cout<<"Shortest paths from starting index are as follows :"<::iterator itr; - for(itr = nodevalues.begin();itr!=nodevalues.end();++itr){ - cout<first<<"\t"<second<second+edgelist[i][2]second){ - nodevalues[edgelist[i][1]]=nodevalues.find(edgelist[i][0])->second+edgelist[i][2]; - c++; - } - } - //this part checks for negetive edge cycle in the graph - if(j == nodes-1 && c>0){ - cout<<"The graph contains negetive edge cycle"<>nodes; - - //input the starting node - int starting_node; - cout<<"Enter the node from which you want to find the shortest path: "<>starting_node; - - //taking input for the number of edges - int edges; - cout << "Enter the number of edges in the graph: "<> edges; - - //filling the adjacency matrix with 0 - cout<<"Enter the value of the edges where the first number is the starting vertex of the edge the second \n is the endung vertex and the third is the weight of the eddge"<>edgelist[i][0]>>edgelist[i][1]>>edgelist[i][2]; - if (nodevalues.count(edgelist[i][0]) == 0){ - if (edgelist[i][0] == starting_node){ - nodevalues.insert(pair(edgelist[i][0],0)); - } - else{ - nodevalues.insert(pair(edgelist[i][0],99999)); - } - } - if (nodevalues.count(edgelist[i][1]) == 0){ - if (edgelist[i][1] == starting_node){ - nodevalues.insert(pair(edgelist[i][1],0)); - } - else{ - nodevalues.insert(pair(edgelist[i][1],99999)); - } - } - } - - bellman_ford(starting_node,nodes,edges); - - return 0; -} \ No newline at end of file diff --git a/Algorithms/Dynamic programming on Graphs /DFS-Graph/run b/Algorithms/Dynamic programming on Graphs /DFS-Graph/run deleted file mode 100644 index d096258..0000000 Binary files a/Algorithms/Dynamic programming on Graphs /DFS-Graph/run and /dev/null differ diff --git a/Algorithms/Dynamic programming on Graphs /DFS-Graph/run.cpp b/Algorithms/Dynamic programming on Graphs /DFS-Graph/run.cpp deleted file mode 100644 index 7c5af0a..0000000 --- a/Algorithms/Dynamic programming on Graphs /DFS-Graph/run.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/* The following is the c++ implementation of DF traversal of a graph - -Created by : Arnab Chanda - 01.09.2019 - -*/ - -#include -using namespace std; - -class Graph{ - public: - int value; - list *edges; - - Graph(int val){ - - value = val; - edges = new list[val]; - } - void initialise_edges(int val1,int val2){ - - edges[val1].push_back(val2); - } - - void dfs_traversal(int s, bool visited[] ){ - visited[s] = true; - cout<>n; - Graph g = Graph(n); - - cout<<"Enter the edges of the graph: "<>edges; - while(edges-->0){ - int x,y; - cin>>x>>y; - g.initialise_edges(x,y); - //for bidirected graph add the following line - //g.initialise_edges(y,x); - } - cout<<"Enter the starting element: "<>start; - - g.dfs(start); - return 0; -} \ No newline at end of file diff --git a/Algorithms/Dynamic programming on Graphs /Dijkstra-Algorithm/run b/Algorithms/Dynamic programming on Graphs /Dijkstra-Algorithm/run deleted file mode 100644 index 6b16896..0000000 Binary files a/Algorithms/Dynamic programming on Graphs /Dijkstra-Algorithm/run and /dev/null differ diff --git a/Algorithms/Dynamic programming on Graphs /Dijkstra-Algorithm/run.cpp b/Algorithms/Dynamic programming on Graphs /Dijkstra-Algorithm/run.cpp deleted file mode 100644 index 1eb5ffc..0000000 --- a/Algorithms/Dynamic programming on Graphs /Dijkstra-Algorithm/run.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* Dijkstra Algorithm - Shortest path between two single points algorithm - -Time complexity Worst case = O(n*n) - -Created by: Arnab Chanda - 21.08.2019 - -*/ - -#include - -using namespace std; - -int edgelist[10000][3]; - -map nodevalues; -map finalresult; - -//function to print the result -void printresult(){ - map::iterator itr; - for(itr = finalresult.begin();itr!=finalresult.end();++itr){ - cout<<"The distance between the starting node and "<first<<" is : "<second<::iterator itr; - while(finalresult.size()secondfirst)==finalresult.end())){ - min = itr->second; - nextNode = itr->first; - finalresult.insert(pair(nextNode,min)); - } - } - for(int i = 0;isecond){ - nodevalues[edgelist[i][1]] = min+edgelist[i][2]; - } - } - } - } - printresult(); -} - - - -int main(){ - - //input the number of nodes - int nodes; - cout<<"Dijkstra Algorithm"<>nodes; - - //input the starting node - int starting_node; - cout<<"Enter the node from which you want to find the shortest path: "<>starting_node; - - //taking input for the number of edges - int edges; - cout << "Enter the number of edges in the graph: "<> edges; - - //filling the adjacency matrix with 0 - cout<<"Enter the value of the edges where the first number is the starting vertex of the edge the second \nis the endung vertex and the third is the weight of the eddge"<>edgelist[i][0]>>edgelist[i][1]>>edgelist[i][2]; - if (edgelist[i][0] == starting_node){ - nodevalues.insert(pair(edgelist[i][1],edgelist[i][2])); - } - else{ - nodevalues.insert(pair(edgelist[i][1],99999)); - } - - } - cout<<"All inputs taken!"< - -using namespace std; - -class Graph{ - - public: - - int v; - list *adj; - - Graph(int edges){ - v = edges; - adj = new list[v]; - } - - void add_edge(int x, int y){ - adj[x].push_back(y); - adj[y].push_back(x); - } - - void dfs(int pos, bool visited[]){ - visited[pos] = true; - - for(auto i = adj[pos].begin();i!= adj[pos].end();++i){ - if(visited[*i] == false){ - dfs(*i,visited); - } - } - } - - bool isConnected(){ - - bool visited[v]; - int i; - - for(i = 0;i0) - break; - } - - if(i == v){ - return false; - } - - dfs(i,visited); - - for(i = 0;i0){ - return false; - } - } - - return true; - } - - void checkEuler(){ - - if(isConnected() == false){ - cout<<"Sorry the graph is not an Euler graph"<2){ - cout<<"The graph is not Eulerian"<>n; - Graph g = Graph(n); - - cout<<"Enter the edges of the graph: "<>edges; - while(edges-->0){ - int x,y; - cin>>x>>y; - g.add_edge(x,y); - } - - g.checkEuler(); - return 0; -} \ No newline at end of file diff --git a/Algorithms/Dynamic programming on Graphs /Floyd-Warshall-Algorithm/run b/Algorithms/Dynamic programming on Graphs /Floyd-Warshall-Algorithm/run deleted file mode 100644 index 63aed55..0000000 Binary files a/Algorithms/Dynamic programming on Graphs /Floyd-Warshall-Algorithm/run and /dev/null differ diff --git a/Algorithms/Dynamic programming on Graphs /Floyd-Warshall-Algorithm/run.cpp b/Algorithms/Dynamic programming on Graphs /Floyd-Warshall-Algorithm/run.cpp deleted file mode 100644 index 13cbc20..0000000 --- a/Algorithms/Dynamic programming on Graphs /Floyd-Warshall-Algorithm/run.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* - Floyd Warshall algorithm - -Floyd Warshall algorithm helps to find the shortest pair path between all the points in a graph. -Below is the c++ implementation of the algorithm. - -Time complexity: O(n*n*n) - -Created by: Arnab Chanda,14.08.2019 - -*/ - -#include - -using namespace std; - -int adjacencymatrix[1000][1000]; -int d[1000][1000]; - -void printMatrix(int nodes){ - - //printing the matrix - cout<<"The final path matrix : "<>nodes; - - //filling the adjacency matrix with 0 - for(int i = 0;i>x; - if(x>=0){ - adjacencymatrix[i][j] = x; - } - } - } - - //print the adjacency matrix - for(int i = 0;i -using namespace std; - -#define edge pair - -class Graph { -private: - vector> G; // graph - vector> T; // mst - int *parent; - int V; // number of vertices/nodes in graph -public: - Graph(int V); - void AddWeightedEdge(int u, int v, int w); - int find_set(int i); - void union_set(int u, int v); - void kruskal(); - void print(); -}; -Graph::Graph(int V) { - parent = new int[V]; - - //i 0 1 2 3 4 5 - //parent[i] 0 1 2 3 4 5 - for (int i = 0; i < V; i++) - parent[i] = i; - - G.clear(); - T.clear(); -} -void Graph::AddWeightedEdge(int u, int v, int w) { - G.push_back(make_pair(w, edge(u, v))); -} -int Graph::find_set(int i) { - // If i is the parent of itself - if (i == parent[i]) - return i; - else - // Else if i is not the parent of itself - // Then i is not the representative of his set, - // so we recursively call Find on its parent - return find_set(parent[i]); -} - -void Graph::union_set(int u, int v) { - parent[u] = parent[v]; -} -void Graph::kruskal() { - int i, uRep, vRep; - sort(G.begin(), G.end()); // increasing weight - for (i = 0; i < G.size(); i++) { - uRep = find_set(G[i].second.first); - vRep = find_set(G[i].second.second); - if (uRep != vRep) { - T.push_back(G[i]); // add to tree - union_set(uRep, vRep); - } - } -} -void Graph::print() { - cout << "Edge :" << " Weight" << endl; - for (int i = 0; i < T.size(); i++) { - cout << T[i].second.first << " - " << T[i].second.second << " : " - << T[i].first; - cout << endl; - } -} -int main() { - Graph g(6); - g.AddWeightedEdge(0, 1, 4); - g.AddWeightedEdge(0, 2, 4); - g.AddWeightedEdge(1, 2, 2); - g.AddWeightedEdge(1, 0, 4); - g.AddWeightedEdge(2, 0, 4); - g.AddWeightedEdge(2, 1, 2); - g.AddWeightedEdge(2, 3, 3); - g.AddWeightedEdge(2, 5, 2); - g.AddWeightedEdge(2, 4, 4); - g.AddWeightedEdge(3, 2, 3); - g.AddWeightedEdge(3, 4, 3); - g.AddWeightedEdge(4, 2, 4); - g.AddWeightedEdge(4, 3, 3); - g.AddWeightedEdge(5, 2, 2); - g.AddWeightedEdge(5, 4, 3); - g.kruskal(); - g.print(); - return 0; -} \ No newline at end of file diff --git a/Algorithms/Greedy Algorithms/Job-Sequencing-Deadline/run b/Algorithms/Greedy Algorithms/Job-Sequencing-Deadline/run deleted file mode 100644 index 1ba58eb..0000000 Binary files a/Algorithms/Greedy Algorithms/Job-Sequencing-Deadline/run and /dev/null differ diff --git a/Algorithms/Greedy Algorithms/Job-Sequencing-Deadline/run.cpp b/Algorithms/Greedy Algorithms/Job-Sequencing-Deadline/run.cpp deleted file mode 100644 index c8f10f1..0000000 --- a/Algorithms/Greedy Algorithms/Job-Sequencing-Deadline/run.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* - -Job sequencing algorithm. - -Created on: 13.09.2019 - Arnab Chanda -*/ - -#include - -using namespace std; - -// A structure to represent a job -struct Job -{ - char id; // Job Id - int dead; // Deadline of job - int profit; // Profit if job is over before or on deadline -}; - -// This function is used for sorting all jobs according to profit -bool comparison(Job a, Job b) -{ - return (a.profit > b.profit); -} - -// Returns minimum number of platforms reqquired -void printJobScheduling(Job arr[], int n) -{ - // Sort all jobs according to decreasing order of prfit - sort(arr, arr+n, comparison); - - int result[n]; // To store result (Sequence of jobs) - bool slot[n]; // To keep track of free time slots - - // Initialize all slots to be free - for (int i=0; i=0; j--) - { - // Free slot found - if (slot[j]==false) - { - result[j] = i; // Add this job to result - slot[j] = true; // Make this slot occupied - break; - } - } - } - - // Print the result - for (int i=0; i -#include -int a[30],count=0; -int place(int pos) { -int i; -for (i=1;i -void towers(int, char, char, char); -int main() - -{ - int num; - printf("Enter the number of disks : "); - scanf("%d", &num); - printf("The sequence of moves involved in the Tower of Hanoi are :\n"); - towers(num, 'A', 'B', 'C'); - return 0; -} - -void towers(int num, char beg, char aux, char end) - -{ - if (num == 1) - { - printf("\n Move disk 1 from peg %c to peg %c", beg, end); - return; - } - towers(num - 1, beg,end,aux); - printf("\n Move disk %d from peg %c to peg %c", num, beg, aux); - towers(num - 1, aux,beg,end); - -} - diff --git a/Algorithms/Recursion/Tower of Hanoi/j.exe b/Algorithms/Recursion/Tower of Hanoi/j.exe deleted file mode 100644 index 0457ae4..0000000 Binary files a/Algorithms/Recursion/Tower of Hanoi/j.exe and /dev/null differ diff --git a/Algorithms/Searching/linear,binary,interpolation/AllInOne.cpp b/Algorithms/Searching/linear,binary,interpolation/AllInOne.cpp deleted file mode 100644 index 7dd5efe..0000000 --- a/Algorithms/Searching/linear,binary,interpolation/AllInOne.cpp +++ /dev/null @@ -1,96 +0,0 @@ -#include - -#define MAX 10 - -void linear(int a[],int n,int s){ - int i,j; - for(i=0;i l) - printf("\nSearch Element : %d : Not Found \n",s); -} - -void interpolation(int a[],int n,int s){ - - int f,l,pos; - f=0; - l=n-1; - while(f<=l && s>=a[f] && s<=a[l]){ - pos=f + (((double)(l - f) / (a[l] - a[f])) * (s - a[f])); - - if(s==a[pos]) { - - printf("Element : %d : Found : Position : %d.\n",s,pos+1); - break; - } - else if(s>a[pos]) - f=pos+1; - else - l=pos-1; - } - - if (f > l) - printf("\nSearch Element : %d : Not Found \n",s); - } - -int main(){ - int i,a[MAX],n,s,c; - printf("Enter the number of elements: "); - scanf("%d",&n); - printf("Enter the array elements: "); - for(i=0;i -using namespace std; - -void swap(int *xp, int *yp) -{ - int temp = *xp; - *xp = *yp; - *yp = temp; -} - -// A function to implement bubble sort -void bubbleSort(int arr[], int n) -{ - int i, j; - for (i = 0; i < n-1; i++) - - // Last i elements are already in place - for (j = 0; j < n-i-1; j++) - if (arr[j] > arr[j+1]) - swap(&arr[j], &arr[j+1]); -} - -/* Function to print an array */ -void printArray(int arr[], int size) -{ - int i; - for (i = 0; i < size; i++) - cout << arr[i] << " "; - cout << endl; -} - -// Driver code -int main() -{ - int arr[] = {64, 34, 25, 12, 22, 11, 90}; - int n = sizeof(arr)/sizeof(arr[0]); - bubbleSort(arr, n); - cout<<"Sorted array: \n"; - printArray(arr, n); - return 0; -} diff --git a/Algorithms/Sorting/Heap sort.cpp b/Algorithms/Sorting/Heap sort.cpp deleted file mode 100644 index 6ad223c..0000000 --- a/Algorithms/Sorting/Heap sort.cpp +++ /dev/null @@ -1,83 +0,0 @@ - -#include -#include - - -void merge(int a[], int lb, int ub) -{ - int i,start,m,k,l,b[10]; - start=lb; - l=lb; - m=(lb+ub)/2; - k=m+1; - while(lb<=m&&k<=ub){ - if(a[lb]>=a[k]){ - b[l]=a[k]; - k++; - } - else{ - b[l]=a[lb]; - lb++; - } - l++; - } - if(lb>m){ - while(k<=ub){ - b[l]=a[k]; - l++; - k++; - } - } - else{ - while(lb<=m){ - b[l]=a[lb]; - l++; - lb++; - } - } - for(l=start;l<=ub;l++){ - a[l]=b[l]; - } - -} -void mergeSort(int arr[], int l, int u) -{ - if (l < u) - { - - int m = (l+u)/2; - - // Sort first and second halves - mergeSort(arr, l, m); - mergeSort(arr, m+1, u); - - merge(arr, l, u); - } -} - -/* UTILITY FUNCTIONS */ -/* Function to print an array */ -void printArray(int A[], int size) -{ - int i; - for (i=0; i < size; i++) - printf("%d ", A[i]); - printf("\n"); -} - -/* Driver program to test above functions */ -int main() -{ - int arr[] = {1, 11, 13, 5, 6, 7}; - int arr_size = sizeof(arr)/sizeof(arr[0]); - int lb=0,ub=arr_size-1; - printf("Given array is \n"); - printArray(arr, arr_size); - - mergeSort(arr, lb,ub); - - printf("\nSorted array is \n"); - printArray(arr, arr_size); - return 0; -} - diff --git a/Algorithms/Sorting/Heap sort.exe b/Algorithms/Sorting/Heap sort.exe deleted file mode 100644 index 5033277..0000000 Binary files a/Algorithms/Sorting/Heap sort.exe and /dev/null differ diff --git a/Algorithms/Sorting/Selection&Insertion&Bubble.cpp b/Algorithms/Sorting/Selection&Insertion&Bubble.cpp deleted file mode 100644 index e16a6c9..0000000 --- a/Algorithms/Sorting/Selection&Insertion&Bubble.cpp +++ /dev/null @@ -1,71 +0,0 @@ -#include -#define MAX 10 - - - -void selection(int a[] ,int n){ - int i,j,min,temp; - for(i=0;ia[j+1]){ - temp=a[j]; - a[j]+=a[j+1]; - a[j+1]=temp; - } - } - } - } -void insertion(int a[],int n) -{ - int i,k,j; - for (i = 1 ; i <= n - 1; i++) { - k = i; - while ( k > 0 && a[k-1] > a[k]) { - temp= a[k]; - a[k] = a[k-1]; - a[k-1] = temp; - k-- -} -int main(){ - int i,a[MAX],n,c; - printf("Enter the number of elements: "); - scanf("%d",&n); - printf("Enter the elements: "); - for(i=0;i -using namespace std; - -int shellSort(int arr[], int n) -{ - for (int gap = n/2; gap > 0; gap /= 2) - { - for (int i = gap; i < n; i += 1) - { - int temp = arr[i]; - - int j; - for (j = i; j >= gap && arr[j - gap] > temp; j -= gap) - arr[j] = arr[j - gap]; - - - arr[j] = temp; - } - } - return 0; -} - -void printArray(int arr[], int n) -{ - for (int i=0; i>arr[i]; - } - n = sizeof(arr)/sizeof(arr[0]); - cout << "Array before sorting: \n"; - printArray(arr, n); - - shellSort(arr, n); - - cout << "\nArray after sorting: \n"; - printArray(arr, n); - - return 0; -} diff --git a/Algorithms/Sorting/mergeSort.cpp b/Algorithms/Sorting/mergeSort.cpp deleted file mode 100644 index 72a08db..0000000 --- a/Algorithms/Sorting/mergeSort.cpp +++ /dev/null @@ -1,118 +0,0 @@ -#include -using namespace std; - -// Merges two sorted subarrays of A[]. -// First sorted subarray is A[l..m]. -// Second sorted subarray is A[m+1..r]. -// You might want to call this function in function mergeSort(). -void merge(int A[], int l, int m, int r) -{ - int i = 0; // cursor in leftArray[] - int j = 0; // cursor in rightArray[] - int k = l; // cursor in A[] - - int sizeOfRight = r - m; // calculates sizes of subarrays - int sizeOfLeft = m - l + 1; - - int leftArray[sizeOfLeft]; // creates temporary arrays - int rightArray[sizeOfRight]; - - for (i; i < sizeOfLeft; i++) { // fills leftArray[] - leftArray[i] = A[k]; - k++; - } - - for (j; j < sizeOfRight; j++) { // fills rightAray[] - rightArray[j] = A[k]; - k++; - } - - i = 0; // reseting cursors - j = 0; - k = l; - - // merging contents of arrays - while (i < sizeOfLeft && j < sizeOfRight) { - if (leftArray[i] <= rightArray[j]) { - A[k] = leftArray[i]; - i++; - k++; - } - else { - A[k] = rightArray[j]; - j++; - k++; - } - } - - // finishes merging the remaining array - while (i < sizeOfLeft) { - A[k] = leftArray[i]; - i++; - k++; - } - - while (j < sizeOfRight) { - A[k] = rightArray[j]; - j++; - k++; - } -} - -// using mergeSort to sort sub-array A[l..r] -// l is for left index and r is right index of the -// sub-array of A[] to be sorted -void mergeSort(int A[], int l, int r) -{ - int first = l; - int last = r; - - if (first == last) // base case - return; - else { - int middle = (first + last) / 2; // general case - - mergeSort(A,first, middle); - mergeSort(A, middle + 1, last); - - merge(A, first, middle, last); - } -} - -int main() -{ - cout << "Please enter the length (number of elements) of the input array: "; - int n; - cin >> n; - - if(n <= 0) { - cout << "Illegal input array length!" << endl; - return 0; - } - - int* A = new int [n]; - - cout << "Please enter each element in the array" << endl; - cout << "(each element must be an integer within the range of int type)." << endl; - for(int i=0; i -using namespace std; - -void swap(int* a, int* b) -{ - int t = *a; - *a = *b; - *b = t; -} - -int partition (int arr[], int low, int high) -{ - int pivot = arr[high]; - int i = (low - 1); - - for (int j = low; j <= high - 1; j++) - { - if (arr[j] < pivot) - { - i++; - swap(&arr[i], &arr[j]); - } - } - swap(&arr[i + 1], &arr[high]); - return (i + 1); -} - -void quickSort(int arr[], int low, int high) -{ - if (low < high) - { - int pi = partition(arr, low, high); - - quickSort(arr, low, pi - 1); - quickSort(arr, pi + 1, high); - } -} - -void printArray(int arr[], int size) -{ - int i; - for (i = 0; i < size; i++) - cout << arr[i] << " "; - cout << endl; -} - -int main() -{ - int arr[] = {10, 7, 8, 9, 1, 5}; - int n = sizeof(arr) / sizeof(arr[0]); - quickSort(arr, 0, n - 1); - cout << "Sorted array: \n"; - printArray(arr, n); - return 0; -} diff --git a/Data Structures/Heap/heap.cpp b/Data Structures/Heap/heap.cpp deleted file mode 100644 index 5757888..0000000 --- a/Data Structures/Heap/heap.cpp +++ /dev/null @@ -1,175 +0,0 @@ -#include -using namespace std; - -// A heap can be implemented using an array -// The child of parent node ,which is at index i in array -// will always be at index 2i+1 and 2i+2 -class heap { - int arr[50]; - int count; - public: - heap(); - bool isFull(); - bool isEmpty(); - void insert(int); - int getSize(); // Get the current size of heap - void heapify(int); - void build_max_heap(); // Build a max heap - void display_heap(); // Print the elements in the heap - int delete_first_element(); // Remove the first element and return it - int get_left_child(int); // Returns the left child of a parent - int get_right_child(int); // Returns the right child of a parent - int get_parent(int); // Returns the value of parent index - int get_max(); // Returns the maximum element in the heap - void replace(int, int); // Replaces the key value at an index - void siftUp(int); // To re-convert the changed heap into max heap -}; -// Here we assume that the heap can have a maximum size of 50 -heap::heap() { - count = 0; -} - -bool heap::isFull() { - return count == 50; -} - -bool heap::isEmpty() { - return count == 0; -} - -void heap::insert(int val) { - if(!isFull()) { - arr[count++] = val; - siftUp(count-1); - } -} - -int heap::getSize() { - return count+1; -} - -// This program demonstrates the logic to build max_heaps -// To build min_heaps simply change the following lines -// Line 54: arr[maxindex] > arr[leftchild] -// Line 62: arr[maxindex] > arr[rightchild] -void heap::heapify(int index) { - int parent = index; - int leftchild = 2*index+1; - int rightchild = 2*index+2; - int maxindex = parent; - if(leftchild < count) { - if(arr[maxindex] < arr[leftchild]) { - maxindex = leftchild; - } - } - if(rightchild < count) { - if(arr[maxindex] < arr[rightchild]) { - maxindex = rightchild; - } - } - if(maxindex != index) { - int temp = arr[maxindex]; - arr[maxindex] = arr[index]; - arr[index] = temp; - heapify(maxindex); - } -} - -void heap::build_max_heap() { - for(int i = count/2; i >= 0; i--) { - heapify(i); - } -} - -void heap::display_heap() { - for(int i = 0; i < count; i++) { - cout << arr[i] << " "; - } - cout << "\n"; -} - -// This also returns the largest element in the heap -int heap::delete_first_element() { - if(isEmpty()) { - return -1; - } else { - int temp = arr[0]; - arr[0] = arr[count-1]; - arr[count-1] = temp; - heapify(0); - count--; - return arr[count]; - } -} - -int heap::get_left_child(int i) { - if(2*i+1 < count) { - return arr[2*i+1]; - } else { - return -1; - } -} - -int heap::get_right_child(int i) { - if(2*i+2 < count) { - return arr[2*i+2]; - } else { - return -1; - } -} - -int heap::get_parent(int i) { - if(i < count) { - return arr[i]; - } else { - return -1; - } -} - -int heap::get_max() { - if(isEmpty()) { - return -1; - } else { - return arr[0]; - } -} - -void heap::replace(int value, int index) { - if(index < count) { - arr[index] = value; - siftUp(index); - } -} - -void heap::siftUp(int index) { - while(index != 0) { - index = (index-1)/2; // To get the parent of a child - heapify(index); - } -} - -// Driver method -int main() { - heap hp; - hp.insert(4); - hp.insert(2); - hp.insert(6); - hp.insert(7); - hp.insert(4); - hp.insert(9); - hp.insert(1); - hp.insert(5); - hp.insert(19); - hp.insert(5); - hp.insert(7); - hp.build_max_heap(); - hp.display_heap(); - cout << hp.delete_first_element() << "\n"; - hp.display_heap(); - cout << hp.get_max() << "\n"; - cout << "Parent" << hp.get_parent(2) << "\n"; - cout << "Left" << hp.get_left_child(2) << "\n"; - cout << "Right" << hp.get_right_child(2) << "\n"; - hp.replace(20, 9); - hp.display_heap(); -} diff --git a/Data Structures/Linked List/Circular Linked List/CircularLinkedList.cpp b/Data Structures/Linked List/Circular Linked List/CircularLinkedList.cpp deleted file mode 100644 index b236b9c..0000000 --- a/Data Structures/Linked List/Circular Linked List/CircularLinkedList.cpp +++ /dev/null @@ -1,136 +0,0 @@ -#include -#include - -struct circular -{ - int i; - struct circular *next; -}; - - -struct circular *temp; -struct circular *head; -struct circular *p; -struct circular *mid; -struct circular *move; - -int cnt=0; - - -void create(void); -void insert(void); -void display(void); -void del(void); - -void main() -{ - int ch=0; - clrscr(); - while(ch!=5) - { - printf("\n1.CREATE"); - printf("\n2.INSERT"); - printf("\n3.DELETE"); - printf("\n4.DISPLAY"); - printf("\n5.EXIT"); - scanf("%d",&ch); - - - if(ch==1) - { - create(); - cnt++; - cnt++; - } - - if(ch==2) - { - insert(); - cnt++; - } - if(ch==3) - { - del(); - cnt--; - } - - if(ch==4) - { - display(); - } - - if(ch==5) - { - break; - } - } - getch(); -} -void create() -{ - head=(struct circular *)malloc(sizeof(struct circular)); - head->next=head; - printf("ENETER THE DATA"); - scanf("%d",&head->i); - temp=head; - - temp->next=(struct circular *)malloc(sizeof(struct circular)); - temp=temp->next; - temp->next=head; - printf("ENETER THE DATA"); - scanf("%d",&temp->i); - -} -void insert() -{ - int add,t; - - printf("\n\t ENTER ANY NUMBER BETWEEN 1 AND %d",cnt); - scanf("%d",&add); - p=head; - t=1; - while(tnext; - t++; - } - printf("%d",p->i); - clrscr(); - mid=(struct circular *)malloc(sizeof(struct circular)); - printf("ENETER THE DATA"); - scanf("%d",&mid->i); - mid->next=p->next; - p->next=mid; -} - -void display() -{ - p=head; - printf("%d-->",p->i); - p=p->next; - while(p!=head) - { - printf("%d-->",p->i); - p=p->next; - } -} - -void del(void) -{ - int add,t; - - printf("\n\t ENTER ANY NUMBER BETWEEN 1 AND %d",cnt); - scanf("%d",&add); - p=head; - t=1; - while(tnext; - t++; - } - printf("%d",p->i); - clrscr(); - mid=p->next; - p->next=mid->next; - -} diff --git a/Data Structures/Linked List/Doubley Linked List/DoublyLinkedList.cpp b/Data Structures/Linked List/Doubley Linked List/DoublyLinkedList.cpp deleted file mode 100644 index eb1ff6d..0000000 --- a/Data Structures/Linked List/Doubley Linked List/DoublyLinkedList.cpp +++ /dev/null @@ -1,112 +0,0 @@ -#include -#include - -struct dnode{ - int data; - struct dnode *prev; - struct dnode *next; -}; -struct dnode *start=NULL; -void insert(){ -int ch; -struct dnode *p=start,*temp; -int item; -printf("Please enter your choice:\n1>Insert End\n2>Insert Value\n3>Insert Beg\n:"); -scanf("%d",&ch); -switch(ch){ - case 1:printf("Please enter the item to be inserted:"); - scanf("%d",&item); - while(p->next!=NULL) - p=p->next; - temp=(struct dnode*)malloc(sizeof(struct dnode)); - temp->data=item; - temp->prev=p; - temp->next=NULL; - break; - case 2:int loc,i; - printf("Please enter the item to be inserted:"); - scanf("%d",&item); - printf("Please enter the location at which the item is to be inserted:"); - scanf("%d",&loc); - for(i=0;inext); - if(p!=NULL){ - temp=(struct dnode*)malloc(sizeof(struct dnode)); - temp->data=item; - temp->prev=p; - temp->next=p->next; - if(p->next!=NULL){ - temp->next->prev=temp; - - } - p->next=temp; - } - break; - case 3:printf("Please enter the item to be inserted:"); - scanf("%d",&item); - temp=(struct dnode *)malloc(sizeof(struct dnode)); - temp->data=item; - temp->prev=NULL; - temp->next=p; - start=temp; - break; - } -} -void delete_node(){ - int item; - struct dnode *p=start; - printf("Please enter the data item to be deleted:"); - scanf("%d",&item); - while(p->data!=item && p->next!=NULL){ - p=p->next; - } - if(p->data==item){ - if(p->next==NULL){ - p->prev->next=NULL; - } - else{ - p->prev->next=p->next; - } - if(p->prev==NULL){ - p->next->prev=NULL; - } - else{ - p->next->prev=p->prev; - } - - free(p);} - else{ - printf("No such Data Found!"); - } -} -void display() -{ - struct dnode *p=start; - while(p!=NULL){ - printf("%d\n",p->data); - p=p->next; - } -} -void create(){ - int item; - printf("Please enter the initial element:"); - scanf("%d",&item); - start=(struct dnode*)malloc(sizeof(struct dnode)); - start->data=item; - start->next=NULL; - start->prev=NULL; -} -main(){ - create(); - while(1){ - int ch; - printf("Please enter your choice:\n1>insert\n2>delete\n3>display\n4>EXIT\n:"); - scanf("%d",&ch); - switch(ch){ - case 1:insert();break; - case 2:delete_node();break; - case 3:display;break; - case 4:exit(0); - default:printf("Wrong Argument!"); - } - } -} diff --git a/Data Structures/Linked List/Linear Linked List/Deletion.c b/Data Structures/Linked List/Linear Linked List/Deletion.c deleted file mode 100644 index f12a142..0000000 --- a/Data Structures/Linked List/Linear Linked List/Deletion.c +++ /dev/null @@ -1,181 +0,0 @@ -#include -#include -#include -int item; -void insert_end(); -void delete_by_location(); -void delete_by_item(); -void display(void); -struct node -{ - int data; - struct node *next; -}; -struct node *start; -struct node *tail = NULL; -void main() -{ - int choice; - printf("PUSH ELEMENTS ONE BY ONE BEFORE DELETING INTO THE LINKED LIST:"); - int will; - while(will) - { - insert_end(); - printf("ENTER 1 TO CONTINUE INSERTING AND 0 TO STOP:"); - scanf("%d",&will); - } - while (1) - { - printf("\n LINKED LIST: \n 1. DELETE BY LOCATION\n 2. DELETE BY VALUE\n 3. DISPLAY\n 4. EXIT\n\n"); - printf("\nENTER YOUR CHOICE:\n"); - scanf("%d", &choice); - switch (choice) - { - case 1: - delete_by_location(); - break; - case 2: - delete_by_item(); - break; - case 3: - display(); - break; - case 4: - exit(0); - break; - default: - printf("\n YOU HAVE ENTERED A WRONG CHOICE\n"); - } - } - -} -void insert_end() -{ - struct node *p = start, *temp; - - temp = (struct node *)malloc(sizeof(struct node)); - printf("\n ENTER ITEM:\n"); - scanf("%d", &item); - temp->data = item; - if (start == NULL) - { - start = temp; - temp->next = NULL; - } - else - { - while (p->next != NULL) - { - p = p->next; - } - p->next = temp; - temp->next = NULL; - } -} -void delete_by_location() -{ - struct node *p = start, *old = start, *temp; - int loc, i; - if (start==NULL) - { - printf("NOTHING TO DELETE"); - return; - } - printf("\nENTER LOCATION:\n"); - scanf("%d", &loc); - for (i = 1; i < loc; i++) - { - p = p->next; - } - - if (p == NULL) - { - printf("LOCATION NOT FOUND\n"); - free(p); - return; - } - if (p == start) - { - start = start->next; - free(p); - } - else if (p->next == NULL) - { - for (i = 1; i < loc - 1; i++) - { - old = old->next; - } - old->next = NULL; - free(p); - } - - else - { - for (i = 1; i < loc - 1; i++) - { - old = old->next; - } - old->next = p->next; - free(p); - } -} -void delete_by_item() -{ - int value; - struct node *p = start, *old = start, *temp; - if (start == NULL) - { - printf("NOTHING TO DELETE\n"); - return; - } - printf("\nENTER DATA OF A NODE WHICH YOU WISH TO DELETE:\n"); - scanf("%d", &value); - while (p->data != value) - { - p = p->next; - if (p==NULL) - { - printf("VALUE ENTERED IS NOT FOUND"); - free(p); - return; - } - } - - if (p == start) - { - start = start->next; - free(p); - } - else if (p->next == NULL) - { - while (old->next->data != value) - { - old = old->next; - } - old->next = NULL; - free(p); - } - - - else - { - while (old->next->data != value) - { - old = old->next; - } - old->next = p->next; - free(p); - } -} -void display() -{ - struct node *p = start; - printf("\n YOUR LINKED LIST LOOKS LIKE :\n\n"); - printf("\n|_START"); - while (p != NULL) - { - printf(" |_%d_|_|->", p->data); - p = p->next; - } - printf("[NULL]\n"); -} diff --git a/Data Structures/Linked List/Linear Linked List/Insertion.c b/Data Structures/Linked List/Linear Linked List/Insertion.c deleted file mode 100644 index 1d034a7..0000000 --- a/Data Structures/Linked List/Linear Linked List/Insertion.c +++ /dev/null @@ -1,156 +0,0 @@ -#include -#include -#include -int item; -void insert_beginning(void); -void insert_end(void); -void insert_location(); -void insert_after_value(); -void display(void); -struct node -{ - int data; - struct node* next; - -}; -struct node *start; -struct node*tail=NULL; -void main() -{ - int choice; - while(1) - { - printf ("\n LINKED LIST: \n 1. INSERT AT THE BEGINNING\n 2. INSERT AT THE END\n 3. INSERT AT A GIVEN LOCATION\n 4. INSERT AFTER A GIVEN VALUE\n 5. DISPLAY\n 6. EXIT\n\n"); - printf ("\nENTER YOUR CHOICE:\n"); - scanf("%d",&choice); - switch(choice) - { - case 1:insert_beginning(); - break; - case 2:insert_end(); - break; - case 3:insert_location(); - break; - case 4:insert_after_value(); - break; - case 5:display(); - break; - case 6:exit(0); - break; - default: printf("\n YOU HAVE ENTERED A WRONG CHOICE\n"); - } - } -} -void insert_beginning() -{ - struct node *p= start,*temp; - temp=(struct node*)malloc(sizeof(struct node)); - printf("\n ENTER ITEM:\n"); - scanf("%d",&item); - temp->data= item; - temp->next= start; - start=temp; -} -void insert_end() -{ - struct node *p= start, *temp; - - temp=(struct node*)malloc(sizeof(struct node)); - printf("\n ENTER ITEM:\n"); - scanf("%d",&item); - temp->data=item; - if (start == NULL) - { - start=temp; - temp->next = NULL; - } - else - { - while(p->next!=NULL) - { - p=p->next; - } - p->next=temp; - temp->next=NULL; - } -} -void insert_location() -{ - struct node *p=start, *temp; - int loc,i; - printf("\nENTER LOCATION\n "); - scanf("%d",&loc); - temp=(struct node*)malloc(sizeof(struct node)); - printf("\n ENTER ITEM:\n"); - scanf("%d",&item); - temp->data= item; - if (loc==1) - { - temp->next=p; - start=temp; - } - else - { - - for(i=1;inext; - - if(p==NULL) - { - printf("NO SUCH LOCATION\n"); - free(p); - return; - } - } - - struct node *location=p->next; - p->next=temp; - temp->next=location; - } - -} -void insert_after_value() -{ - int value; - struct node *p=start, *temp; - printf("\nENTER DATA OF A NODE AFTER WHICH YOU WISH TO SEE ITEM:\n"); - scanf("%d",&value); - while(p!=NULL) - { - if(p->data==value) - { - temp=(struct node*)malloc(sizeof(struct node)); - printf("\n ENTER ITEM:\n"); - scanf("%d",&item); - temp->data= item; - temp->next=p->next; - p->next=temp; - break; - } - else if(p->next==NULL && p->data!=value) - { - printf("NO SUCH VALUE"); - return; - } - p=p->next; - } - if (p==start && p==NULL) - { - printf("This Action Can Not be performed as there is no element in the linked list"); - return; - } -} -void display() -{ - struct node* p= start; - printf("\n YOUR LINKED LIST LOOKS LIKE :\n\n"); - printf("\n|_HEAD"); - while(p!=NULL) - { - printf(" |_%d_|_|->",p->data); - p=p->next; - } - printf("[NULL]\n"); -} - diff --git a/Data Structures/Linked List/Linear Linked List/LinearLinkedList.cpp b/Data Structures/Linked List/Linear Linked List/LinearLinkedList.cpp deleted file mode 100644 index c1c3110..0000000 --- a/Data Structures/Linked List/Linear Linked List/LinearLinkedList.cpp +++ /dev/null @@ -1,143 +0,0 @@ -#include -#include -struct node{ - int data; - struct node *next; -}; - -struct node *start=(struct node*)malloc(sizeof(struct node)); -int flag=1; -void insert_end(){ - struct node *p=start,*temp; - int item; - printf("Please enter the data item to be inserted:"); - scanf("%d",&item); - while(p->next!=NULL){ - p=p->next; - } - temp=(struct node*)malloc(sizeof(struct node)); - temp->data=item; - p->next=temp; - temp->next=NULL; -} -void create(){ - int i,node,item; - printf("Please enter the no. of node:"); - scanf("%d",&node); - printf("Please enter the data item to be inserted:"); - scanf("%d",&item); - start->data=item; - start->next=NULL; - for(i=0;inext; - if(loc=i+1){ - temp=(struct node *)malloc(sizeof(struct node)); - temp->data=item; - temp->next=p->next; - p->next=temp; - - } - else{ - printf("Location is not present in the List!"); - } -} -void insert_bet_val(){ - struct node *p=start,*temp; - int val,item; - printf("The value to be inserted:"); - scanf("%d",&item); - printf("The value after which to be inserted:"); - scanf("%d",&val); - while(p->data!=val && p->next!=NULL) - p=p->next; - if(p->data==val){ - temp=(struct node*)malloc(sizeof(struct node)); - temp->data=item; - temp->next=p->next; - p->next=temp->next; - } - else{ - printf("Value not found in the list!"); - - } -} - -void delete_item(){ - int ch; - struct node *p=start; - printf("Please enter you choice:\n1>delete at beginning.\n2>delete after value.\n3>delete at end\n:"); - scanf("%d",&ch); - switch(ch){ - case 1:start=p->next; - free(p); - break; - case 2:int item; - printf("The value after which deletion occurs:"); - scanf("%d",&item); - - while(p->data!=item && p->next!=NULL) - p=p->next; - if(p->data==item){ - p->next=p->next->next; - } - else{ - printf("No such value found!"); - } - break; - case 3:while(p->next->next!=NULL){ - p=p->next; - } - p->next=NULL; - break; - default:printf("Wrong Choice!"); - - } -} -void search(){ - int item,i; - struct node *p=start; - printf("Please enter the item to be seached:"); - scanf("%d",&item); - for(i=0;p!=NULL;i++){ - if(p->data==item){ - printf("%d found at %d",item,i); - return; - } - } - printf("No Such Element Found!"); -} -void sort(){ - struct node *i=start,*j; - while(i!=NULL){ - j=i->next; - while(j!=NULL){ - if(i->data>j->data){ - int tem=i->data; - i->data=j->data; - j->data=tem; - } - } - i=i->next; - } -} - - -main(){ - int ch; - printf("Please enter your choice:"); - scanf("%d",&ch); - while(1){ - - } -} diff --git a/Data Structures/Linked List/Linear Linked List/LinearLinkedList.exe b/Data Structures/Linked List/Linear Linked List/LinearLinkedList.exe deleted file mode 100644 index ada6e74..0000000 Binary files a/Data Structures/Linked List/Linear Linked List/LinearLinkedList.exe and /dev/null differ diff --git a/Data Structures/Linked List/Polynomial addition/polyadd.cpp b/Data Structures/Linked List/Polynomial addition/polyadd.cpp deleted file mode 100644 index fabef40..0000000 --- a/Data Structures/Linked List/Polynomial addition/polyadd.cpp +++ /dev/null @@ -1,127 +0,0 @@ -#include -#include - -struct term{ - int coef; - int pow; - struct term *next; -}; -void insert_end(struct term *start){ - struct term *p=start,*temp; - int co,po; - printf("Please enter coefficient to be inserted:"); - scanf("%d",&co); - printf("Please enter power of the coefficient:"); - scanf("%d",&po); - while(p->next!=NULL){ - p=p->next; - } - temp=(struct term*)malloc(sizeof(struct term)); - temp->coef=co; - temp->pow=po; - p->next=temp; - temp->next=NULL; - -} -void sort(struct term *start){ - struct term *i=start,*j; - - while(i!=NULL){ - - j=i->next; - - while(j!=NULL){ - if(i->powpow){ - int tem1=i->pow; - int tem2=i->coef; - i->coef=j->coef; - i->pow=j->pow; - j->coef=tem2; - j->pow=tem1; - } - j=j->next; - } - i=i->next; - } -} -struct term* add(struct term *start1,struct term *start2){ - struct term *start3=(struct term*)malloc(sizeof(struct term)),*p1=start1,*p2=start2,*p3=start3,*temp; - while(p1!=NULL){ - temp=(struct term*)malloc(sizeof(struct term)); - temp->coef=p1->coef; - temp->pow=p1->pow; - temp->next=NULL; - p3->next=temp; - p3=p3->next; - p1=p1->next; - } - while(p2!=NULL){ - temp=(struct term*)malloc(sizeof(struct term)); - temp->coef=p2->coef; - temp->pow=p2->pow; - temp->next=NULL; - p3->next=temp; - p3=p3->next; - p2=p2->next; - } - start3=start3->next; - sort(start3); - p3=start3; - while(p3!=NULL){ - if(p3->next->pow==p3->pow){ - p3->coef=p3->coef+p3->next->coef; - p3->next=p3->next->next; - } - - p3=p3->next; - } - return start3; -} -//displays the polynomials -void display(struct term *start){ - struct term *p=start; - while(p!=NULL){ - - printf("%d x^%d ",p->coef,p->pow); - p=p->next; - } - printf("\n"); -} -//Creates the Polynomials Linked List -void createStarts(struct term *start){ - - int i,node,co,po; - printf("Please enter the no. of terms in the polynomial:"); - scanf("%d",&node); - if(node==0){ - printf("\nThere must be atleast 1 term!"); - exit(1); - } - printf("Please enter coefficient to be inserted:"); - scanf("%d",&co); - printf("Please enter power of the coefficient:"); - scanf("%d",&po); - start->coef=co; - start->pow=po; - start->next=NULL; - for(i=0;i -#include -#define MAXSIZE 100 -int queue[MAXSIZE],front=-1,rear=-1,f=0; -int size; -void qInsert(){ - if((front==0 && rear==size) || front==rear+1){ - printf("\nCIRCULAR QUEUE Overflow!"); - return; - } - if(front==-1 && rear==-1) - { - front=0; - rear=0; - } - else if(front!=0 && rear==size) - rear=0; - else - rear++; - - printf("\nPlease enter the item to be inserted:"); - scanf("%d",&queue[rear]); - - -} -void qDelete(){ - int item; - if(front==-1){ - printf("CIRCULAR QUEUE Underflow!"); - return; - } - item=queue[front]; - if(front==rear) - { - front=-1; - rear=-1; - } - if(front==size) - front=0; - else - front++; - printf("%d has been deleted from Queue!\n",item); -} - -void qView(){ - if(front==-1){ - printf("\nCIRCULAR QUEUE Underflow!"); - } - if(front<=rear){ - int i; - printf("\nCIRCULAR QUEUE1 is:\n"); - for (i=front;i<=rear;i++){ - printf("%d\n",queue[i]); - } - } - else{ - int i; - printf("%d %d",front,rear); - printf("\nCIRCULAR QUEUE2 is:\n"); - for(i=front;iINSERT\n2>DELETE\n3>VIEW\n4>Search\n5>EXIT\n:"); - scanf("%d",&ch); - switch(ch){ - case 1:qInsert();break; - case 2:qDelete();break; - case 3:qView();break; - case 4:break; - case 5:exit(0); - default:printf("Wrong Choice!"); - } - - - } - -} - diff --git a/Data Structures/Queue/Circular Q/main.o b/Data Structures/Queue/Circular Q/main.o deleted file mode 100644 index cae6097..0000000 Binary files a/Data Structures/Queue/Circular Q/main.o and /dev/null differ diff --git a/Data Structures/Queue/Circular Q/main1.c b/Data Structures/Queue/Circular Q/main1.c deleted file mode 100644 index dfb7665..0000000 --- a/Data Structures/Queue/Circular Q/main1.c +++ /dev/null @@ -1,102 +0,0 @@ -#include -#include -#define MAXSIZE 100 -int queue[MAXSIZE],front=-1,rear=-1,f=0; -int size; -void qInsert(){ - if((front==0 && rear==size) || front==rear+1){ - printf("\nCIRCULAR QUEUE Overflow!"); - return; - } - if(front==-1 && rear==-1) - { - front=0; - rear=0; - } - else if(front!=0 && rear==size) - rear=0; - else - rear++; - - printf("\nPlease enter the item to be inserted:"); - scanf("%d",&queue[rear]); - - -} -void qDelete(){ - int item; - if(front==-1){ - printf("CIRCULAR QUEUE Underflow!"); - return; - } - item=queue[front]; - if(front==rear) - { - front=-1; - rear=-1; - } - if(front==size) - front=0; - else - front++; - printf("%d has been deleted from Queue!\n",item); -} - -void qView(){ - if(front==-1){ - printf("\nCIRCULAR QUEUE Underflow!"); - } - if(front<=rear){ - int i; - printf("\nCIRCULAR QUEUE1 is:\n"); - for (i=front;i<=rear;i++){ - printf("%d\n",queue[i]); - } - } - else{ - int i; - printf("%d %d",front,rear); - printf("\nCIRCULAR QUEUE2 is:\n"); - for(i=front;iINSERT\n2>DELETE\n3>VIEW\n4>Search\n5>EXIT\n:"); - scanf("%d",&ch); - switch(ch){ - case 1:qInsert();break; - case 2:qDelete();break; - case 3:qView();break; - case 4:break; - case 5:exit(0); - default:printf("Wrong Choice!"); - } - - - } - -} - diff --git a/Data Structures/Queue/Circular Q/main1.exe b/Data Structures/Queue/Circular Q/main1.exe deleted file mode 100644 index 479bd90..0000000 Binary files a/Data Structures/Queue/Circular Q/main1.exe and /dev/null differ diff --git a/Data Structures/Queue/Circular Q/main1.o b/Data Structures/Queue/Circular Q/main1.o deleted file mode 100644 index 94459bb..0000000 Binary files a/Data Structures/Queue/Circular Q/main1.o and /dev/null differ diff --git a/Data Structures/Queue/Double ended Q/Double ended Q.dev b/Data Structures/Queue/Double ended Q/Double ended Q.dev deleted file mode 100644 index 1f526d5..0000000 --- a/Data Structures/Queue/Double ended Q/Double ended Q.dev +++ /dev/null @@ -1,62 +0,0 @@ -[Project] -FileName=Double ended Q.dev -Name=Project1 -Type=1 -Ver=2 -ObjFiles= -Includes= -Libs= -PrivateResource= -ResourceIncludes= -MakeIncludes= -Compiler= -CppCompiler= -Linker= -IsCpp=0 -Icon= -ExeOutput= -ObjectOutput= -LogOutput= -LogOutputEnabled=0 -OverrideOutput=0 -OverrideOutputName= -HostApplication= -UseCustomMakefile=0 -CustomMakefile= -CommandLine= -Folders= -IncludeVersionInfo=0 -SupportXPThemes=0 -CompilerSet=0 -CompilerSettings=0000000000000000000000000 -UnitCount=1 - -[VersionInfo] -Major=1 -Minor=0 -Release=0 -Build=0 -LanguageID=1033 -CharsetID=1252 -CompanyName= -FileVersion= -FileDescription=Developed using the Dev-C++ IDE -InternalName= -LegalCopyright= -LegalTrademarks= -OriginalFilename= -ProductName= -ProductVersion= -AutoIncBuildNr=0 -SyncProduct=1 - -[Unit1] -FileName=main.c -CompileCpp=0 -Folder= -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - diff --git a/Data Structures/Queue/Double ended Q/Double ended Q.layout b/Data Structures/Queue/Double ended Q/Double ended Q.layout deleted file mode 100644 index 8ac3c6c..0000000 --- a/Data Structures/Queue/Double ended Q/Double ended Q.layout +++ /dev/null @@ -1,8 +0,0 @@ -[Editors] -Order=0 -Focused=0 -[Editor_0] -CursorCol=2 -CursorRow=167 -TopLine=58 -LeftChar=1 diff --git a/Data Structures/Queue/Double ended Q/deque.cpp b/Data Structures/Queue/Double ended Q/deque.cpp deleted file mode 100644 index 35088db..0000000 --- a/Data Structures/Queue/Double ended Q/deque.cpp +++ /dev/null @@ -1,223 +0,0 @@ -#include -using namespace std ; -#define MAX 10 - -int deque[MAX]; -int leftt =-1 ; -int rightt = -1 ; - -void inputdeque(void); -void outputdeque(void); -void insertleft(void); -void insertright(void); -void deleteleft(void); -void deleteright(void); -void display(void); - -int main( ) -{ - int option; - cout<<"\n *****MAIN MENU*****"; - cout<<"\n 1.Input restricted deque"; - cout<<"\n 2.Output restricted deque"; - cout<<"\n Enter your option : "; - cin>>option; - - switch (option) - { - case 1: inputdeque(); - break; - case 2: outputdeque(); - break; - } return 0; -} - -void inputdeque( ) -{ - int option; - do - { - cout<<"\n\n INPUT RESTRICTED DEQUE"; - cout<<"\n 1.Insert at right"; - cout<<"\n 2.Delete from left"; - cout<<"\n 3.Delete from right"; - cout<<"\n 4.Display"; - cout<<"\n 5.Quit"; - cout<<"\n Enter your option : "; - - cin>>option ; - switch (option) - { - case 1: insertright(); - break; - case 2: deleteleft(); - break; - case 3: deleteright(); - break; - case 4: display(); - break; - } - - }while (option!=5); -} - -void outputdeque( ) -{ - int option; - do - { - cout<<"\n\n OUTPUT RESTRICTED DEQUE"; - cout<<"\n 1.Insert at right"; - cout<<"\n 2.Insert at left"; - cout<<"\n 3.Delete from left"; - cout<<"\n 4.Display"; - cout<<"\n 5.Quit"; - cout<<"\n Enter your option : "; - - cin>>option ; - switch(option) - { - case 1: insertright(); - break; - case 2: insertleft(); - break; - case 3: deleteleft(); - break; - case 4: display(); - break; - } - }while (option!=5); -} - -void insertright( ) -{ - int val; - cout<<"\n Enter the value to be added:" ; - cin>>val; - if ( (leftt == 0 && rightt == MAX-1 ) || (leftt == rightt+1) ) - { - cout<<"\n OVERFLOW"; - return; - } - if (leftt == -1) // Queue is Empty Inititally - { - leftt = 0; - rightt = 0; - } - else - { - if (rightt == MAX-1) //rightt is at last position of queue - rightt = 0; - else - rightt = rightt+1; - } - deque[rightt] = val ; -} - -void insertleft( ) -{ - int val; - cout<<"\n Enter the value to be added:"; - cin>>val; - - if( (leftt ==0 && rightt == MAX-1) || (leftt == rightt+1) ) - { - cout<<"\n OVERFLOW"; - return; - } - if (leftt == -1) //If queue is initially empty - { - leftt = 0; - rightt = 0; - } - else - { - if(leftt == 0) - leftt = MAX - 1 ; - else - leftt = leftt - 1 ; - } - deque[leftt] = val; -} - -void deleteleft( ) -{ - if ( leftt == -1 ) - { - cout<<"\n UNDERFLOW"; - return ; - } - - cout<<"\n The deleted element is : "<< deque[leftt]; - - if (leftt == rightt) /*Queue has only one element */ - { - leftt = -1 ; - rightt = -1 ; - } - else - { - if ( leftt == MAX - 1 ) - leftt = 0; - else - leftt = leftt+1; - } -} - -void deleteright() -{ - if ( leftt == -1 ) - { - cout<<"\n UNDERFLOW"; - return ; - } - - cout<<"\n The element deleted is : "<< deque[rightt]; - - if (leftt == rightt) /*queue has only one element*/ - { - leftt = -1 ; - rightt = -1 ; - } - else - { - if (rightt == 0) - rightt = MAX - 1 ; - else - rightt = rightt - 1 ; - } -} - -void display( ) -{ - int front = leftt, rear = rightt; - if ( front == -1 ) - { - cout<<"\n QUEUE IS EMPTY"; - return; - } - cout<<"\n The elements of the queue are : "; - if (front <= rear ) - { - while (front <= rear) - { - cout << deque[front] <<" "; - front++; - } - } - else - { - while (front <= MAX - 1) - { - cout << deque[front] <<" "; - front++; - } - front = 0; - while (front <= rear) - { - cout<< deque[front]<<" "; - front++; - } - } - cout< -#include - -using namespace std; - -void showdq (deque g) -{ - deque :: iterator it; // Iterator to iterate over the deque . - - for (it = g.begin(); it != g.end(); ++it) - cout << '\t' << *it; - - cout << "\n"; -} - -int main () -{ - deque que; - int option , x ; - do - { - - - cout<<"\n\n DEQUEUE USING STL C++ "; - cout<<"\n 1.Insert front"; - cout<<"\n 2.Insert Back"; - cout<<"\n 3.Delete front"; - cout<<"\n 4.Delete Back"; - cout<<"\n 5.Display "; - - cout<<"\n Enter your option : "; - cin>>option; - - switch (option) - { - case 1 : cout<<"\n Enter number : "; - cin>>x; - que.push_front(x); - break; - - case 2 : cout<<"\n Enter number : "; - cin>>x; - que.push_back(x); - break; - - case 3 : que.pop_front(); - break; - - case 4 : que.pop_back(); - break; - case 5 : showdq(que); - break; - } - } while (option!=6); - - return 0; -} - diff --git a/Data Structures/Queue/Double ended Q/main.c b/Data Structures/Queue/Double ended Q/main.c deleted file mode 100644 index 03e0fed..0000000 --- a/Data Structures/Queue/Double ended Q/main.c +++ /dev/null @@ -1,167 +0,0 @@ -#include -#include -#define SIZE 100 - -void enQueue(int); -int deQueueFront(); -int deQueueRear(); -void enQueueRear(int); -void enQueueFront(int); -void display(); - -int queue[SIZE]; -int rear = 0, front = 0; - -int main() -{ - char ch; - int choice1, choice2, value; - printf("\n******* Type of Double Ended Queue *******\n"); - do - { - printf("\n1.Input-restricted deque \n"); - printf("2.output-restricted deque \n"); - printf("\nEnter your choice of Queue Type : "); - scanf("%d",&choice1); - switch(choice1) - { - case 1: - printf("\nSelect the Operation\n"); - printf("1.Insert\n2.Delete from Rear\n3.Delete from Front\n4. Display"); - do - { - printf("\nEnter your choice for the operation in c deque: "); - scanf("%d",&choice2); - switch(choice2) - { - case 1: enQueueRear(value); - display(); - break; - case 2: value = deQueueRear(); - printf("\nThe value deleted is %d",value); - display(); - break; - case 3: value=deQueueFront(); - printf("\nThe value deleted is %d",value); - display(); - break; - case 4: display(); - break; - default:printf("Wrong choice"); - } - printf("\nDo you want to perform another operation (Y/N): "); - ch=getch(); - }while(ch=='y'||ch=='Y'); - getch(); - break; - - case 2 : - printf("\n---- Select the Operation ----\n"); - printf("1. Insert at Rear\n2. Insert at Front\n3. Delete\n4. Display"); - do - { - printf("\nEnter your choice for the operation: "); - scanf("%d",&choice2); - switch(choice2) - { - case 1: enQueueRear(value); - display(); - break; - case 2: enQueueFront(value); - display(); - break; - case 3: value = deQueueFront(); - printf("\nThe value deleted is %d",value); - display(); - break; - case 4: display(); - break; - default:printf("Wrong choice"); - } - printf("\nDo you want to perform another operation (Y/N): "); - ch=getch(); - } while(ch=='y'||ch=='Y'); - getch(); - break ; - } - printf("\nDo you want to continue(y/n):"); - ch=getch(); - }while(ch=='y'||ch=='Y'); -} - -void enQueueRear(int value) -{ - char ch; - if(front == SIZE/2) - { - printf("\nQueue is full!!! Insertion is not possible!!! "); - return; - } - do - { - printf("\nEnter the value to be inserted:"); - scanf("%d",&value); - queue[front] = value; - front++; - printf("Do you want to continue insertion Y/N"); - ch=getch(); - }while(ch=='y'); -} - -void enQueueFront(int value) -{ - char ch; - if(front==SIZE/2) - { - printf("\nQueue is full!!! Insertion is not possible!!!"); - return; - } - do - { - printf("\nEnter the value to be inserted:"); - scanf("%d",&value); - rear--; - queue[rear] = value; - printf("Do you want to continue insertion Y/N"); - ch = getch(); - } - while(ch == 'y'); -} -int deQueueRear() -{ - int deleted; - if(front == rear) - { - printf("\nQueue is Empty!!! Deletion is not possible!!!"); - return 0; - } - front--; - deleted = queue[front+1]; - return deleted; -} -int deQueueFront() -{ - int deleted; - if(front == rear) - { - printf("\nQueue is Empty!!! Deletion is not possible!!!"); - return 0; - } - rear++; - deleted = queue[rear-1]; - return deleted; -} - -void display() -{ - int i; - if(front == rear) - printf("\nQueue is Empty!!! Deletion is not possible!!!") - else{ - printf("\nThe Queue elements are:"); - for(i=rear; i < front; i++) - { - printf("%d\t ",queue[i]); - } - } -} diff --git a/Data Structures/Queue/Linear Q/LQ.dev b/Data Structures/Queue/Linear Q/LQ.dev deleted file mode 100644 index 5e6045b..0000000 --- a/Data Structures/Queue/Linear Q/LQ.dev +++ /dev/null @@ -1,62 +0,0 @@ -[Project] -FileName=LQ.dev -Name=Project2 -Type=1 -Ver=2 -ObjFiles= -Includes= -Libs= -PrivateResource= -ResourceIncludes= -MakeIncludes= -Compiler= -CppCompiler= -Linker= -IsCpp=0 -Icon= -ExeOutput= -ObjectOutput= -LogOutput= -LogOutputEnabled=0 -OverrideOutput=0 -OverrideOutputName= -HostApplication= -UseCustomMakefile=0 -CustomMakefile= -CommandLine= -Folders= -IncludeVersionInfo=0 -SupportXPThemes=0 -CompilerSet=0 -CompilerSettings=0000000000000000000000000 -UnitCount=1 - -[VersionInfo] -Major=1 -Minor=0 -Release=0 -Build=0 -LanguageID=1033 -CharsetID=1252 -CompanyName= -FileVersion= -FileDescription=Developed using the Dev-C++ IDE -InternalName= -LegalCopyright= -LegalTrademarks= -OriginalFilename= -ProductName= -ProductVersion= -AutoIncBuildNr=0 -SyncProduct=1 - -[Unit1] -FileName=main.c -CompileCpp=0 -Folder= -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - diff --git a/Data Structures/Queue/Linear Q/LQ.exe b/Data Structures/Queue/Linear Q/LQ.exe deleted file mode 100644 index 308d5ea..0000000 Binary files a/Data Structures/Queue/Linear Q/LQ.exe and /dev/null differ diff --git a/Data Structures/Queue/Linear Q/LQ.layout b/Data Structures/Queue/Linear Q/LQ.layout deleted file mode 100644 index b1f641d..0000000 --- a/Data Structures/Queue/Linear Q/LQ.layout +++ /dev/null @@ -1,8 +0,0 @@ -[Editors] -Order=0 -Focused=0 -[Editor_0] -CursorCol=17 -CursorRow=36 -TopLine=47 -LeftChar=1 diff --git a/Data Structures/Queue/Linear Q/Makefile.win b/Data Structures/Queue/Linear Q/Makefile.win deleted file mode 100644 index df7c0d1..0000000 --- a/Data Structures/Queue/Linear Q/Makefile.win +++ /dev/null @@ -1,28 +0,0 @@ -# Project: Project2 -# Makefile created by Dev-C++ 5.11 - -CPP = g++.exe -CC = gcc.exe -WINDRES = windres.exe -OBJ = main.o -LINKOBJ = main.o -LIBS = -L"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib" -L"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/lib" -static-libgcc -INCS = -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include" -CXXINCS = -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++" -BIN = LQ.exe -CXXFLAGS = $(CXXINCS) -CFLAGS = $(INCS) -RM = rm.exe -f - -.PHONY: all all-before all-after clean clean-custom - -all: all-before $(BIN) all-after - -clean: clean-custom - ${RM} $(OBJ) $(BIN) - -$(BIN): $(OBJ) - $(CC) $(LINKOBJ) -o $(BIN) $(LIBS) - -main.o: main.c - $(CC) -c main.c -o main.o $(CFLAGS) diff --git a/Data Structures/Queue/Linear Q/main.c b/Data Structures/Queue/Linear Q/main.c deleted file mode 100644 index 606aee6..0000000 --- a/Data Structures/Queue/Linear Q/main.c +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include -#define MAX 5 -int queue[MAX]; -int f=-1,r=-1,item; -void ins(); -void del(); -void display(); -int main() -{ - int ch; - while(1) - { - printf("\n\n~~~~~~~~~~~~~~~~MENU~~~~~~~~~~~~~~~~\n"); - printf("\n\n1.Insert\n2.Delete\n3.Display\n4.Exit\n"); - printf("ENTER A CHOICE:"); - scanf("%d",&ch); - switch(ch) - { - case 1: ins(); - break; - case 2: del(); - break; - case 3: display(); - break; - case 4: exit(0); - break; - - default: printf("WRONG CHOICE!!!\n"); - } - } -} -void ins() -{ - - if(r==MAX-1) - printf("OVERFLOW!\n"); - else{ - - - printf("Enter your number: "); - scanf("%d",&item); - r=r+1; - queue[r]=item; - printf("%d is added to the queue.",item); - } - if(f==-1) - - - { - f=0; - } -} -void del() -{ - if (f==-1) - printf("UNDERFLOW!"); - else{ - item=queue[f]; - printf("%d deleted from the queue.",queue[f]); - } - if(f==r){ - f=r=-1; - } - else{ - f=f+1; - } -} -void display(){ - int i; - if(f==-1) - printf("EMPTY QUEUE\n"); - else - { - for(i=f;i<=r;i++) - printf("%d\t",queue[i]); - } -} - diff --git a/Data Structures/Queue/Linear Q/main.o b/Data Structures/Queue/Linear Q/main.o deleted file mode 100644 index a3a466d..0000000 Binary files a/Data Structures/Queue/Linear Q/main.o and /dev/null differ diff --git a/Data Structures/Queue/Linear Queue/Linear Queue.cbp b/Data Structures/Queue/Linear Queue/Linear Queue.cbp deleted file mode 100644 index 0c6f2b3..0000000 --- a/Data Structures/Queue/Linear Queue/Linear Queue.cbp +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - diff --git a/Data Structures/Queue/Linear Queue/Linear Queue.depend b/Data Structures/Queue/Linear Queue/Linear Queue.depend deleted file mode 100644 index 6da843d..0000000 --- a/Data Structures/Queue/Linear Queue/Linear Queue.depend +++ /dev/null @@ -1,5 +0,0 @@ -# depslib dependency file v1.0 -1534090355 source:d:\btech curriculum\data structure & algorithm through c\queue\linear queue\main.c - - - diff --git a/Data Structures/Queue/Linear Queue/Linear Queue.layout b/Data Structures/Queue/Linear Queue/Linear Queue.layout deleted file mode 100644 index afcbbd5..0000000 --- a/Data Structures/Queue/Linear Queue/Linear Queue.layout +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/Data Structures/Queue/Linear Queue/bin/Debug/Linear Queue.exe b/Data Structures/Queue/Linear Queue/bin/Debug/Linear Queue.exe deleted file mode 100644 index cfb3f62..0000000 Binary files a/Data Structures/Queue/Linear Queue/bin/Debug/Linear Queue.exe and /dev/null differ diff --git a/Data Structures/Queue/Linear Queue/desktop.ini b/Data Structures/Queue/Linear Queue/desktop.ini deleted file mode 100644 index bb9f3d6..0000000 --- a/Data Structures/Queue/Linear Queue/desktop.ini +++ /dev/null @@ -1,4 +0,0 @@ -[ViewState] -Mode= -Vid= -FolderType=Generic diff --git a/Data Structures/Queue/Linear Queue/main.c b/Data Structures/Queue/Linear Queue/main.c deleted file mode 100644 index b83a013..0000000 --- a/Data Structures/Queue/Linear Queue/main.c +++ /dev/null @@ -1,72 +0,0 @@ -#include -#include -#define MAX 5 -int queue[MAX]; -int f=-1,r=-1; -void insert(); -void del(); -void display(); -int main() -{ - int ch; - while(1) - { - printf("\n\n~~~~~~~~~~~~~~~~MENU~~~~~~~~~~~~~~~~\n"); - printf("\n\n1.Insert\n2.Delete\n3.Display\n4.Exit\n"); - printf("ENTER A CHOICE:"); - scanf("%d",&ch); - switch(ch) - { - case 1: insert(); - break; - case 2: del(); - break; - case 3: display(); - break; - case 4: exit(0); - break; - - default: printf("WRONG CHOICE!!!\n"); - } - } -} -void insert() -{ - int item; - if(r==MAX-1) - printf("OVERFLOW!"); - else - - printf("Enter your number: "); - scanf("%d\n",&item); - r=r+1; - queue[r]=item; - printf("%d is added to the queue.",item); - if(f==-1) - { - f=0; - } -} -void del() -{ - if (f==-1) - printf("UNDERFLOW!"); - else{ - printf("%d is deleted from the queue",queue[r]); - r=r-1; -} -} -void display(){ - int i; - if(f==-1) - printf("EMPTY QUEUE\n"); - else - { - for(i=f;i<=r;i++) - printf("%d\t",queue[r]); - } -} - - - - diff --git a/Data Structures/Queue/Linear Queue/main.exe b/Data Structures/Queue/Linear Queue/main.exe deleted file mode 100644 index 21ece27..0000000 Binary files a/Data Structures/Queue/Linear Queue/main.exe and /dev/null differ diff --git a/Data Structures/Queue/Linear Queue/main.o b/Data Structures/Queue/Linear Queue/main.o deleted file mode 100644 index 83de051..0000000 Binary files a/Data Structures/Queue/Linear Queue/main.o and /dev/null differ diff --git a/Data Structures/Queue/Linear Queue/main1.c b/Data Structures/Queue/Linear Queue/main1.c deleted file mode 100644 index 9bd73d2..0000000 --- a/Data Structures/Queue/Linear Queue/main1.c +++ /dev/null @@ -1,72 +0,0 @@ -#include -#include -#define MAX 5 -int queue[MAX]; -int f=-1,r=-1; -void insert(); -void del(); -void display(); -int main() -{ - int ch; - while(1) - { - printf("\n\n~~~~~~~~~~~~~~~~MENU~~~~~~~~~~~~~~~~\n"); - printf("\n\n1.Insert\n2.Delete\n3.Display\n4.Exit\n"); - printf("ENTER A CHOICE:"); - scanf("%d",&ch); - switch(ch) - { - case 1: insert(); - break; - case 2: del(); - break; - case 3: display(); - break; - case 4: exit(0); - break; - - default: printf("WRONG CHOICE!!!\n"); - } - } -} -void insert() -{ - int item; - if(r==MAX-1) - printf("OVERFLOW!"); - else - - printf("Enter your number: "); - scanf("%d\n",&item); - r=r+1; - queue[r]=item; - printf("%d is added to the queue.",item); - if(f==-1) - { - f=0; - } -} -void del() -{ - if (f==-1) - printf("UNDERFLOW!"); - else{ - printf("%d is deleted from the queue",queue[r]); - f=f+1; -} -} -void display(){ - int i; - if(f==-1) - printf("EMPTY QUEUE\n"); - else - { - for(i=f;i<=r;i++) - printf("%d\t",queue[i]); - } -} - - - - diff --git a/Data Structures/Queue/Linear Queue/main1.exe b/Data Structures/Queue/Linear Queue/main1.exe deleted file mode 100644 index f84a2f1..0000000 Binary files a/Data Structures/Queue/Linear Queue/main1.exe and /dev/null differ diff --git a/Data Structures/Queue/Linear Queue/main1.h b/Data Structures/Queue/Linear Queue/main1.h deleted file mode 100644 index e47c6f7..0000000 --- a/Data Structures/Queue/Linear Queue/main1.h +++ /dev/null @@ -1,72 +0,0 @@ -#include -#include -#define MAX 5 -int queue[MAX]; -int f=-1,r=-1,item; -void ins(); -void del(); -void display(); -int main() -{ - int ch; - while(1) - { - printf("\n\n~~~~~~~~~~~~~~~~MENU~~~~~~~~~~~~~~~~\n"); - printf("\n\n1.Insert\n2.Delete\n3.Display\n4.Exit\n"); - printf("ENTER A CHOICE:"); - scanf("%d",&ch); - switch(ch) - { - case 1: ins(); - break; - case 2: del(); - break; - case 3: display(); - break; - case 4: exit(0); - break; - - default: printf("WRONG CHOICE!!!\n"); - } - } -} -void ins() -{ - - if(r==MAX-1) - printf("OVERFLOW!"); - else - - printf("Enter your number: "); - scanf("%d",&item); - r=r+1; - queue[r]=item; - printf("%d is added to the queue.",item); - if(f==-1) - { - f=0; - } -} -void del() -{ - if (f==-1) - printf("UNDERFLOW!"); - else{ - printf("%d is deleted from the queue",queue[r]); - f=f+1; -} -} -void display(){ - int i; - if(f==-1) - printf("EMPTY QUEUE\n"); - else - { - for(i=f;i<=r;i++) - printf("%d\t",queue[i]); - } -} - - - - diff --git a/Data Structures/Queue/Linear Queue/main1.o b/Data Structures/Queue/Linear Queue/main1.o deleted file mode 100644 index a7d5772..0000000 Binary files a/Data Structures/Queue/Linear Queue/main1.o and /dev/null differ diff --git a/Data Structures/Queue/Linear Queue/obj/Debug/main.o b/Data Structures/Queue/Linear Queue/obj/Debug/main.o deleted file mode 100644 index 2834b69..0000000 Binary files a/Data Structures/Queue/Linear Queue/obj/Debug/main.o and /dev/null differ diff --git a/Data Structures/Stack/Evaluation/Evaluation.cpp b/Data Structures/Stack/Evaluation/Evaluation.cpp deleted file mode 100644 index 39d58cc..0000000 --- a/Data Structures/Stack/Evaluation/Evaluation.cpp +++ /dev/null @@ -1,128 +0,0 @@ - - - #include - #include - - - # define MAXSTACK 100 /* for max size of stack */ - # define POSTFIXSIZE 100 /* define max number of charcters in postfix expression */ - - /* declare stack and its top pointer to be used during postfix expression - evaluation*/ - int stack[MAXSTACK]; - int top = -1 ; /* because array index in C begins at 0 */ - /* can be do this initialization somewhere else */ - - /* define push operation */ - void push(int item) - { - - if(top >= MAXSTACK -1) - { - printf("stack over flow"); - return; - } - else - { - top = top + 1 ; - stack[top]= item; - } - } - - /* define pop operation */ - int pop() - { - int item; - if(top <0) - { - printf("stack under flow"); - } - else - { - item = stack[top]; - top = top - 1; - return item; - } - } - - /* define function that is used to input postfix expression and to evaluate it */ - void EvalPostfix(char postfix[]) - { - - int i ; - char ch; - int val; - int A, B ; - - - /* evaluate postfix expression */ - for (i = 0 ; postfix[i] != ')'; i++) - { - ch = postfix[i]; - if (isdigit(ch)) - { - /* we saw an operand,push the digit onto stack - ch - '0' is used for getting digit rather than ASCII code of digit */ - push(ch - '0'); - } - else if (ch == '+' || ch == '-' || ch == '*' || ch == '/') - { - /* we saw an operator - * pop top element A and next-to-top elemnet B - * from stack and compute B operator A - */ - A = pop(); - B = pop(); - - switch (ch) /* ch is an operator */ - { - case '*': - val = B * A; - break; - - case '/': - val = B / A; - break; - - case '+': - val = B + A; - break; - - case '-': - val = B - A; - break; - } - - /* push the value obtained above onto the stack */ - push(val); - } - } - printf( " \n Result of expression evaluation : %d \n", pop()) ; - } - - int main() - { - - int i ; - - /* declare character array to store postfix expression */ - char postfix[POSTFIXSIZE]; - printf("ASSUMPTION: There are only four operators(*, /, +, -) in an expression and operand is single digit only.\n"); - printf( " \nEnter postfix expression,\npress right parenthesis ')' for end expression : "); - - /* take input of postfix expression from user */ - - for (i = 0 ; i <= POSTFIXSIZE - 1 ; i++) - { - scanf("%c", &postfix[i]); - - if ( postfix[i] == ')' ) /* is there any way to eliminate this if */ - { break; } /* and break statement */ - } - - /* call function to evaluate postfix expression */ - - EvalPostfix(postfix); - - return 0; - } diff --git a/Data Structures/Stack/Evaluation/valuation.exe b/Data Structures/Stack/Evaluation/valuation.exe deleted file mode 100644 index cef84e6..0000000 Binary files a/Data Structures/Stack/Evaluation/valuation.exe and /dev/null differ diff --git a/Data Structures/Stack/Infix to prefix/Correct.cpp b/Data Structures/Stack/Infix to prefix/Correct.cpp deleted file mode 100644 index 11bd325..0000000 --- a/Data Structures/Stack/Infix to prefix/Correct.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include -#include -char stack[20]; -int top = -1; -void push(char x) -{ - stack[++top] = x; -} - -char pop() -{ - if(top == -1) - return -1; - else - return stack[top--]; -} - -int priority(char x) -{ - if(x == '(') - return 0; - if(x == '+' || x == '-') - return 1; - if(x == '*' || x == '/') - return 2; - if(x == '^') - return 3; -} - -main() -{ - char exp[20]; - char *e, x; - printf("Enter the expression :: "); - scanf("%s",exp); - e = exp; - while(*e != '\0') - { - if(isalnum(*e)) - printf("%c",*e); - else if(*e == '(') - push(*e); - else if(*e == ')') - { - while((x = pop()) != '(') - printf("%c", x); - } - else - { - while(priority(stack[top]) >= priority(*e)) - printf("%c",pop()); - push(*e); - } - e++; - } - while(top != -1) - { - printf("%c",pop()); - } -} diff --git a/Data Structures/Stack/Infix to prefix/Infix to prefix2.c b/Data Structures/Stack/Infix to prefix/Infix to prefix2.c deleted file mode 100644 index e907fd2..0000000 --- a/Data Structures/Stack/Infix to prefix/Infix to prefix2.c +++ /dev/null @@ -1,194 +0,0 @@ - - -#include -#include /* for exit() */ -#include /* for isdigit(char ) */ -#include - -#define SIZE 100 - - -/* declared here as global variable because stack[] -* is used by more than one fucntions */ -char stack[SIZE]; -int top = -1; - -/* define push operation */ - -void push(char item) -{ - if(top >= SIZE-1) - { - printf("\nStack Overflow."); - } - else - { - top = top+1; - stack[top] = item; - } -} - -/* define pop operation */ -char pop() -{ - char item ; - - if(top <0) - { - printf("stack under flow: invalid infix expression"); - getchar(); - /* underflow may occur for invalid expression */ - /* where ( and ) are not matched */ - exit(1); - } - else - { - item = stack[top]; - top = top-1; - return(item); - } -} - -/* define function that is used to determine whether any symbol is operator or not -(that is symbol is operand) -* this fucntion returns 1 if symbol is opreator else return 0 */ - -int is_operator(char symbol) -{ - if(symbol == '^' || symbol == '*' || symbol == '/' || symbol == '+' || symbol =='-') - { - return 1; - } - else - { - return 0; - } -} - -/* define fucntion that is used to assign precendence to operator. -* Here ^ denotes exponent operator. -* In this fucntion we assume that higher integer value -* means higher precendence */ - -int precedence(char symbol) -{ - if(symbol == '^')/* exponent operator, highest precedence*/ - { - return(3); - } - else if(symbol == '*' || symbol == '/') - { - return(2); - } - else if(symbol == '+' || symbol == '-') /* lowest precedence */ - { - return(1); - } - else - { - return(0); - } -} - -void InfixToPostfix(char infix_exp[], char postfix_exp[]) -{ - int i, j; - char item; - char x; - - push('('); /* push '(' onto stack */ - strcat(infix_exp,")"); /* add ')' to infix expression */ - - i=0; - j=0; - item=infix_exp[i]; /* initialize before loop*/ - - while(item != '\0') /* run loop till end of infix expression */ - { - if(item == '(') - { - push(item); - } - else if( isdigit(item) || isalpha(item)) - { - postfix_exp[j] = item; /* add operand symbol to postfix expr */ - j++; - } - else if(is_operator(item) == 1) /* means symbol is operator */ - { - x=pop(); - while(is_operator(x) == 1 && precedence(x)>= precedence(item)) - { - postfix_exp[j] = x; /* so pop all higher precendence operator and */ - j++; - x = pop(); /* add them to postfix expresion */ - } - push(x); - /* because just above while loop will terminate we have - oppped one extra item - for which condition fails and loop terminates, so that one*/ - - push(item); /* push current oprerator symbol onto stack */ - } - else if(item == ')') /* if current symbol is ')' then */ - { - x = pop(); /* pop and keep popping until */ - while(x != '(') /* '(' encounterd */ - { - postfix_exp[j] = x; - j++; - x = pop(); - } - } - else - { /* if current symbol is neither operand not '(' nor ')' and nor - operator */ - printf("\nInvalid infix Expression.\n"); /* the it is illegeal symbol */ - getchar(); - exit(1); - } - i++; - - - item = infix_exp[i]; /* go to next symbol of infix expression */ - } /* while loop ends here */ - if(top>0) - { - printf("\nInvalid infix Expression.\n"); /* the it is illegeal symbol */ - getchar(); - exit(1); - } - if(top>0) - { - printf("\nInvalid infix Expression.\n"); /* the it is illegeal symbol */ - getchar(); - exit(1); - } - - - postfix_exp[j] = '\0'; /* add sentinel else puts() fucntion */ - /* will print entire postfix[] array upto SIZE */ - -} - -/* main function begins */ -int main() -{ - char infix[SIZE], postfix[SIZE]; /* declare infix string and postfix string */ - - /* why we asked the user to enter infix expression - * in parentheses ( ) - * What changes are required in porgram to - * get rid of this restriction since it is not - * in algorithm - * */ - printf("ASSUMPTION: The infix expression contains single letter variables and single digit constants only.\n"); - printf("\nEnter Infix expression : "); - gets(infix); - - InfixToPostfix(infix,postfix); /* call to convert */ - printf("Postfix Expression: "); - puts(postfix); /* print postfix expression */ - - return 0; -} diff --git a/Data Structures/Stack/Infix to prefix/Infix to prefix2.o b/Data Structures/Stack/Infix to prefix/Infix to prefix2.o deleted file mode 100644 index 063dc7a..0000000 Binary files a/Data Structures/Stack/Infix to prefix/Infix to prefix2.o and /dev/null differ diff --git a/Data Structures/Stack/Infix to prefix/Makefile.win b/Data Structures/Stack/Infix to prefix/Makefile.win deleted file mode 100644 index 07aeda7..0000000 --- a/Data Structures/Stack/Infix to prefix/Makefile.win +++ /dev/null @@ -1,31 +0,0 @@ -# Project: Project1 -# Makefile created by Dev-C++ 5.11 - -CPP = g++.exe -CC = gcc.exe -WINDRES = windres.exe -OBJ = "Infix\ to\ prefix/main.o" "Infix\ to\ prefix2.o" -LINKOBJ = "Infix to prefix/main.o" "Infix to prefix2.o" -LIBS = -L"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib" -L"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/lib" -static-libgcc -INCS = -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include" -CXXINCS = -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++" -BIN = "POLISH Infix to Postfix.exe" -CXXFLAGS = $(CXXINCS) -CFLAGS = $(INCS) -RM = rm.exe -f - -.PHONY: all all-before all-after clean clean-custom - -all: all-before $(BIN) all-after - -clean: clean-custom - ${RM} $(OBJ) $(BIN) - -$(BIN): $(OBJ) - $(CC) $(LINKOBJ) -o $(BIN) $(LIBS) - -"Infix\ to\ prefix/main.o": Infix\ to\ prefix/main.c - $(CC) -c "Infix to prefix/main.c" -o "Infix to prefix/main.o" $(CFLAGS) - -"Infix\ to\ prefix2.o": Infix\ to\ prefix2.c - $(CC) -c "Infix to prefix2.c" -o "Infix to prefix2.o" $(CFLAGS) diff --git a/Data Structures/Stack/Infix to prefix/POLISH Infix to Postfix b/Data Structures/Stack/Infix to prefix/POLISH Infix to Postfix deleted file mode 100644 index e782378..0000000 --- a/Data Structures/Stack/Infix to prefix/POLISH Infix to Postfix +++ /dev/null @@ -1,72 +0,0 @@ -[Project] -FileName=POLISH Infix to Postfix -Name=Project1 -Type=1 -Ver=2 -ObjFiles= -Includes= -Libs= -PrivateResource= -ResourceIncludes= -MakeIncludes= -Compiler= -CppCompiler= -Linker= -IsCpp=0 -Icon= -ExeOutput= -ObjectOutput= -LogOutput= -LogOutputEnabled=0 -OverrideOutput=0 -OverrideOutputName= -HostApplication= -UseCustomMakefile=0 -CustomMakefile= -CommandLine= -Folders= -IncludeVersionInfo=0 -SupportXPThemes=0 -CompilerSet=0 -CompilerSettings=0000000000000000000000000 -UnitCount=2 - -[VersionInfo] -Major=1 -Minor=0 -Release=0 -Build=0 -LanguageID=1033 -CharsetID=1252 -CompanyName= -FileVersion= -FileDescription=Developed using the Dev-C++ IDE -InternalName= -LegalCopyright= -LegalTrademarks= -OriginalFilename= -ProductName= -ProductVersion= -AutoIncBuildNr=0 -SyncProduct=1 - -[Unit1] -FileName=Infix to prefix\main.c -CompileCpp=0 -Folder= -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit2] -FileName=Infix to prefix2.c -CompileCpp=0 -Folder= -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - diff --git a/Data Structures/Stack/Infix to prefix/POLISH Infix to Postfix.layout b/Data Structures/Stack/Infix to prefix/POLISH Infix to Postfix.layout deleted file mode 100644 index 14cd03d..0000000 --- a/Data Structures/Stack/Infix to prefix/POLISH Infix to Postfix.layout +++ /dev/null @@ -1,13 +0,0 @@ -[Editors] -Order=0,1 -Focused=0 -[Editor_0] -CursorCol=6 -CursorRow=19 -TopLine=4 -LeftChar=1 -[Editor_1] -CursorCol=1 -CursorRow=1 -TopLine=1 -LeftChar=1 diff --git a/Data Structures/Stack/Infix to prefix/Untitled1.cpp b/Data Structures/Stack/Infix to prefix/Untitled1.cpp deleted file mode 100644 index 11bd325..0000000 --- a/Data Structures/Stack/Infix to prefix/Untitled1.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include -#include -char stack[20]; -int top = -1; -void push(char x) -{ - stack[++top] = x; -} - -char pop() -{ - if(top == -1) - return -1; - else - return stack[top--]; -} - -int priority(char x) -{ - if(x == '(') - return 0; - if(x == '+' || x == '-') - return 1; - if(x == '*' || x == '/') - return 2; - if(x == '^') - return 3; -} - -main() -{ - char exp[20]; - char *e, x; - printf("Enter the expression :: "); - scanf("%s",exp); - e = exp; - while(*e != '\0') - { - if(isalnum(*e)) - printf("%c",*e); - else if(*e == '(') - push(*e); - else if(*e == ')') - { - while((x = pop()) != '(') - printf("%c", x); - } - else - { - while(priority(stack[top]) >= priority(*e)) - printf("%c",pop()); - push(*e); - } - e++; - } - while(top != -1) - { - printf("%c",pop()); - } -} diff --git a/Data Structures/Stack/Infix to prefix/Write a program to convert an infix expression into its equivalent postfix notation.pdf b/Data Structures/Stack/Infix to prefix/Write a program to convert an infix expression into its equivalent postfix notation.pdf deleted file mode 100644 index 4065075..0000000 Binary files a/Data Structures/Stack/Infix to prefix/Write a program to convert an infix expression into its equivalent postfix notation.pdf and /dev/null differ diff --git a/Data Structures/Stack/Infix to prefix/main.c b/Data Structures/Stack/Infix to prefix/main.c deleted file mode 100644 index 394660b..0000000 --- a/Data Structures/Stack/Infix to prefix/main.c +++ /dev/null @@ -1,138 +0,0 @@ -#include -#include -#include -#include - -#define MAX 20 -int top=-1; -char stack[MAX]; - -int main() -{ - char infix[MAX],postfix[MAX]; - printf("Enter your infix expression(containing only single digit vairable and constant) : "); - scanf("%s",&infix); - infix_to_postfix(infix,postfix); - printf("\nThe postfix epression is : "); - puts(postfix); -} -void infix_to_postfix(char infix[],char postfix[]) -{ - int i=0,j=0; - char item,x; - - push('('); - strcat(infix,')'); - item=infix[i]; - - while(item!=NULL) - { - if(item=='(') - { - push(item); - } - else if(isalnum(item)) - { - stack[j]=item; - j++; - } - else if(is_operator(item)) - { - char x; - x=pop(); - while(is_operator(item)==1 && precedance(x) >= precedance(item)) - { - stack[j]=x; - j++; - x=pop(); - } - push(x); - push(item); - } - else if(item==')') - { - x=pop(); - while(x!='(') - { - stack[j]=x; - x=pop(); - } - } - else - { - print("Invalid infix expression!"); - exit(1); - } - - - i++; - item=infix[i]; - } - postfix[j]=NULL; -} - - -void push(char item) -{ - if(top >= MAX-1) - { - printf("\nStack Overflow."); - } - else - { - top = top+1; - stack[top] = item; - } -} - - -void pop() -{ - char item ; - - if(top <0) - { - printf("stack under flow: invalid infix expression"); - exit(1); - } - else - { - item = stack[top]; - top = top-1; - return(item); - } -} - -void is_operator(char symbol) -{ - if(symbol == '^' || symbol == '*' || symbol == '/' || symbol == '+' || symbol =='-') - { - return 1; - } - else - { - return 0; - } -} - - -void precedance(char symbol) -{ - if(symbol == '^') - { - return(3); - } - else if(symbol == '*' || symbol == '/') - { - return(2); - } - else if(symbol == '+' || symbol == '-') - { - return(1); - } - else - { - return(0); - } -} - diff --git a/Data Structures/Stack/Infix to prefix/main.o b/Data Structures/Stack/Infix to prefix/main.o deleted file mode 100644 index ce17a87..0000000 Binary files a/Data Structures/Stack/Infix to prefix/main.o and /dev/null differ diff --git a/Data Structures/Stack/Pop, Push and Peep/POP,PUSH,PEEP.cbp b/Data Structures/Stack/Pop, Push and Peep/POP,PUSH,PEEP.cbp deleted file mode 100644 index ad1eae0..0000000 --- a/Data Structures/Stack/Pop, Push and Peep/POP,PUSH,PEEP.cbp +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - diff --git a/Data Structures/Stack/Pop, Push and Peep/POP,PUSH,PEEP.depend b/Data Structures/Stack/Pop, Push and Peep/POP,PUSH,PEEP.depend deleted file mode 100644 index bbf7745..0000000 --- a/Data Structures/Stack/Pop, Push and Peep/POP,PUSH,PEEP.depend +++ /dev/null @@ -1,6 +0,0 @@ -# depslib dependency file v1.0 -1532189719 source:d:\btech curriculum\data structure & algorithm through c\stack\pop,push,peep\main.c - - - - diff --git a/Data Structures/Stack/Pop, Push and Peep/POP,PUSH,PEEP.layout b/Data Structures/Stack/Pop, Push and Peep/POP,PUSH,PEEP.layout deleted file mode 100644 index f09a32a..0000000 --- a/Data Structures/Stack/Pop, Push and Peep/POP,PUSH,PEEP.layout +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/Data Structures/Stack/Pop, Push and Peep/bin/Debug/POP,PUSH,PEEP.exe b/Data Structures/Stack/Pop, Push and Peep/bin/Debug/POP,PUSH,PEEP.exe deleted file mode 100644 index 4480833..0000000 Binary files a/Data Structures/Stack/Pop, Push and Peep/bin/Debug/POP,PUSH,PEEP.exe and /dev/null differ diff --git a/Data Structures/Stack/Pop, Push and Peep/main.c b/Data Structures/Stack/Pop, Push and Peep/main.c deleted file mode 100644 index ad96a3c..0000000 --- a/Data Structures/Stack/Pop, Push and Peep/main.c +++ /dev/null @@ -1,82 +0,0 @@ -#include -#include -#include - -#define MAX 5 - -int top=-1,stack[MAX]; -void push(); -void pop(); -void display(); - -int main() -{ - int ch; - - while(1) - { - printf("\n*** Stack Menu ***"); - printf("\n\n1.Push\n2.Pop\n3.Display\n4.Exit"); - printf("\n\nEnter your choice(1-4):"); - scanf("%d",&ch); - - switch(ch) - { - case 1: push(); - break; - case 2: pop(); - break; - case 3: display(); - break; - case 4: exit(0); - - default: printf("\nWrong Choice!!"); - } - } -} - -void push() -{ - int val; - - if(top==MAX-1) - { - printf("\nStack is full!!"); - } - else - { - printf("\nEnter element to push:"); - scanf("%d",&val); - top=top+1; - stack[top]=val; - } -} - -void pop() -{ - if(top==-1) - { - printf("\nStack is empty!!"); - } - else - { - printf("\nDeleted element is %d",stack[top]); - top=top-1; - } -} - -void display() -{ - int i; - - if(top==-1) - { - printf("\nStack is empty!!"); - } - else - { - printf("\nStack is...\n"); - for(i=0;i<=top;i++) - printf("%d\n",stack[i]); - } -} diff --git a/Data Structures/Stack/Pop, Push and Peep/main.exe b/Data Structures/Stack/Pop, Push and Peep/main.exe deleted file mode 100644 index 3210501..0000000 Binary files a/Data Structures/Stack/Pop, Push and Peep/main.exe and /dev/null differ diff --git a/Data Structures/Stack/Pop, Push and Peep/main.o b/Data Structures/Stack/Pop, Push and Peep/main.o deleted file mode 100644 index f526669..0000000 Binary files a/Data Structures/Stack/Pop, Push and Peep/main.o and /dev/null differ diff --git a/Data Structures/Stack/Pop, Push and Peep/obj/Debug/main.o b/Data Structures/Stack/Pop, Push and Peep/obj/Debug/main.o deleted file mode 100644 index 248330a..0000000 Binary files a/Data Structures/Stack/Pop, Push and Peep/obj/Debug/main.o and /dev/null differ diff --git a/Data Structures/Stack/Reversal of string/String Reversal.cpp b/Data Structures/Stack/Reversal of string/String Reversal.cpp deleted file mode 100644 index 2e6432a..0000000 --- a/Data Structures/Stack/Reversal of string/String Reversal.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include -#include -#include - -#define MAX 10 -int top=-1,item; -char stack[MAX]; - -void push(char item){ - if(top==MAX-1){ - printf("OVERFLOW!\n"); - } - else{ - top=top+1; - stack[top]=item; - } -} - -char pop(){ - if(top==-1){ - printf("UNDERFLOW!\n"); - } - else{ - item=stack[top]; - top=top-1; - return item; - } -} -int main(){ - int i,l; - char str[10]; - printf("\nEnter Your sting : "); - gets(str); - - l=strlen(str); - for(i=0;i -using namespace std; - - -struct Node -{ - int data; - struct Node* left, *right; - Node(int data) - { - this->data = data; - left = right = NULL; - } -}; -void printPostorder(struct Node* node) -{ - if (node == NULL) - return; - - printPostorder(node->left); - - printPostorder(node->right); - - cout << node->data << " "; -} - -void printInorder(struct Node* node) -{ - if (node == NULL) - return; - - printInorder(node->left); - - cout << node->data << " "; - - printInorder(node->right); -} - -void printPreorder(struct Node* node) -{ - if (node == NULL) - return; - - cout << node->data << " "; - - printPreorder(node->left); - - printPreorder(node->right); -} - -int main() -{ - struct Node *root = new Node(1); - root->left = new Node(2); - root->right = new Node(3); - root->left->left = new Node(4); - root->left->right = new Node(5); - - cout << "\nPreorder traversal of binary tree is \n"; - printPreorder(root); - - cout << "\nInorder traversal of binary tree is \n"; - printInorder(root); - - cout << "\nPostorder traversal of binary tree is \n"; - printPostorder(root); - - return 0; -} - diff --git a/Data Structures/Trees/Traversal.exe b/Data Structures/Trees/Traversal.exe deleted file mode 100644 index f0a9265..0000000 Binary files a/Data Structures/Trees/Traversal.exe and /dev/null differ diff --git a/README.md b/README.md deleted file mode 100644 index 08b987a..0000000 --- a/README.md +++ /dev/null @@ -1,19 +0,0 @@ -# DataStructure and Algorithms -A collection of all popular Data Structure and Algorithm. You can contribute by adding new Data Structures and Algorithms. - -## How to contribute: - -1. Fork this repository to your own account by clicking the Fork button. -1. Access your new fork on your account in the repositories and clone it: -1. Cloning process can be carried out by the following methods -> - 1. Click on Clone or download button on forked repo and download zip - 1. Open terminal/Git bash and use - https: ` git clone https://github.com/arghac14/DataStructure-and-Algorithms.git ` - ssh: `git@github.com:YourUserName/DataStructure-and-Algorithms.git` - -1. Add new Data Structure and Algorithms that don't already exist in the original repo. -1. Push the changes and make a PR! - - - -