diff --git a/AI/8 PUZZLE/about.txt b/AI/8 PUZZLE/about.txt deleted file mode 100644 index 5879633..0000000 --- a/AI/8 PUZZLE/about.txt +++ /dev/null @@ -1,2 +0,0 @@ -The 8-puzzle is a sliding tile puzzle that is made up of a square structured frame area containing 9 tiles in random/irregular order with one tile missing. The 8-puzzle problem is a puzzle invented and popularized by Noyes Palmer Chapman in the 1870s. -It is a smaller version of the 15-puzzle (also called Gem Puzzle, Boss Puzzle, Game of Fifteen, Mystic Square and numerous other names). 8-puzzle is basically a frame area separated into 3x3 grids containing 8 tiles and one void grid. The tiles are marked in some way so as they can be identified. The tiles are mostly numbered from 1 to 8. We are given with an initial configuration of the tiles. A desired final configuration is also given. We have to reach the final state by sliding the tiles in either vertically or horizontally using the empty grid present. Diagonally swapping is not allowed. diff --git a/AI/8 PUZZLE/puzzle.c b/AI/8 PUZZLE/puzzle.c deleted file mode 100644 index 5c84935..0000000 --- a/AI/8 PUZZLE/puzzle.c +++ /dev/null @@ -1,101 +0,0 @@ -#include -int i,j; -void swap(int x, int y) -{ - int temp; - temp=x; - x=y; - y=temp; -} -void move_up(int arr_in[][3]) -{ - for(i=0;i<3;i++) - { - for(i=0;j<3;j++) - { - if(arr_in[i][j]==0) - { - swap(arr_in[i][j],arr_in[i-1][j]); - } - } - } -} -void move_down(int arr_in[][3]) -{ - for(i=0;i<3;i++) - { - for(i=0;j<3;j++) - { - if(arr_in[i][j]==0) - { - swap(arr_in[i][j],arr_in[i+1][j]); - } - } - } -} -void move_left(int arr_in[][3]) -{ - for(i=0;i<3;i++) - { - for(i=0;j<3;j++) - { - if(arr_in[i][j]==0) - { - swap(arr_in[i][j],arr_in[i][j-1]); - } - } - } -} -void move_right(int arr_in[][3]) -{ - for(i=0;i<3;i++) - { - for(i=0;j<3;j++) - { - if(arr_in[i][j]==0) - { - swap(arr_in[i][j],arr_in[i][j+1]); - } - } - } -} -void puzzle(int arr_in[][3],int i,int j,int arr_fi[][3]) -{ - for(i=0;i<3;i++) - { - for(j=0;j<3;j++) - { - if(arr_in[i][j]==arr_fi[i][j]) - { - continue; - } - else - break; - } - } - -} -void main() -{ - int arr_in[3][3],arr_fi[3][3],i,j; - printf("enter puzzle's initial position: \n"); - for(i=0;i<3;i++) - for(j=0;j<3;j++) - { - scanf("%d",&arr_in[i][j]); - } - printf("enter puzzle's final position: \n"); - for(i=0;i<3;i++) - for(j=0;j<3;j++) - { - scanf("%d",&arr_fi[i][j]); - } - for(i=0;i<3;i++) - { - for(j=0;j<3;j++) - { - printf("%d ",arr_fi[i][j]); - } - printf("\n"); - } -} diff --git a/AI/MAP of ROMANIA/A* Algorithm/About b/AI/MAP of ROMANIA/A* Algorithm/About deleted file mode 100644 index 4efd771..0000000 --- a/AI/MAP of ROMANIA/A* Algorithm/About +++ /dev/null @@ -1 +0,0 @@ -A* Search algorithm is one of the best and popular technique used in path-finding and graph traversals. diff --git a/AI/MAP of ROMANIA/A_star Algorithm/Map of Romania with A_star.c b/AI/MAP of ROMANIA/A_star Algorithm/Map of Romania with A_star.c deleted file mode 100644 index 32d975d..0000000 --- a/AI/MAP of ROMANIA/A_star Algorithm/Map of Romania with A_star.c +++ /dev/null @@ -1,183 +0,0 @@ -/* -This assignment wishes to send the user(agent) from Arad to Bucharest -or from any place in the map to Bucharest in the map of Romania using -the A* Algorithm Search Technique. The Heuristic Function for this Problem -is the sum of the Straight Line Distance of Bucharest from the next state(node) -and the cost of reaching to that node(distance between the current and next node). -*/ - - -#include -#include -#include - - -int path[20][20]; -int dist_bucharest[20]; -int visited[20]; -int availables[10][2]; -char *name[20]={"Arad", "Bucharest" , "Craiova", "Dobreta", "Eforie", "Fagarus", "Giurgiu", "Hirsova", "Lasi", "Lugoj", "Mehadia", "Neamt", "Oradea", "Pitesti", "RimnicuVilcea", "Sibiu", "Timisora", "Urziceni", "Valsui", "Zerind"}; -; - -void create_map() //initialises the map -{ - for(int i=0; i<20;i++) - for(int j=0; j<20; j++) - { - path[i][j] = 20000; - path[i][i] = 0; - } - path[0][15] = 140; - path[0][19] = 75; - path[0][16] = 118; - path[1][5] = 211; - path[1][6] = 90; - path[1][13] = 101; - path[1][17] = 85; - path[2][3] = 120; - path[2][13] = 138; - path[2][14] = 146; - path[3][10] = 75; - path[4][7] = 86; - path[5][15] = 99; - path[7][17] = 98; - path[8][11] = 87; - path[8][18] = 92; - path[9][10] = 70; - path[9][16] = 111; - path[12][19] = 71; - path[12][15] = 151; - path[13][14] = 97; - path[14][15] = 80; - path[17][18] = 142; - - for(int i=0; i<20; i++) - for(int j=0; j<20; j++) - path[j][i]= path[i][j]; - - dist_bucharest[0]=366; - dist_bucharest[1]=0; - dist_bucharest[2]=160; - dist_bucharest[3]=242; - dist_bucharest[4]=161; - dist_bucharest[5]=176; - dist_bucharest[6]=77; - dist_bucharest[7]=151; - dist_bucharest[8]=226; - dist_bucharest[9]=244; - dist_bucharest[10]=241; - dist_bucharest[11]=234; - dist_bucharest[12]=380; - dist_bucharest[13]=100; - dist_bucharest[14]=193; - dist_bucharest[15]=253; - dist_bucharest[16]=329; - dist_bucharest[17]=80; - dist_bucharest[18]=199; - dist_bucharest[19]=374; - - for(int i=0;i<20; i++) - visited[i] = 0; - - -} - -int minimum(int arr[][2],int n) //finds the minimum heuristic value from the "Available" array -{ - int mincount=0; - int min = 9999; - int i; - for(i=0; i0 && visited[j]!=1) - { - availables[k][0]=j; - availables[k][1]=dist_bucharest[j] + path[currpoint][j]; - k++; - } - - } - - - int indexi=minimum(availables,k); - minpoint=availables[indexi][0]; - if(currpoint==1) printf("NIL\t\t\t\t\t%s\n",name[currpoint]); - else printf("%d\t\t\t\t\t%s\n",availables[indexi][1] - dist_bucharest[minpoint],name[currpoint]); - - visited[currpoint]=1; - steps++; - currpoint=minpoint; - } - if(steps!=0){ steps--;} - if(steps==0){ printf("NIL\t\t\t\t\tBucharest\n\nThe Initial place is the Final place, i.e., You are already in Bucharest!\n");} - printf("Total no of Steps(traveling to adjacent nodes)= %d\n", steps); - return 0; -} - - - diff --git a/AI/MAP of ROMANIA/Greedy BFS/Map of Romania.c b/AI/MAP of ROMANIA/Greedy BFS/Map of Romania.c deleted file mode 100644 index 04d8129..0000000 --- a/AI/MAP of ROMANIA/Greedy BFS/Map of Romania.c +++ /dev/null @@ -1,177 +0,0 @@ -/* -This assignment wishes to send the user(agent) from Arad to Bucharest -or from any place in the map to Bucharest in the map of Romania using -the Greedy Best First Search. The Straight line distance to reach -Bucharest is the Heuristic Function for this Problem. -*/ - - -#include -#include -#include - - -int path[20][20]; -int dist_bucharest[20]; -int visited[20]; -int availables[10][2]; -char *name[20]={"Arad", "Bucharest" , "Craiova", "Dobreta", "Eforie", "Fagarus", "Giurgiu", "Hirsova", "Lasi", "Lugoj", "Mehadia", "Neamt", "Oradea", "Pitesti", "RimnicuVilcea", "Sibeu", "Timisora", "Urziceni", "Valsui", "Zerind"}; -; - -void create_map() //initialises the map -{ - for(int i=0; i<20;i++) - for(int j=0; j<20; j++) - { - path[i][j] = 20000; - path[i][i] = 0; - } - path[0][15] = 140; - path[0][19] = 75; - path[0][16] = 118; - path[1][5] = 211; - path[1][6] = 90; - path[1][13] = 101; - path[1][17] = 85; - path[2][3] = 120; - path[2][13] = 138; - path[2][14] = 146; - path[3][10] = 75; - path[4][7] = 86; - path[5][15] = 99; - path[7][17] = 98; - path[8][11] = 87; - path[8][18] = 92; - path[9][10] = 70; - path[9][16] = 111; - path[12][19] = 71; - path[12][15] = 151; - path[14][15] = 80; - path[14][13] = 97; - path[17][18] = 142; - - for(int i=0; i<20; i++) - for(int j=0; j<20; j++) - path[j][i]= path[i][j]; - - dist_bucharest[0]=366; - dist_bucharest[1]=0; - dist_bucharest[2]=160; - dist_bucharest[3]=242; - dist_bucharest[4]=161; - dist_bucharest[5]=176; - dist_bucharest[6]=77; - dist_bucharest[7]=151; - dist_bucharest[8]=226; - dist_bucharest[9]=244; - dist_bucharest[10]=241; - dist_bucharest[11]=234; - dist_bucharest[12]=380; - dist_bucharest[13]=100; - dist_bucharest[14]=193; - dist_bucharest[15]=253; - dist_bucharest[16]=329; - dist_bucharest[17]=80; - dist_bucharest[18]=199; - dist_bucharest[19]=374; - - for(int i=0;i<20; i++) - visited[i] = 0; - - -} - -int minimum(int arr[][2],int n) //finds the minimum heuristic value from the "Available" array -{ - int mincount=0; - int min = 9999; - for(int i=0; i0 && visited[j]!=1) - { - availables[k][0]=j; - availables[k][1]=dist_bucharest[j]; - k++; - } - - } - - printf("%d\t\t\t\t\t%s\n",dist_bucharest[currpoint],name[currpoint]); - minpoint=minimum(availables,k); - visited[currpoint]=1; - steps++; - currpoint=minpoint; - } - if(steps!=0){ steps--;} - if(steps==0){ printf("NIL\t\t\t\t\tBucharest\n\nThe Initial place is the Final place, i.e., You are already in Bucharest!\n");} - printf("Total no of Steps(traveling to adjacent nodes)= %d\n", steps); - return 0; -} - - - diff --git a/AI/MAP of ROMANIA/Greedy BFS/Map of Romania.pdf b/AI/MAP of ROMANIA/Greedy BFS/Map of Romania.pdf deleted file mode 100644 index 3fa5ced..0000000 Binary files a/AI/MAP of ROMANIA/Greedy BFS/Map of Romania.pdf and /dev/null differ diff --git a/AI/MAP of ROMANIA/Greedy BFS/about.txt b/AI/MAP of ROMANIA/Greedy BFS/about.txt deleted file mode 100644 index c46fca8..0000000 --- a/AI/MAP of ROMANIA/Greedy BFS/about.txt +++ /dev/null @@ -1 +0,0 @@ -This assignment wishes to send the user from Arad to Bucharest in the map of Romania using the Greedy Best First Search with the Straight line distance to reach Bucharest as the Heuristic Function for the Problem. diff --git a/AI/README.md b/AI/README.md deleted file mode 100644 index 10379ab..0000000 --- a/AI/README.md +++ /dev/null @@ -1 +0,0 @@ -AI projects diff --git a/AI/astar_algo.py b/AI/astar_algo.py deleted file mode 100644 index 1f9d432..0000000 --- a/AI/astar_algo.py +++ /dev/null @@ -1,113 +0,0 @@ -from collections import deque - -class Graph: - - def __init__(self, adjacency_list): - self.adjacency_list = adjacency_list - - def get_neighbors(self, v): - return self.adjacency_list[v] - - # heuristic function with equal values for all nodes - def h(self, n): - H = { - '0': 7, - '1': 6, - '2': 2, - '3': 1, - '4': 0 - } - - return H[n] - - def a_star_algorithm(self, start_node, stop_node): - # open_list is a list of nodes which have been visited, but who's neighbors - # haven't all been inspected, starts off with the start node - # closed_list is a list of nodes which have been visited - # and who's neighbors have been inspected - open_list = set([start_node]) - closed_list = set([]) - - # g contains current distances from start_node to all other nodes - # the default value (if it's not found in the map) is +infinity - g = {} - - g[start_node] = 0 - - # parents contains an adjacency map of all nodes - parents = {} - parents[start_node] = start_node - - while len(open_list) > 0: - n = None - - # find a node with the lowest value of f() - evaluation function - for v in open_list: - if n == None or g[v] + self.h(v) < g[n] + self.h(n): - n = v; - - if n == None: - print('Path does not exist!') - return None - - # if the current node is the stop_node - # then we begin reconstructin the path from it to the start_node - if n == stop_node: - reconst_path = [] - - while parents[n] != n: - reconst_path.append(n) - n = parents[n] - - reconst_path.append(start_node) - - reconst_path.reverse() - - print('Path found: {}'.format(reconst_path)) - return reconst_path - - # for all neighbors of the current node do - for (m, weight) in self.get_neighbors(n): - # if the current node isn't in both open_list and closed_list - # add it to open_list and note n as it's parent - if m not in open_list and m not in closed_list: - open_list.add(m) - parents[m] = n - g[m] = g[n] + weight - - # otherwise, check if it's quicker to first visit n, then m - # and if it is, update parent data and g data - # and if the node was in the closed_list, move it to open_list - else: - if g[m] > g[n] + weight: - g[m] = g[n] + weight - parents[m] = n - - if m in closed_list: - closed_list.remove(m) - open_list.add(m) - - # remove n from the open_list, and add it to closed_list - # because all of his neighbors were inspected - open_list.remove(n) - closed_list.add(n) - - print('Path does not exist!') - return None - -adjacency_list = { -'0': [('2', 4), ('1', 1)], -'1': [('2', 2), ('3', 5), ('4', 12)], -'2': [('3', 2)], -'3': [('4', 3)] -} -graph1 = Graph(adjacency_list) -graph1.a_star_algorithm('0', '4') - - -############################################################################# -##### expected path: ['S', 'A', 'B', 'C', 'D'] ##### - - -# Defn : Heuristic function at a node n is an estimate of the optimum cost from the current node n to a Goal and it is denoted by h(n) . -## so here we have given that optimum value in fun h() diff --git a/Binary_search.cpp b/Binary_search.cpp new file mode 100644 index 0000000..674f604 --- /dev/null +++ b/Binary_search.cpp @@ -0,0 +1,38 @@ +#include +using namespace std; +int binary_search(int v,int n); +int a[100]; +int main(){ + int n,v; + cin>>n; + for(int i=0;i>a[i]; + } + cin>>v; + int ans= binary_search(v,n); + cout<1){ + + int mid=(lo+hi)/2; + if(a[mid]==v){ + return mid; + } + if(a[mid]>v){ + hi=mid; + } + else if(a[mid] - int main() -{ -int n,r,sum=0,temp; -printf("enter the number="); -scanf("%d",&n); -temp=n; -while(n>0) -{ -r=n%10; -sum=sum+(r*r*r); -n=n/10; -} -if(temp==sum) -printf("armstrong number "); -else -printf("not armstrong number"); -return 0; -} \ No newline at end of file diff --git a/C/Banker's Algorithm/About b/C/Banker's Algorithm/About deleted file mode 100644 index 5675705..0000000 --- a/C/Banker's Algorithm/About +++ /dev/null @@ -1,2 +0,0 @@ -For information about the Banker's Algorithm, Please visit the following link: -https://www.geeksforgeeks.org/bankers-algorithm-in-operating-system-2/ diff --git a/C/Banker's Algorithm/bankers_algorithm.c b/C/Banker's Algorithm/bankers_algorithm.c deleted file mode 100644 index ad31edb..0000000 --- a/C/Banker's Algorithm/bankers_algorithm.c +++ /dev/null @@ -1,198 +0,0 @@ -/* -The banker’s algorithm is a resource allocation and deadlock avoidance algorithm that tests for safety by simulating the allocation for predetermined maximum possible amounts of all resources, then makes an “s-state” check to test for possible activities, before deciding whether allocation should be allowed to continue. - -This program is an Example of banker's algorithm with predefined allocation of resources for the given 5 proceses. The total number of resources assumed here is 3. -*/ - -#include -#define n 5 -#define m 3 - - -int fin=0,finrq=0; //no of processes finished for work | finished after request -int allocation[n][m]={{0,1,0},{2,0,0},{3,0,2},{2,1,1},{0,0,2}}; //initial resource allocation -int max[n][m]={{7,5,3},{3,2,2},{9,0,2},{2,2,2},{4,3,3}}; //maximum resource allocation for completion of the process -int available[m]={3,3,2}; //available resources -int work[m]={3,3,2}; //temp available resources for calculation of system as safe or unsafe -int finish[n]={0,0,0,0,0}; //array for determining the condition of ith process for work -int finishrq[n]={0,0,0,0,0}; //array for determining the condition of ith process after request alc -int need[n][m]; //array for determining the need of resources by a process -int request[m]; //the requested no of resources fot the process indexed by 'rq' -int rq; - -//calculating the need -void calcneed() -{ - for(int i=0;i work[j]) - ctr++; - } - if(ctr==0) - updatework(i); - } - } - flag++; - if(flag>5) break; - } - if(fin!=5) {printf("SYSTEM is NOT SAFE !\n"); return 0;} - else {printf("SYSTEM IS SAFE !\n"); return 1;} -} -//Safety finished - -//resource request - -//this function updates for safety checking -void update(int i) -{ - for(int j=0;jneed[rq][j]) ctr++; - } - if(ctr!=0) {printf("\nProcess request exceeds its max demand!\n"); return 0;} - ctr=0; - for(j=0;javailable[j]) ctr++; - } - if(ctr!=0) {printf("\nProcess must wait as resources are not available !\n"); return 0;} - update(rq); - int ch1=check(); - if(ch1==0) updaterev(rq); - else{ - - for(j=0,ctr=0;j -#include -#include - -void rightShift(int p[],int first[],int new) -{ - int i=0; - while(new-i-1) - { - first[new-i-1]=first[new-i-2]; - i++; - } - first[0]=p[new-1]; - i=0; - while(new-i-1) - { - p[new-i-1]=p[new-i-2]; - i++; - } -} - - - -int main() -{ - - printf("\n BOOTH's Algorithm\n"); - printf("0-0 Right Shift.\n"); - printf("0-1 Add M to P. Right Shift.\n"); - printf("1-0 Add -M to P. Right Shift.\n"); - printf("1-1 Right Shift.\n"); - printf("\n"); - int a,b; - printf("Enter two numbers that are to be multiplied : \n"); - printf("Enter A:\t"); - scanf("%d", &a); - printf("Enter B:\t"); - scanf("%d", &b); - int a1=a,b1=b; - if(a1<0) - a1*=-1; - if(b1<0) b1*=-1; if(b1>a1) - { - a1=b1+a1-(b1=a1); - a=b+a-(b=a); - } - int x=a1,y=b1; - int A[35]={}; - int B[35]={}; - int i=0; - while(x>0) - { - A[i]=x%2; - i++; - x/=2; - } - A[i]=0; - int j=0; - while(y>0) - { - B[j]=y%2; - j++; - y/=2; - } - while(j<=i) - B[j++]=0; - int new=i+1; - i=0;j=0; - while(i=0) - { - while(i=0) - { - while(i ",a); - i=0; - while(i ",b); - i=0; - while(i ",-b); - i=0; - while(i - -#include - -void main() - -{ - - float x [50]; /* max. 50 elements in array x */ - - int n; /*number of elements in array x */ - - float sum, mean, sd; /* sum, mean and standard deviation.*/ - - int i; - - - - /* read data */ - - printf("How many numbers (max 50)? "); - - scanf("%d", &n); - - printf ("Enter numbers: "); - - for(i = 0; i -#include -struct cr -{ - int data; - struct cr *next, *prev; -}s1,*node,*start,*end,*temp; -int count=0; -void construct() -{ - start=NULL;node=NULL;end=NULL; -} - -void insertb() -{ - int x; - printf("Enter the element:"); scanf("%d",&x); - count++; - - node=(struct cr *)malloc(sizeof(s1)); - node->data=x; - if(start==NULL) - { - start=node; - start->next=start; - start->prev=start; - end=node; - } - else - { - node->next=start; - end->next=node; - node->prev=end; - start->prev=node; - start=node; - } -} - -void inserte() -{ - int x; - printf("Enter the element:"); scanf("%d",&x); - count++; - node=(struct cr *)malloc(sizeof(s1)); - node->data=x; - if(start==NULL) - { - start=node; - start->next=start; - start->prev=start; - end=node; - } - else - { - node->next=start; - end->next=node; - node->prev=end; - start->prev=node; - end=node; - } -} - -void deletee() -{ - if(start==NULL) printf("Queue Underflow!!\n"); - else if(end==start) - { - temp=end; - free(temp); - start=NULL;end=NULL; - } - else - { - temp=end; - count--; - for(node=start;node->next->next!=start;node=node->next); - end=node; - end->next=start; - start->prev=end; - free(temp); - } -} - -void deleteb() -{ - if(start==NULL) printf("Queue Underflow!!\n"); - else if(end==start) - { - temp=end; - free(temp); - start=NULL;end=NULL; - } - else - { - temp=start; - count--; - start=start->next; - end->next=start; - start->prev=end; - free(temp); - } -} - -void display() -{ - int i; - if(start==NULL) - printf("\nQueue underflow!\n"); - else - { - printf("\nThe elements are:\n"); - //for(node=start;node!=start;node=node->next) - for(node=start,i=0;inext) - printf("%d ",node->data); - } -} -void main() -{ - int ch; - construct(); - while(1) - { - printf("\n\n***Circular Queue***\n1.Insert at beginning\n2.Insert at end\n3.Delete from begining\n4.Delete from end\n5.Display\n6.Exit\nEnter your choice:\n"); - scanf("%d",&ch); - switch(ch) - { - case 1: insertb(); break; - case 2: inserte(); break; - case 3: deleteb(); break; - case 4: deletee(); break; - case 5: display(); break; - case 6: exit(0); break; - default: printf("\nWrong Choice!!\n"); - } - } -} - - - diff --git a/C/Doubly_linked_list b/C/Doubly_linked_list deleted file mode 100644 index 70090f9..0000000 --- a/C/Doubly_linked_list +++ /dev/null @@ -1,155 +0,0 @@ -// Write a C program to implement Doubly linked list(one-way).This program must include following functions in it. -// a.Write a function to CONSTRUCT a doubly linked list. -// b.Write a function to INSERT an element at the beginning of the created doubly linked list(step a). -// c.Write a function to INSERT an element at the end of the doubly linked list. -// d.Write a function to DELETE an element from the beginning of the doubly linked list. -// e.Write a function to DELETE an element from the end of the doubly linked list. -// f.Write a function for "Display" operation which prints the content of the doubly linked list. - - -#include -#include -int value; -struct Node -{ - int data; - struct Node *previous; - struct Node *next; -}*head=NULL,*temp; - -void construct() -{ - temp =(struct Node *)malloc(sizeof(struct Node)); - temp->previous = NULL; - temp->next = NULL; - printf("Successfully created a doubly linked list\n"); -} - -void insertb() -{ - printf("Enter value to be inserted:"); - scanf("%d",&value); - struct Node *newNode; - newNode = (struct Node*)malloc(sizeof(struct Node)); - newNode -> data = value; - newNode -> previous = NULL; - if(head == NULL) - { - newNode -> next = NULL; - head = newNode; - } - else - { - newNode -> next = head; - head = newNode; - - } - printf("\nInsertion success!!!"); -} - -void inserte() -{ - - printf("Enter value to be inserted:"); - scanf("%d",&value); - struct Node *newNode; - newNode = (struct Node*)malloc(sizeof(struct Node)); - newNode -> data = value; - newNode -> next = NULL; - if(head == NULL) - { - newNode -> previous = NULL; - head = newNode; - } - else - { - struct Node *temp = head; - while(temp -> next != NULL) - temp = temp -> next; - temp -> next = newNode; - newNode -> previous = temp; - } - printf("\nInsertion success!!!"); -} - -void deleteb() -{ - if(head == NULL) - printf("List is Empty!!! Deletion not possible!!!"); - else - { - struct Node *temp = head; - if(temp -> previous == temp -> next) - { - head = NULL; - free(temp); - } - else{ - head = temp -> next; - head -> previous = NULL; - free(temp); - } - printf("\nDeletion success!!!"); - } -} - -void deletee() -{ - if(head == NULL) - printf("List is Empty!!! Deletion not possible!!!"); - else - { - struct Node *temp = head; - if(temp -> previous == temp -> next) - { - head = NULL; - free(temp); - } - else{ - while(temp -> next != NULL) - temp = temp -> next; - temp -> previous -> next = NULL; - free(temp); - } - printf("\nDeletion success!!!"); - } -} - -void display() -{ - - if(head == NULL) - printf("\nList is Empty!!!"); - else - { - struct Node *temp = head; - printf("\nList elements are: \n"); - while(temp -> next != NULL) - { - printf("%d\n",temp -> data); temp=temp->next; - } - printf("%d\n",temp -> data); - } -} - -void main() -{ -int c; -while(1) -{ -printf("\nDOUBLY LINKED LIST\n"); -printf("1.CONSTRUCT doubly linked list\n2.INSERT at beginning\n3.INSERT at end\n4.DELETE from beginning\n5.DELETE from end\n6.DISPLAY\n7.EXIT\n"); -printf("Enter your choice:\t"); -scanf("%d",&c); -switch(c) - { - case 1: construct(); break; - case 2: insertb(); break; - case 3: inserte(); break; - case 4: deleteb(); break; - case 5: deletee(); break; - case 6: display(); break; - case 7: exit(0); break; - } -} -} diff --git "a/C/Floyd\342\200\223Warshall algorithm" "b/C/Floyd\342\200\223Warshall algorithm" deleted file mode 100644 index d6f4b1c..0000000 --- "a/C/Floyd\342\200\223Warshall algorithm" +++ /dev/null @@ -1,75 +0,0 @@ -#include -#define LIMIT 100 -void show(int mat[LIMIT][LIMIT], int n); -void new_graph(); -int adjacency_matrix[LIMIT][LIMIT]; -int n; -int main() -{ - int P[LIMIT][LIMIT]; - int i, j, k; - new_graph(); - printf("\nadjacency_matrixacency Matrix\n"); - show(adjacency_matrix, n); - for(i = 0; i < n; i++) - { - for(j = 0; j < n; j++) - { - P[i][j] = adjacency_matrix[i][j]; - } - } - for(k = 0; k < n; k++) - { - for(i = 0; i < n; i++) - { - for(j = 0; j < n; j++) - { - P[i][j] = (P[i][j] || (P[i][k] && P[k][j])); - } - } - printf("P%d is: \n", k); - show(P, n); - } - printf("P%d is the path matrix of the given graph\n", k - 1); - return 0; -} -void show(int mat[LIMIT][LIMIT], int n) -{ - int i, j; - for(i = 0; i < n; i++) - { - for(j = 0; j < n; j++) - { - printf("%3d", mat[i][j]); - } - printf("\n"); - } -} -void new_graph() -{ - int count, maximum_edges, origin, destination; - printf("Enter Total Number of Vertices:\t"); - scanf("%d", &n); - maximum_edges = n * (n - 1); - for(count = 1; count <= maximum_edges; count++) - { - printf("\nCo - Ordinates for Edge No. %d [(-1 -1) To Quit]:\t", count); - printf("\nEnter Origin Point:\t"); - scanf("%d", &origin); - printf("\nEnter Destination Point:\t"); - scanf("%d", &destination); - if((origin == -1) && (destination == -1)) - { - break; - } - if(destination >= n || origin < 0 || origin >= n || destination < 0) - { - printf("Invalid Edge Input:\n"); - count--; - } - else - { - adjacency_matrix[origin][destination] = 1; - } - } -} diff --git a/C/Game_of_Life b/C/Game_of_Life deleted file mode 100644 index d2c6a39..0000000 --- a/C/Game_of_Life +++ /dev/null @@ -1,197 +0,0 @@ -#include -#include - - void header(void); - void survivalRule(char [][20], int, int); - void birthRule(char [][20], int, int); - void deathRule(char [][20], int, int); - - int main(void) - { - char Life[20][20]; - int orgs, gens; - int i, a, b, row, col; - int count = 0; - int x = 19; - int y = 19; - char ans; - - header(); - - do{ - printf("\nPlease enter the number of organisms you would like to live in the first generation: "); - scanf("%i", &orgs); - - srand( (unsigned)time( NULL ) ); - - for(i = 0; i 4) - { - Life[row][col] == ' '; - } - } - } - } - return; - } - - diff --git a/C/Game_of_Life(graphical) b/C/Game_of_Life(graphical) deleted file mode 100644 index 4c616a9..0000000 --- a/C/Game_of_Life(graphical) +++ /dev/null @@ -1,56 +0,0 @@ -#include -#include -#include - -#define for_x for (int x = 0; x < w; x++) -#define for_y for (int y = 0; y < h; y++) -#define for_xy for_x for_y -void show(void *u, int w, int h) -{ - int (*univ)[w] = u; - printf("\033[H"); - for_y { - for_x printf(univ[y][x] ? "\033[07m \033[m" : " "); - printf("\033[E"); - } - fflush(stdout); -} - -void evolve(void *u, int w, int h) -{ - unsigned (*univ)[w] = u; - unsigned new[h][w]; - - for_y for_x { - int n = 0; - for (int y1 = y - 1; y1 <= y + 1; y1++) - for (int x1 = x - 1; x1 <= x + 1; x1++) - if (univ[(y1 + h) % h][(x1 + w) % w]) - n++; - - if (univ[y][x]) n--; - new[y][x] = (n == 3 || (n == 2 && univ[y][x])); - } - for_y for_x univ[y][x] = new[y][x]; -} - -void game(int w, int h) -{ - unsigned univ[h][w]; - for_xy univ[y][x] = rand() < RAND_MAX / 10 ? 1 : 0; - while (1) { - show(univ, w, h); - evolve(univ, w, h); - usleep(200000); - } -} - -int main(int c, char **v) -{ - int w = 0, h = 0; - if (c > 1) w = atoi(v[1]); - if (c > 2) h = atoi(v[2]); - if (w <= 0) w = 30; - if (h <= 0) h = 30; - game(w, h); -} diff --git a/C/HelloPeople.c b/C/HelloPeople.c deleted file mode 100644 index fe262bf..0000000 --- a/C/HelloPeople.c +++ /dev/null @@ -1,4 +0,0 @@ -#include -void main(){ -printf("hello People"); -} diff --git a/C/Hello_word.c b/C/Hello_word.c deleted file mode 100644 index c5a0eb9..0000000 --- a/C/Hello_word.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -int main() -{ -printf("HELLO WORLD") - -return 0; -} diff --git a/C/Page Replacement Algorithms/Optimal.c b/C/Page Replacement Algorithms/Optimal.c deleted file mode 100644 index 118301a..0000000 --- a/C/Page Replacement Algorithms/Optimal.c +++ /dev/null @@ -1,112 +0,0 @@ -#include -#include -#include -#include -#define frames 3 -int queue[frames]={0,0,0}; -int dist[frames]={0,0,0}; -int hit=0,miss=0; -int max,maxi,pmax; -int search(int num,int arr[],int k) -{ - - int ctr=0,flag=0; - for(int i=0;imax) {max=dist[i]; maxi=i; } - /* else - { - maxi=(pmax+1)%frames; - } - */ - } - pmax=maxi; - return maxi; - - } -} -void display() -{ - for(int i=0;i -#include -#include -#include -#define frames 3 -int queue[frames]={0,0,0}; -int dist[frames]={0,0,0}; -int hit=0,miss=0; -int max,maxi,pmax; -int search(int num,int arr[],int k) -{ - - int ctr=0,flag=0; - for(int i=0;i=0;j--) - { - if(arr[j]==queue[i]) - { - dist[i]=k-j; - break; - - } - dist[i]=50; - } - - - } -// - printf("\nDist: "); - for(int i=0;imax) {max=dist[i]; maxi=i; } - /* else - { - maxi=(pmax+1)%frames; - } - */ - } - pmax=maxi; - return maxi; - - } -} -void display() -{ - for(int i=0;i -#include -#define max 10 - -int queue[max]; -int rear=-1; -int front=-1; -void insert() -{ - int item; - if(rear==max-1) - printf("QUEUE OVERFLOW\n"); - else - { - if(front==-1) - front=0; - printf("INSERT ELEMENT\n"); - scanf("%d",&item); - rear=rear+1; - queue[rear]=item; - } -} -void delete() -{ - if(front==-1||front>rear) - { - printf("QUEUE UNDERFLOW\n"); - return; - } - else - { - printf("ELEMENT DELETED FROM QUEUE IS: %d\n",queue[front]); - front=front+1; - } -} -void display() -{ - int i; - if(front==-1) - printf("QUEUE IS EMPTY\n"); - else - { - printf("QUEUE IS :\n"); - for(i=front;i<=rear;i++) - printf("%d\n",queue[i]); - printf("\n"); - } -} -void main() -{ - int a; - while(1) - { - printf("\n\n1.Insert\n2.Delete\n3.Display\n4.Exit"); - printf("\n\nEnter your choice:"); - scanf("%d",&a); - switch(a) - { - case 1: insert(); - break; - case 2: delete(); - break; - case 3: display(); - break; - case 4: exit(0); - default: printf("\nPlease enter a valid choice"); - } - } -} - diff --git a/C/README.md b/C/README.md deleted file mode 100644 index 5004d2b..0000000 --- a/C/README.md +++ /dev/null @@ -1 +0,0 @@ -This folder contains Algorithms in C. This includes banker's algorithm, simple swap and short coded programs like hello world. diff --git a/C/Scheduling/about.txt b/C/Scheduling/about.txt deleted file mode 100644 index 3803e2b..0000000 --- a/C/Scheduling/about.txt +++ /dev/null @@ -1 +0,0 @@ -It is shortest job first process scheduling algorithm. diff --git a/C/Scheduling/sjf.c b/C/Scheduling/sjf.c deleted file mode 100644 index f83371e..0000000 --- a/C/Scheduling/sjf.c +++ /dev/null @@ -1,77 +0,0 @@ -#include -#include -int i,j,n,cpu,start=-1,end=-1,l=0, check=0, total=0; -float atat=0.0,awt=0; -struct data{ - int at,bt,p_no,rt,ct,p,tat,wt; -}rq[10],temp1; -int k=0; -int main() -{ - struct data aa[10]; - printf("enter number of process: "); - scanf("%d",&n); - for(i=0;i aa[j+1].at) - { - temp1=aa[j]; - aa[j]=aa[j+1]; - aa[j+1]=temp1; - } - } - } - cpu=aa[0].at; - int minbt;int mbt; - while(l != n) - { mbt=-1; - minbt=9999; - for(j=0;j -#include - -struct Node -{ - int data; - struct Node *next; -}*top = NULL; - -void push(int); -void pop(); -void display(); - -void main() -{ - int choice, value; - - printf("\n:: STACK USING LINKED LIST ::\n"); - while(1){ - printf("\n****** MENU ******\n"); - printf("1. Push\n2. Pop\n3. Display\n4. Exit\n"); - printf("Enter your choice: "); - scanf("%d",&choice); - switch(choice){ - case 1: printf("Enter the value to be insert: "); - scanf("%d", &value); - push(value); - break; - case 2: pop(); break; - case 3: display(); break; - case 4: exit(0); - default: printf("\nWrong selection!!! Please try again!!!\n"); - } - } -} -void push(int value) -{ - struct Node *newNode; - newNode = (struct Node*)malloc(sizeof(struct Node)); - newNode->data = value; - if(top == NULL) - newNode->next = NULL; - else - newNode->next = top; - top = newNode; - printf("\nInsertion is Success!!!\n"); -} -void pop() -{ - if(top == NULL) - printf("\nStack is Empty!!!\n"); - else{ - struct Node *temp = top; - printf("\nDeleted element: %d", temp->data); - top = temp->next; - free(temp); - } -} -void display() -{ - if(top == NULL) - printf("\nStack is Empty!!!\n"); - else{ - struct Node *temp = top; - while(temp->next != NULL){ - printf("%d\t",temp->data); - temp = temp -> next; - } - printf("%d\tNULL",temp->data); - } -} diff --git a/C/bdfs.c b/C/bdfs.c deleted file mode 100644 index 096b154..0000000 --- a/C/bdfs.c +++ /dev/null @@ -1,171 +0,0 @@ -#include -#include -#define MAX 20 -typedef struct Q -{ - int data[MAX]; - int R,F; -}Q; -typedef struct node -{ - struct node *next; - int vertex; -}node; -void enqueue(Q *,int); -int dequque(Q *); -int empty(Q *); -int full(Q *); -void BFS(int); -void readgraph(); -void insert(int vi,int vj); -void DFS(int i); -int visited[MAX]; -node *G[20]; -int n; -void main() -{ - int i,op; - do - { - printf("\n\n1)Create\n2)BFS\n3)DFS\n4)Quit"); - printf("\nEnter Your Choice: "); - scanf("%d",&op); - switch(op) - { - case 1: readgraph();break; - case 2: printf("\nStarting Node No. : "); - scanf("%d",&i); - BFS(i);break; - case 3: for(i=0;inext) - { - w=p->vertex; - if(visited[w]==0) - { - enqueue(&q,w); - visited[w]=1; - printf("\nvisit\t%d",w); - } - } - } -} - -void DFS(int i) -{ - node *p; - printf("\n%d",i); - p=G[i]; - visited[i]=1; - while(p!=NULL) - { - i=p->vertex; - if(!visited[i]) - DFS(i); - p=p->next; - } -} - - -int empty(Q *P) -{ - if(P->R==-1) - return(1); - return(0); -} - -int full(Q *P) -{ - if(P->R==MAX-1) - return(1); - return(0); -} - -void enqueue(Q *P,int x) -{ - if(P->R==-1) - { - P->R=P->F=0; - P->data[P->R]=x; - } - else - { - P->R=P->R+1; - P->data[P->R]=x; - } -} - -int dequeue(Q *P) -{ - int x; - x=P->data[P->F]; - if(P->R==P->F) - { - P->R=-1; - P->F=-1; - } - else - P->F=P->F+1; - return(x); -} - -void readgraph() -{ int i,vi,vj,no_of_edges; - printf("\nEnter no. of vertices :"); - scanf("%d",&n); - //initialise G[] with NULL - for(i=0;ivertex=vj; - q->next=NULL; - //insert the node in the linked list for the vertex no. vi - if(G[vi]==NULL) - G[vi]=q; - else - { - // go to the end of linked list - p=G[vi]; - while(p->next!=NULL) - p=p->next; - p->next=q; - } -} diff --git a/C/bfs_graph.c b/C/bfs_graph.c deleted file mode 100644 index 3944865..0000000 --- a/C/bfs_graph.c +++ /dev/null @@ -1,175 +0,0 @@ -#include -#include -#define SIZE 40 - -struct queue { - int items[SIZE]; - int front; - int rear; -}; - -struct queue* createQueue(); -void enqueue(struct queue* q, int); -int dequeue(struct queue* q); -void display(struct queue* q); -int isEmpty(struct queue* q); -void printQueue(struct queue* q); - -struct node -{ - int vertex; - struct node* next; -}; - -struct node* createNode(int); - -struct Graph -{ - int numVertices; - struct node** adjLists; - int* visited; -}; - -struct Graph* createGraph(int vertices); -void addEdge(struct Graph* graph, int src, int dest); -void printGraph(struct Graph* graph); -void bfs(struct Graph* graph, int startVertex); - -int main() -{ - struct Graph* graph = createGraph(6); - addEdge(graph, 0, 1); - addEdge(graph, 0, 2); - addEdge(graph, 1, 2); - addEdge(graph, 1, 4); - addEdge(graph, 1, 3); - addEdge(graph, 2, 4); - addEdge(graph, 3, 4); - - bfs(graph, 0); - - return 0; -} - -void bfs(struct Graph* graph, int startVertex) { - - struct queue* q = createQueue(); - - graph->visited[startVertex] = 1; - enqueue(q, startVertex); - - while(!isEmpty(q)){ - printQueue(q); - int currentVertex = dequeue(q); - printf("Visited %d\n", currentVertex); - - struct node* temp = graph->adjLists[currentVertex]; - - while(temp) { - int adjVertex = temp->vertex; - - if(graph->visited[adjVertex] == 0){ - graph->visited[adjVertex] = 1; - enqueue(q, adjVertex); - } - temp = temp->next; - } - } -} - - -struct node* createNode(int v) -{ - struct node* newNode = malloc(sizeof(struct node)); - newNode->vertex = v; - newNode->next = NULL; - return newNode; -} - - -struct Graph* createGraph(int vertices) -{ - struct Graph* graph = malloc(sizeof(struct Graph)); - graph->numVertices = vertices; - - graph->adjLists = malloc(vertices * sizeof(struct node*)); - graph->visited = malloc(vertices * sizeof(int)); - - - int i; - for (i = 0; i < vertices; i++) { - graph->adjLists[i] = NULL; - graph->visited[i] = 0; - } - - return graph; -} - -void addEdge(struct Graph* graph, int src, int dest) -{ - // Add edge from src to dest - struct node* newNode = createNode(dest); - newNode->next = graph->adjLists[src]; - graph->adjLists[src] = newNode; - - // Add edge from dest to src - newNode = createNode(src); - newNode->next = graph->adjLists[dest]; - graph->adjLists[dest] = newNode; -} - -struct queue* createQueue() { - struct queue* q = malloc(sizeof(struct queue)); - q->front = -1; - q->rear = -1; - return q; -} - - -int isEmpty(struct queue* q) { - if(q->rear == -1) - return 1; - else - return 0; -} - -void enqueue(struct queue* q, int value){ - if(q->rear == SIZE-1) - printf("\nQueue is Full!!"); - else { - if(q->front == -1) - q->front = 0; - q->rear++; - q->items[q->rear] = value; - } -} - -int dequeue(struct queue* q){ - int item; - if(isEmpty(q)){ - printf("Queue is empty"); - item = -1; - } - else{ - item = q->items[q->front]; - q->front++; - if(q->front > q->rear){ - printf("Resetting queue"); - q->front = q->rear = -1; - } - } - return item; -} - -void printQueue(struct queue *q) { - int i = q->front; - - if(isEmpty(q)) { - printf("Queue is empty"); - } else { - printf("\nQueue contains \n"); - for(i = q->front; i < q->rear + 1; i++) { - printf("%d ", q->items[i]); - } - } -} diff --git a/C/binary_search b/C/binary_search deleted file mode 100644 index 1a2347d..0000000 --- a/C/binary_search +++ /dev/null @@ -1,42 +0,0 @@ -#include -#include -int main() -{ - int n,arr[100],i,search,flag=0; - printf("Enter the size of the array \n"); - scanf("%d",&n); - printf("Enter the array \n"); - for (i=0;i -#include -struct node -{ - int data; - struct node * left; - struct node * right; -}; -struct node * newnode( int data) -{ - struct node * node=(struct node*) malloc(sizeof(struct node)); - node->data=data; - node->left=NULL; - node->right=NULL; - return (node); -} -void postorder(struct node * node) -{ - if(node==NULL) - return; - postorder(node->left); - postorder(node->right); - printf("%d ", node->data); -} -void preorder(struct node * node) -{ - if(node==NULL) - return; - printf("%d ", node->data); - preorder(node->left); - preorder(node->right); -} -void main() -{ - struct node * root=newnode(1); - root->left=newnode(2); - root->right=newnode(3); - root->left->left=newnode(4); - root->left->right=newnode(5); - root->right->left=newnode(6); - root->right->right=newnode(7); - printf("POSTORDER TRAVERSAL OF BINARY TREE IS\n"); - postorder(root); - printf("\nPREORDER TRAVERSAL OF BINARY TREE IS\n"); - preorder(root); -} diff --git a/C/buuble_sort b/C/buuble_sort deleted file mode 100644 index bd2e090..0000000 --- a/C/buuble_sort +++ /dev/null @@ -1,33 +0,0 @@ -#include -#include - -int main() { - int size; - int * vector; - printf("size:"); - scanf("%d",&size); - - vector = (int *)calloc(size, sizeof(int)); - - for (int i = 0 ; i < size ; i++) { - printf("position %d: ", i); - scanf("%d",&vector[i]); - } - - for (int i = 0 ; i < size ; i++) { - for (int j = i ; j < size ; j++) { - if (vector[i] > vector[j]) { - int aux; - aux = vector[i]; - vector[i] = vector[j]; - vector[j] = aux; - } - } - } - - for (int i = 0 ; i < size ; i++) { - printf("%d ", vector[i]); - } - printf("\n"); - free(vector); -} diff --git a/C/calculater.c b/C/calculater.c deleted file mode 100644 index 32c52ea..0000000 --- a/C/calculater.c +++ /dev/null @@ -1,37 +0,0 @@ -#include -void main() -{ - char x; - float a, b, c=0; - printf("ENTER YOUR CHOICE\n(+)ADDITION\n(-)SUBSTRACTION\n(*)MULTIPLICATION\n(/)DIVISION\n"); - x=getchar(); - printf("ENETR FIRST NUMBER\n"); - printf("ENETR SECOND NUMBER\n"); - scanf("%f",&a); - scanf("%f",&b); - switch(x) - { - case '+' : - c=a+b; - printf("RESULT=%f",c); - break; - case '-' : - c=a-b; - printf("RESULT=%f",c); - break; - case '*' : - c=a*b; - printf("RESULT=%f",c); - break; - case '/' : - if(b==0) - { printf("DENOMINATOR CAN NOT BE 0\n"); - } - else - {c=a/b; - printf("RESULT=%f",c);} - break; - default : - printf("WRONG INPUT....\n PLEASE ENTER CORRECT OPERATION LIKE+-*/"); - } -} diff --git a/C/circular_doubly.c b/C/circular_doubly.c deleted file mode 100644 index bc60a28..0000000 --- a/C/circular_doubly.c +++ /dev/null @@ -1,385 +0,0 @@ -#include -#include - -struct node -{ - int val; - struct node *next; - struct node *prev; -}; -typedef struct node n; - -n* create_node(int); -void add_node(); -void insert_at_first(); -void insert_at_end(); -void insert_at_position(); -void delete_node_position(); -void sort_list(); -void update(); -void search(); -void display_from_beg(); -void display_in_rev(); - -n *new, *ptr, *prev; -n *first = NULL, *last = NULL; -int number = 0; - -void main() -{ - int ch; - - printf("\n linked list\n"); - printf("1.insert at beginning \n 2.insert at end\n 3.insert at position\n4.sort linked list\n 5.delete node at position\n 6.updatenodevalue\n7.search element \n8.displaylist from beginning\n9.display list from end\n10.exit "); - - while (1) - { - - printf("\n enter your choice:"); - scanf("%d", &ch); - switch (ch) - { - case 1 : - insert_at_first(); - break; - case 2 : - insert_at_end(); - break; - case 3 : - insert_at_position(); - break; - case 4 : - sort_list(); - break; - case 5 : - delete_node_position(); - break; - case 6 : - update(); - break; - case 7 : - search(); - break; - case 8 : - display_from_beg(); - break; - case 9 : - display_in_rev(); - break; - case 10 : - exit(0); - case 11 : - add_node(); - break; - default: - printf("\ninvalid choice"); - } - } -} -/* - *MEMORY ALLOCATED FOR NODE DYNAMICALLY - */ -n* create_node(int info) -{ - number++; - new = (n *)malloc(sizeof(n)); - new->val = info; - new->next = NULL; - new->prev = NULL; - return new; -} -/* - *ADDS NEW NODE - */ -void add_node() -{ - - int info; - - printf("\nenter the value you would like to add:"); - scanf("%d", &info); - new = create_node(info); - - if (first == last && first == NULL) - { - - first = last = new; - first->next = last->next = NULL; - first->prev = last->prev = NULL; - } - else - { - last->next = new; - new->prev = last; - last = new; - last->next = first; - first->prev = last; - } -} -/* - *INSERTS ELEMENT AT FIRST - */ -void insert_at_first() -{ - - int info; - - printf("\nenter the value to be inserted at first:"); - scanf("%d",&info); - new = create_node(info); - - if (first == last && first == NULL) - { - printf("\ninitially it is empty linked list later insertion is done"); - first = last = new; - first->next = last->next = NULL; - first->prev = last->prev = NULL; - } - else - { - new->next = first; - first->prev = new; - first = new; - first->prev = last; - last->next = first; - printf("\n the value is inserted at begining"); - } -} -/* - *INSERTS ELEMNET AT END - */ -void insert_at_end() -{ - - int info; - - printf("\nenter the value that has to be inserted at last:"); - scanf("%d", &info); - new = create_node(info); - - if (first == last && first == NULL) - { - printf("\ninitially the list is empty and now new node is inserted but at first"); - first = last = new; - first->next = last->next = NULL; - first->prev = last->prev = NULL; - } - else - { - last->next = new; - new->prev = last; - last = new; - first->prev = last; - last->next = first; - } -} -/* - *INSERTS THE ELEMENT AT GIVEN POSITION - */ -void insert_at_position() -{ - int info, pos, len = 0, i; - n *prevnode; - - printf("\n enter the value that you would like to insert:"); - scanf("%d", &info); - printf("\n enter the position where you have to enter:"); - scanf("%d", &pos); - new = create_node(info); - - if (first == last && first == NULL) - { - if (pos == 1) - { - first = last = new; - first->next = last->next = NULL; - first->prev = last->prev = NULL; - } - else - printf("\n empty linked list you cant insert at that particular position"); - } - else - { - if (number < pos) - printf("\n node cant be inserted as position is exceeding the linkedlist length"); - - else - { - for (ptr = first, i = 1;i <= number;i++) - { - prevnode = ptr; - ptr = ptr->next; - if (i == pos-1) - { - prevnode->next = new; - new->prev = prevnode; - new->next = ptr; - ptr->prev = new; - printf("\ninserted at position %d succesfully", pos); - break; - } - } - } - } -} -/* - *SORTING IS DONE OF ONLY NUMBERS NOT LINKS - */ -void sort_list() -{ - n *temp; - int tempval, i, j; - - if (first == last && first == NULL) - printf("\nlinked list is empty no elements to sort"); - else - { - for (ptr = first,i = 0;i < number;ptr = ptr->next,i++) - { - for (temp = ptr->next,j=i;jval > temp->val) - { - tempval = ptr->val; - ptr->val = temp->val; - temp->val = tempval; - } - } - } - for (ptr = first, i = 0;i < number;ptr = ptr->next,i++) - printf("\n%d", ptr->val); - } -} -/* - *DELETION IS DONE - */ -void delete_node_position() -{ - int pos, count = 0, i; - n *temp, *prevnode; - - printf("\n enter the position which u wanted to delete:"); - scanf("%d", &pos); - - if (first == last && first == NULL) - printf("\n empty linked list you cant delete"); - - else - { - if (number < pos) - printf("\n node cant be deleted at position as it is exceeding the linkedlist length"); - - else - { - for (ptr = first,i = 1;i <= number;i++) - { - prevnode = ptr; - ptr = ptr->next; - if (pos == 1) - { - number--; - last->next = prevnode->next; - ptr->prev = prevnode->prev; - first = ptr; - printf("%d is deleted", prevnode->val); - free(prevnode); - break; - } - else if (i == pos - 1) - { - number--; - prevnode->next = ptr->next; - ptr->next->prev = prevnode; - printf("%d is deleted", ptr->val); - free(ptr); - break; - } - } - } - } -} -/* - *UPDATION IS DONE FRO GIVEN OLD VAL - */ -void update() -{ - int oldval, newval, i, f = 0; - printf("\n enter the value old value:"); - scanf("%d", &oldval); - printf("\n enter the value new value:"); - scanf("%d", &newval); - if (first == last && first == NULL) - printf("\n list is empty no elemnts for updation"); - else - { - for (ptr = first, i = 0;i < number;ptr = ptr->next,i++) - { - if (ptr->val == oldval) - { - ptr->val = newval; - printf("value is updated to %d", ptr->val); - f = 1; - } - } - if (f == 0) - printf("\n no such old value to be get updated"); - } -} -/* - *SEARCHING USING SINGLE KEY - */ -void search() -{ - int count = 0, key, i, f = 0; - - printf("\nenter the value to be searched:"); - scanf("%d", &key); - - if (first == last && first == NULL) - printf("\nlist is empty no elemnets in list to search"); - else - { - for (ptr = first,i = 0;i < number;i++,ptr = ptr->next) - { - count++; - if (ptr->val == key) - { - printf("\n the value is found at position at %d", count); - f = 1; - } - } - if (f == 0) - printf("\n the value is not found in linkedlist"); - } -} -/* - *DISPLAYING IN BEGINNING - */ -void display_from_beg() -{ - int i; - if (first == last && first == NULL) - printf("\nlist is empty no elemnts to print"); - else - { - printf("\n%d number of nodes are there", number); - for (ptr = first, i = 0;i < number;i++,ptr = ptr->next) - printf("\n %d", ptr->val); - } -} -/* - * DISPLAYING IN REVERSE - */ -void display_in_rev() -{ - int i; - if (first == last && first == NULL) - printf("\nlist is empty there are no elments"); - else - { - for (ptr = last, i = 0;i < number;i++,ptr = ptr->prev) - { - printf("\n%d", ptr->val); - } - } -} diff --git a/C/concate.c b/C/concate.c deleted file mode 100644 index cc8c2eb..0000000 --- a/C/concate.c +++ /dev/null @@ -1,24 +0,0 @@ -#include -void concate(char *original, char *add) -{ - while(*original) - original++; - while(*add) - { - *original=*add; - add++; - original++; - } - *original=NULL; -} -void main() -{ - char original[100], add[100]; - printf("ENTER ORIGINAL STRING\n"); - gets(original); - printf("ENTER STRING TO CONCATENATE\n"); - gets(add); - concate(original, add); - printf("ENTER AFTER CONCATENATION IS \"%s\"\n",original); -} - diff --git a/C/cqueue.c b/C/cqueue.c deleted file mode 100644 index bfe7163..0000000 --- a/C/cqueue.c +++ /dev/null @@ -1,99 +0,0 @@ -#include -#include -#define max 5 -int q[10],front=0,rear=-1; -void insert() -{ - int x; - if((front==0&&rear==max-1)||(front>0&&rear==front-1)) - printf("Queue is overflow\n"); - else - { - printf("Enter element to be insert:"); - scanf("%d",&x); - if(rear==max-1&&front>0) - { - rear=0; - q[rear]=x; - } - else - { - if((front==0&&rear==-1)||(rear!=front-1)) - q[++rear]=x; - } - } -} -void delete() -{ - int a; - if((front==0)&&(rear==-1)) - { - printf("Queue is underflow\n"); - exit(0); - } - if(front==rear) - { - a=q[front]; - rear=-1; - front=0; - } - else - if(front==max-1) - { - a=q[front]; - front=0; - } - else a=q[front++]; - printf("Deleted element is:%d\n",a); -} - -void display() -{ - int i,j; - if(front==0&&rear==-1) - { - printf("Queue is underflow\n"); - exit(0); - } - if(front>rear) - { - for(i=0;i<=rear;i++) - printf("\t%d",q[i]); - for(j=front;j<=max-1;j++) - printf("\t%d",q[j]); - printf("\nrear is at %d\n",q[rear]); - printf("\nfront is at %d\n",q[front]); - } - else - { - for(i=front;i<=rear;i++) - { - printf("\t%d",q[i]); - } - printf("\nrear is at %d\n",q[rear]); - printf("\nfront is at %d\n",q[front]); - } - printf("\n"); -} -void main() -{ - int ch; - printf("\nCircular Queue operations\n"); - printf("1.insert\n2.delete\n3.display\n4.exit\n"); - while(1) - { - printf("Enter your choice:"); - scanf("%d",&ch); - switch(ch) - { - case 1: insert(); - break; - case 2: delete(); - break; - case 3:display(); - break; - case 4:exit(0); - default:printf("Invalid option\n"); - } - } -} diff --git a/C/crdllinklist.c b/C/crdllinklist.c deleted file mode 100644 index 6c41eca..0000000 --- a/C/crdllinklist.c +++ /dev/null @@ -1,139 +0,0 @@ -#include -#include -struct cr -{ - int data; - struct cr *next, *prev; -}s1,*node,*start,*end,*temp; -int count=0; -void construct() -{ - start=NULL;node=NULL;end=NULL; -} - -void insertb() -{ - int x; - printf("Enter the element:"); scanf("%d",&x); - count++; - - node=(struct cr *)malloc(sizeof(s1)); - node->data=x; - if(start==NULL) - { - start=node; - start->next=start; - start->prev=start; - end=node; - } - else - { - node->next=start; - end->next=node; - node->prev=end; - start->prev=node; - start=node; - } -} - -void inserte() -{ - int x; - printf("Enter the element:"); scanf("%d",&x); - count++; - node=(struct cr *)malloc(sizeof(s1)); - node->data=x; - if(start==NULL) - { - start=node; - start->next=start; - start->prev=start; - end=node; - } - else - { - node->next=start; - end->next=node; - node->prev=end; - start->prev=node; - end=node; - } -} - -void deletee() -{ - if(start==NULL) printf("Queue Underflow!!\n"); - else if(end==start) - { - temp=end; - free(temp); - start=NULL;end=NULL; - } - else - { - temp=end; - count--; - for(node=start;node->next->next!=start;node=node->next); - end=node; - end->next=start; - start->prev=end; - free(temp); - } -} - -void deleteb() -{ - if(start==NULL) printf("Queue Underflow!!\n"); - else if(end==start) - { - temp=end; - free(temp); - start=NULL;end=NULL; - } - else - { - temp=start; - count--; - start=start->next; - end->next=start; - start->prev=end; - free(temp); - } -} - -void display() -{ - int i; - if(start==NULL) - printf("\nQueue underflow!\n"); - else - { - printf("\nThe elements are:\n"); - //for(node=start;node!=start;node=node->next) - for(node=start,i=0;inext) - printf("%d ",node->data); - } -} -void main() -{ - int ch; - construct(); - while(1) - { - printf("\n\n***Circular Queue***\n1.Insert at beginning\n2.Insert at end\n3.Delete from begining\n4.Delete from end\n5.Display\n6.Exit\nEnter your choice:\n"); - scanf("%d",&ch); - switch(ch) - { - case 1: insertb(); break; - case 2: inserte(); break; - case 3: deleteb(); break; - case 4: deletee(); break; - case 5: display(); break; - case 6: exit(0); break; - default: printf("\nWrong Choice!!\n"); - } - } -} - - - diff --git a/C/dijkstra algo b/C/dijkstra algo deleted file mode 100644 index e6a8e0e..0000000 --- a/C/dijkstra algo +++ /dev/null @@ -1,76 +0,0 @@ -#include -#define INFINITY 9999 -#define MAX 10 -void dijkstra(int G[MAX][MAX],int n,int startnode); -int main() -{ - int G[MAX][MAX],i,j,n,u; - printf("Enter no. of vertices:"); - scanf("%d",&n); - printf("\nEnter the adjacency matrix:\n"); - - for(i=0;i -#include -struct node{ - int data; - struct node *next; -}; -struct node *head = NULL; -int counter = 0; - -struct node *makenode(int makedata); -void deleteeven(struct node *first); -void shownodes(struct node *first); - -int main(){ - int dataf, str = 1; - - if(head == NULL){ - printf("\nSince the list is empty, enter the list:"); - printf("\nEnter data for node: "); - scanf("%d", &dataf); - head = (struct node *)malloc(sizeof(struct node)); - head -> data = dataf; - counter++; - head -> next = NULL; - } - printf("\n Lets enter more nodes :- "); - - while(str == 1){ - counter++; - struct node *temp, *q; - q = head; - - printf("\nEnter data for node %d: ", counter); - scanf("%d",&dataf); - - while(q->next != NULL){ - q = q->next; - } - - temp = makenode(dataf); - - if(counter == 2){ - head -> next = temp; - } - - if(counter > 2){ - q -> next = temp; - } - - printf("\nWant to continue adding nodes: 1- yes, 0- no\n"); - scanf("%d", &str); - } - - deleteeven(head); - shownodes(head); - - return 0; -} - -struct node *makenode(int makedata){ - struct node *ptr; - ptr = (struct node *)malloc(sizeof(struct node)); - - if(ptr == NULL){ - printf("\nMemory not available."); - exit(1); - } - - ptr -> data = makedata; - ptr -> next = NULL; - return ptr; -} - -void deleteeven(struct node *first){ - struct node *q, *p, *temp; - q = first; - p = first; - - for(int i = 1; i < counter; i++){ - p = p-> next; - if(i % 2 != 0){ - q->next = p->next; - q = p; - temp = p; - continue; - } - q = q->next; - free(temp); - temp = NULL; - } - -} - -void shownodes(struct node *first){ - struct node *q; - q = first; - printf("\n"); - - while(q != NULL){ - if(q -> next == NULL){ - printf("%d\n",q -> data); - break; - } - printf("%d -> ", q -> data); - q = q -> next; - } -} diff --git a/C/fibonaci_using_recursion b/C/fibonaci_using_recursion deleted file mode 100644 index fa18e31..0000000 --- a/C/fibonaci_using_recursion +++ /dev/null @@ -1,20 +0,0 @@ - #include -void printFibonacci(int n){ - static int n1=0,n2=1,n3; - if(n>0){ - n3 = n1 + n2; - n1 = n2; - n2 = n3; - printf("%d ",n3); - printFibonacci(n-1); - } -} -int main(){ - int n; - printf("Enter the number of elements: "); - scanf("%d",&n); - printf("Fibonacci Series: "); - printf("%d %d ",0,1); - printFibonacci(n-2); - return 0; - } diff --git a/C/friends.c b/C/friends.c deleted file mode 100644 index 5b903c6..0000000 --- a/C/friends.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -int main(void) -{ - // Here we are using \v, which - // is vertical tab character. - printf("Hello friends"); - - printf("\v Welcome to GFG"); - - return (0); -} diff --git a/C/func_swap.c b/C/func_swap.c deleted file mode 100644 index b73a70f..0000000 --- a/C/func_swap.c +++ /dev/null @@ -1,20 +0,0 @@ -#include - -void swap(int *xp, int *yp) -{ - int temp = *xp; - *xp = *yp; - *yp = temp; -} - -int main() -{ - int x, y; - printf("Enter Value of x "); - scanf("%d", &x); - printf("\nEnter Value of y "); - scanf("%d", &y); - swap(&x, &y); - printf("\nAfter Swapping: x = %d, y = %d", x, y); - return 0; -} diff --git a/C/hashtable.c b/C/hashtable.c deleted file mode 100644 index e5ffc2a..0000000 --- a/C/hashtable.c +++ /dev/null @@ -1,357 +0,0 @@ -#include -#include -#include - -/* Node for storing an item in a Linked List */ -struct node -{ - int key; - int value; - struct node *next; -}; - -/* For storing a Linked List at each index of Hash Table */ -struct arrayitem -{ - - struct node *head; - /* head pointing the first element of Linked List at an index of Hash Table */ - - struct node *tail; - /* tail pointing the last element of Linked List at an index of Hash Table */ - -}; - -struct arrayitem *array; -int size = 0; /* Determines the no. of elements present in Hash Table */ -int max = 10; /* Determines the maximum capacity of Hash Table array */ - -/* This function creates an index corresponding to the every given key */ -int hashcode(int key) -{ - return (key % max); -} - -struct node* get_element(struct node *list, int find_index); -void remove_element(int key); -void rehash(); -void init_array(); - -void insert(int key, int value) -{ - float n = 0.0; - /* n => Load Factor, keeps check on whether rehashing is required or not */ - - int index = hashcode(key); - - /* Extracting Linked List at a given index */ - struct node *list = (struct node*) array[index].head; - - /* Creating an item to insert in the Hash Table */ - struct node *item = (struct node*) malloc(sizeof(struct node)); - item->key = key; - item->value = value; - item->next = NULL; - - if (list == NULL) - { - /* Absence of Linked List at a given Index of Hash Table */ - - printf("Inserting %d(key) and %d(value) \n", key, value); - array[index].head = item; - array[index].tail = item; - size++; - - } - else - { - /* A Linked List is present at given index of Hash Table */ - - int find_index = find(list, key); - if (find_index == -1) - { - /* - *Key not found in existing linked list - *Adding the key at the end of the linked list - */ - - array[index].tail->next = item; - array[index].tail = item; - size++; - - }else - { - /* - *Key already present in linked list - *Updating the value of already existing key - */ - - struct node *element = get_element(list, find_index); - element->value = value; - - } - - } - - //Calculating Load factor - n = (1.0 * size) / max; - if (n >= 0.75) - { - //rehashing - - printf("going to rehash\n"); - rehash(); - - } - -} - -void rehash() -{ - struct arrayitem *temp = array; - /* temp pointing to the current Hash Table array */ - - int i = 0, n = max; - size = 0; - max = 2 * max; - - /* - *array variable is assigned with newly created Hash Table - *with double of previous array size - */ - array = (struct arrayitem*) malloc(max * sizeof(struct node)); - init_array(); - - for (i = 0; i < n; i++) - { - - /* Extracting the Linked List at position i of Hash Table array */ - struct node* list = (struct node*) temp[i].head; - - if (list == NULL) - { - - /* if there is no Linked List, then continue */ - continue; - - } - else - { - /* - *Presence of Linked List at i - *Keep moving and accessing the Linked List item until the end. - *Get one key and value at a time and add it to new Hash Table array. - */ - - while (list != NULL) - { - insert(list->key, list->value); - list = list->next; - } - - } - - } - temp = NULL; -} - -/* - *This function finds the given key in the Linked List - *Returns it's index - *Returns -1 in case key is not present -*/ -int find(struct node *list, int key) -{ - int retval = 0; - struct node *temp = list; - while (temp != NULL) - { - if (temp->key == key) - { - return retval; - } - temp = temp->next; - retval++; - } - return -1; - -} - -/* Returns the node (Linked List item) located at given find_index */ -struct node* get_element(struct node *list, int find_index) -{ - int i = 0; - struct node *temp = list; - while (i != find_index) - { - temp = temp->next; - i++; - } - return temp; -} - -/* To remove an element from Hash Table */ -void remove_element(int key) -{ - int index = hashcode(key); - struct node *list = (struct node*) array[index].head; - - if (list == NULL) - { - printf("This key does not exists\n"); - - } - else - { - int find_index = find(list, key); - - if (find_index == -1) - { - printf("This key does not exists\n"); - - } - else - { - struct node *temp = list; - if (temp->key == key) - { - - array[index].head = temp->next; - printf("This key has been removed\n"); - return; - } - - while (temp->next->key != key) - { - temp = temp->next; - } - - if (array[index].tail == temp->next) - { - temp->next = NULL; - array[index].tail = temp; - - } - else - { - temp->next = temp->next->next; - - } - - printf("This key has been removed\n"); - - } - - } - -} - -/* To display the contents of Hash Table */ -void display() -{ - int i = 0; - for (i = 0; i < max; i++) - { - struct node *temp = array[i].head; - if (temp == NULL) - { - printf("array[%d] has no elements\n", i); - - } - else - { - printf("array[%d] has elements-: ", i); - while (temp != NULL) - { - printf("key= %d value= %d\t", temp->key, temp->value); - temp = temp->next; - } - printf("\n"); - - } - } -} - -/* For initializing the Hash Table */ -void init_array() -{ - int i = 0; - for (i = 0; i < max; i++) - { - array[i].head = NULL; - array[i].tail = NULL; - } - -} - -/* Returns size of Hash Table */ -int size_of_array() -{ - return size; -} - -void main() -{ - int choice, key, value, n, c; - clrscr(); - - array = (struct arrayitem*) malloc(max * sizeof(struct arrayitem*)); - init_array(); - - do { - printf("Implementation of Hash Table in C chaining with Singly Linked List \n\n"); - printf("MENU-: \n1.Inserting item in the Hash Table" - "\n2.Removing item from the Hash Table" - "\n3.Check the size of Hash Table" - "\n4.To display a Hash Table" - "\n\n Please enter your choice -: "); - - scanf("%d", &choice); - - switch(choice) - { - - case 1: - - printf("Inserting element in Hash Table\n"); - printf("Enter key and value-:\t"); - scanf("%d %d", &key, &value); - insert(key, value); - - break; - - case 2: - - printf("Deleting in Hash Table \nEnter the key to delete-:"); - scanf("%d", &key); - remove_element(key); - - break; - - case 3: - - n = size_of_array(); - printf("Size of Hash Table is-:%d\n", n); - - break; - - case 4: - - display(); - - break; - - default: - - printf("Wrong Input\n"); - - } - - printf("\nDo you want to continue-:(press 1 for yes)\t"); - scanf("%d", &c); - - }while(c == 1); - - getch(); - -} diff --git a/C/hello_world.c b/C/hello_world.c deleted file mode 100644 index 9e07b3c..0000000 --- a/C/hello_world.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -int main() -{ -printf("Hello world!"); - -return 0; -} diff --git a/C/hellouniverse.c b/C/hellouniverse.c deleted file mode 100644 index 60ca307..0000000 --- a/C/hellouniverse.c +++ /dev/null @@ -1,6 +0,0 @@ -#include -int main() -{ -printf("hello"); -return 0; -} diff --git a/C/insertion_sort b/C/insertion_sort deleted file mode 100644 index 9579172..0000000 --- a/C/insertion_sort +++ /dev/null @@ -1,50 +0,0 @@ -#include - -/* Function to sort an array using insertion sort*/ -void insertionSort(int arr[], int n) -{ - int i, key, j; - for (i = 1; i < n; i++) - { - key = arr[i]; - j = i - 1; - - /* Move elements of arr[0..i-1], that are - greater than key, to one position ahead - of their current position */ - while (j >= 0 && arr[j] > key) - { - arr[j + 1] = arr[j]; - j = j - 1; - } - arr[j + 1] = key; - } -} - - - - -/* Driver code */ -int main() -{ - - int number_of_elements; - printf("Enter the size of the array: \n"); - scanf("%d",&number_of_elements); - int array_unsorted[number_of_elements]; - int i; - printf("Enter the array elements: \n"); - for(i=0;i - #include - int main(){ - int a[10][10],b[10][10],mul[10][10],r,c,i,j,k; - system("cls"); - printf("enter the number of row="); - scanf("%d",&r); - printf("enter the number of column="); - scanf("%d",&c); - printf("enter the first matrix element=\n"); - for(i=0;i -#include - -// this function returns minimum of integer numbers passed. First -// argument is count of numbers. -int min(int arg_count, ...) -{ - int i; - int min, a; - - // va_list is a type to hold information about variable arguments - va_list ap; - - // va_start must be called before accessing variable argument list - va_start(ap, arg_count); - - // Now arguments can be accessed one by one using va_arg macro - // Initialize min as first argument in list - min = va_arg(ap, int); - - // traverse rest of the arguments to find out minimum - for(i = 2; i <= arg_count; i++) { - if((a = va_arg(ap, int)) < min) - min = a; - } - - //va_end should be executed before the function returns whenever - // va_start has been previously used in that function - va_end(ap); - - return min; -} - -int main() -{ - int count = 5; - - // Find minimum of 5 numbers: (12, 67, 6, 7, 100) - printf("Minimum value is %d", min(count, 12, 67, 6, 7, 100)); - getchar(); - return 0; -} diff --git a/C/oddeven.c b/C/oddeven.c deleted file mode 100644 index a750733..0000000 --- a/C/oddeven.c +++ /dev/null @@ -1,84 +0,0 @@ -#include -#include -struct Node -{ - int data; - struct Node *next; -}; -void segregateEvenOdd(struct Node **head_ref) -{ - struct Node *end = *head_ref; - struct Node *prev = NULL; - struct Node *curr = *head_ref; - while (end->next != NULL) - end = end->next; - struct Node *new_end = end; - while (curr->data %2 != 0 && curr != end) - { - new_end->next = curr; - curr = curr->next; - new_end->next->next = NULL; - new_end = new_end->next; - } - if (curr->data%2 == 0) - { - *head_ref = curr; - while (curr != end) - { - if ( (curr->data)%2 == 0 ) - { - prev = curr; - curr = curr->next; - } - else - { - prev->next = curr->next; - curr->next = NULL; - new_end->next = curr; - new_end = curr; - curr = prev->next; - } - } - } - else prev = curr; - if (new_end!=end && (end->data)%2 != 0) - { - prev->next = end->next; - end->next = NULL; - new_end->next = end; - } - return; -} -void push(struct Node** head_ref, int new_data) -{ - struct Node* new_node = - (struct Node*) malloc(sizeof(struct Node)); - new_node->data = new_data; - new_node->next = (*head_ref); - (*head_ref) = new_node; -} -void printList(struct Node *node) -{ - while (node!=NULL) - { - printf("%d ", node->data); - node = node->next; - } -} -int main() -{ - struct Node* head = NULL; - push(&head, 11); - push(&head, 10); - push(&head, 8); - push(&head, 6); - push(&head, 4); - push(&head, 2); - push(&head, 0); - printf("\nOriginal Linked list \n"); - printList(head); - segregateEvenOdd(&head); - printf("\nModified Linked list \n"); - printList(head); - return 0; -} diff --git a/C/printing.c b/C/printing.c deleted file mode 100644 index f4c9a3f..0000000 --- a/C/printing.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -int main(void) -{ - // Here we are using \n, which - // is a new line character. - printf("Hello\n"); - printf("GeeksforGeeks"); - return (0); -} diff --git a/C/recursion.c b/C/recursion.c deleted file mode 100644 index dd16f2c..0000000 --- a/C/recursion.c +++ /dev/null @@ -1,28 +0,0 @@ - -#include -#include - -int factorial(int n) -{ -if(n>1) -return(n*factorial(n-1)); -return 1; -} -int main() -{ -auto unsigned int n; -printf("Hi , I will find factorial for you \n"); -printf("Enter the number : "); -scanf("%d",&n); -if(n<=1) -{ -printf("The factorial of %d is 1",n); -return 0; -} -else -{ -printf("The factorial of %d is %ld",n,factorial(n)); -getch(); -return 0; -} -} diff --git a/C/simple_swap.c b/C/simple_swap.c deleted file mode 100644 index bb1f34e..0000000 --- a/C/simple_swap.c +++ /dev/null @@ -1,17 +0,0 @@ -#include - -int main() -{ - int x, y; - printf("Enter Value of x "); - scanf("%d\n", &x); - printf("Enter Value of y "); - scanf("%d\n", &y); - - int temp = x; - x = y; - y = temp; - - printf("\nAfter Swapping: x = %d, y = %d", x, y); - return 0; -} diff --git a/C/swap_without_temp.c b/C/swap_without_temp.c deleted file mode 100644 index 5cd9738..0000000 --- a/C/swap_without_temp.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -int main() -{ - int x = 10, y = 5; //sample - - - x = x + y; - y = x - y; - x = x - y; - - printf("After Swapping: x = %d, y = %d", x, y); - - return 0; -} diff --git a/CPP/Array/circularArrayRotation.cpp b/CPP/Array/circularArrayRotation.cpp deleted file mode 100644 index b2d607f..0000000 --- a/CPP/Array/circularArrayRotation.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - Problem Description : - array,a=[3,4,5] number of rotations,k=2 and indices to check,q=[1,2] . - First we perform the two rotations: - [3,4,5]-->[5,3,4]-->[4,5,3] - Now return the values from the zero-based indices 1 and 2 as indicated in the array. - a[1]=5 - a[2]=3 - - Constraints : - 1< n <10^5 | 1< a[i] <10^5 | 1< k <10^5 | 0<= q -using namespace std; -int main() -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - int m,n,q,i,j,k; - cin>>n>>m>>q; - m=m%n; - k=n-m; - //input a array - int arr[n],arr1[q]; - for(i=0;i>arr[i]; - } - //input position of array - for(i=0;i>arr1[i]; - } - int temp; - //Rotation Forward and Backward - if(m<=k){ - for(i=0;i0;j--) - { - - arr[j]=arr[j-1]; - - } - arr[0]=temp; - }} - else { - for(i=0;i -#include -using namespace std; - -int main() -{ - //cout << "Hello world!" << endl; - int t; - cin>>t; - while(t--){ - int n; - cin>>n; - double q[n]; - double p[n],x[n],l=0; - for(int i=0;i>p[i]>>q[i]>>x[i]; - l=l+(p[i]*x[i]*x[i]*q[i]*0.0001); - } - cout< -using namespace std; - -int main() { - int a,n,k; - cin>>a>>n>>k; - int * arr = new int[k](); - // use the modulo ! why iterating !!! and then keep dividing A by n+1 because n got used to nuke last - for(int i =0;i - - #include - - #include - - - - using namespace std; - - - - // Number of vertices in the graph - - #define V 5 - - - - // A utility function to find the vertex with minimum key value, from - - // the set of vertices not yet included in MST - - int minKey(int key[], bool mstSet[]) - - { - - // Initialize min value - - int min = INT_MAX, min_index; - - - - for (int v = 0; v < V; v++) - - if (mstSet[v] == false && key[v] < min) - - min = key[v], min_index = v; - - - - return min_index; - - } - - - - // A utility function to print the constructed MST stored in parent[] - - int printMST(int parent[], int n, int graph[V][V]) - - { - - cout<<"Edge Weight\n"; - - for (int i = 1; i < V; i++) - - printf("%d - %d %d \n", parent[i], i, graph[i][parent[i]]); - - } - - - - // Function to construct and print MST for a graph represented using adjacency - - // matrix representation - - void primMST(int graph[V][V]) - - { - - int parent[V]; // Array to store constructed MST - - int key[V]; // Key values used to pick minimum weight edge in cut - - bool mstSet[V]; // To represent set of vertices not yet included in MST - - - - // Initialize all keys as INFINITE - - for (int i = 0; i < V; i++) - - key[i] = INT_MAX, mstSet[i] = false; - - - - // Always include first 1st vertex in MST. - - key[0] = 0; // Make key 0 so that this vertex is picked as first vertex - - parent[0] = -1; // First node is always root of MST - - - - // The MST will have V vertices - - for (int count = 0; count < V - 1; count++) - - { - - // Pick thd minimum key vertex from the set of vertices - - // not yet included in MST - - int u = minKey(key, mstSet); - - - - // Add the picked vertex to the MST Set - - mstSet[u] = true; - - - - // Update key value and parent index of the adjacent vertices of - - // the picked vertex. Consider only those vertices which are not yet - - // included in MST - - for (int v = 0; v < V; v++) - - - - // graph[u][v] is non zero only for adjacent vertices of m - - // mstSet[v] is false for vertices not yet included in MST - - // Update the key only if graph[u][v] is smaller than key[v] - - if (graph[u][v] && mstSet[v] == false && graph[u][v] < key[v]) - - parent[v] = u, key[v] = graph[u][v]; - - } - - - - // print the constructed MST - - printMST(parent, V, graph); - - } - - - - // driver program to test above function - - int main() - - { - - /* Let us create the following graph - - 2 3 - - (0)--(1)--(2) - - | / \ | - - 6| 8/ \5 |7 - - | / \ | - - (3)-------(4) - - 9 */ - - int graph[V][V] = { { 0, 2, 0, 6, 0 }, { 2, 0, 3, 8, 5 }, - - { 0, 3, 0, 0, 7 }, { 6, 8, 0, 0, 9 }, { 0, 5, 7, 9, 0 }, }; - - - - // Print the solution - - primMST(graph); - - - - return 0; - - } \ No newline at end of file diff --git a/CPP/RSIGNS b/CPP/RSIGNS deleted file mode 100644 index dbd9028..0000000 --- a/CPP/RSIGNS +++ /dev/null @@ -1,39 +0,0 @@ -//RSIGNS - codechef - -#include -#define m 1000000007 -using namespace std; -int exponentMod(int A, int B, int C) -{ - if (A == 0) - return 0; - if (B == 0) - return 1; - long y; - if (B % 2 == 0) { - y = exponentMod(A, B / 2, C); - y = (y * y) % C; - } - else { - y = A % C; - y = (y * exponentMod(A, B - 1, C) % C) % C; - } - - return (int)((y + C) % C); -} - -int main() { - // your code goes here - int t; - cin>>t; - while(t--) - { - unsigned long long k,ans=1; - cin>>k; - //ans=pow(2,k-1)*10; - ans=exponentMod(2,k-1,m); - ans=(ans*10)%m; - cout< -using namespace std; -class process{ - public: - int at, bt, ct, tat, wt; - void input() - { - cout<<"enter at and bt\n"; - cin>>at>>bt; - } - void fcfs() - { - tat=ct-at; - wt=ct-at-bt; - } -}; -int main() -{ - process temp; - int i,j,n,ct=0; - float avgwt=0, avgtat=0; - cout<<"enter number of process:- "; - cin>>n; - process p[n]; - for(i=0;ip[j].at) - { - temp=p[i]; - p[i]=p[j]; - p[j]=temp; - } - } - for(i=0;i - -using namespace std; - -int main() { - - int x = 5, y = 7; - cout<<"Before swapping: x = "<< x <<" and y = "<< y << endl; - - x = x ^ y ^ (y = x); - cout<<"After swapping: x = "<< x <<" and y = "<< y << endl; - - return 0; -} - diff --git a/CPP/Swaping one line/Swaping_1_Line_Addition.cpp b/CPP/Swaping one line/Swaping_1_Line_Addition.cpp deleted file mode 100644 index ef3f1b3..0000000 --- a/CPP/Swaping one line/Swaping_1_Line_Addition.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include - -using namespace std; - -int main() { - - int x = 5, y = 7; - cout<<"Before swapping: x = "<< x <<" and y = "<< y << endl; - - x = (x + y) - (y = x); - cout<<"After swapping: x = "<< x <<" and y = "<< y << endl; - - return 0; -} - diff --git a/CPP/Swaping one line/Swaping_1_Line_Multiplication.cpp b/CPP/Swaping one line/Swaping_1_Line_Multiplication.cpp deleted file mode 100644 index 2bdfb3f..0000000 --- a/CPP/Swaping one line/Swaping_1_Line_Multiplication.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include - -using namespace std; - -int main() { - - int x = 5, y = 7; - cout<<"Before swapping: x = "<< x <<" and y = "<< y << endl; - - x = (x * y) / (y = x); - cout<<"After swapping: x = "<< x <<" and y = "<< y << endl; - - return 0; -} diff --git a/CPP/array_rotation.cpp b/CPP/array_rotation.cpp deleted file mode 100644 index ac4d27d..0000000 --- a/CPP/array_rotation.cpp +++ /dev/null @@ -1,42 +0,0 @@ -// C++ program to rotate an array by -// d elements -#include -using namespace std; - -/*Function to left Rotate arr[] of -size n by 1*/ -void leftRotatebyOne(int arr[], int n) -{ - int temp = arr[0], i; - for (i = 0; i < n - 1; i++) - arr[i] = arr[i + 1]; - - arr[i] = temp; -} - -/*Function to left rotate arr[] of size n by d*/ -void leftRotate(int arr[], int d, int n) -{ - for (int i = 0; i < d; i++) - leftRotatebyOne(arr, n); -} - -/* utility function to print an array */ -void printArray(int arr[], int n) -{ - for (int i = 0; i < n; i++) - cout << arr[i] << " "; -} - -/* Driver program to test above functions */ -int main() -{ - int arr[] = { 1, 2, 3, 4, 5, 6, 7 }; - int n = sizeof(arr) / sizeof(arr[0]); - - // Function calling - leftRotate(arr, 2, n); - printArray(arr, n); - - return 0; -} diff --git a/CPP/backtracking/NQueens.cpp b/CPP/backtracking/NQueens.cpp deleted file mode 100644 index 472aaa2..0000000 --- a/CPP/backtracking/NQueens.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include -#define N 4 -using namespace std; - -void printSolution(int board[N][N]) -{ - cout << "\n"; - for (int i = 0; i < N; i++) - { - for (int j = 0; j < N; j++) - cout << "" << board[i][j]; - cout << "\n"; - } -} - -bool isSafe(int board[N][N], int row, int col) -{ - int i, j; - - /* Check this row on left side */ - for (i = 0; i < col; i++) - if (board[row][i]) - return false; - - /* Check upper diagonal on left side */ - for (i = row, j = col; i >= 0 && j >= 0; i--, j--) - if (board[i][j]) - return false; - - /* Check lower diagonal on left side */ - for (i = row, j = col; j >= 0 && i < N; i++, j--) - if (board[i][j]) - return false; - - return true; -} - -void solveNQ(int board[N][N], int col) -{ - - if (col >= N) - { - printSolution(board); - return; - } - - /* Consider this column and try placing - this queen in all rows one by one */ - for (int i = 0; i < N; i++) - { - /* Check if queen can be placed on - board[i][col] */ - if (isSafe(board, i, col)) - { - /* Place this queen in board[i][col] */ - // cout<<"\n"< -using namespace std; -int main() -{ - int n,m; - cin>>n>>m; - int a[n],b[m]; - for(int i=0;i>a[i]; - } - for(int i=0;i>b[i]; - } - int cnt = 0; - for (int k=1; k<=100; k++) - { - int flag = 1; - for (int i=0; i -using namespace std; -int main () -{ - int n,a; - cin>>n>>a; - int arr[n]; - for(int i=0;i>arr[i]; - } - int sum=0,am=0; - cin>>am; - for(int i=0;i -using namespace std; - -// A utility function to swap two elements -void swap(int* a, int* b) -{ - int t = *a; - *a = *b; - *b = t; -} - -/* This function takes last element as pivot, places -the pivot element at its correct position in sorted -array, and places all smaller (smaller than pivot) -to left of pivot and all greater elements to right -of pivot */ -int partition (int arr[], int low, int high) -{ - int pivot = arr[high]; // pivot - int i = (low - 1); // Index of smaller element - - for (int j = low; j <= high - 1; j++) - { - // If current element is smaller than the pivot - if (arr[j] < pivot) - { - i++; // increment index of smaller element - swap(&arr[i], &arr[j]); - } - } - swap(&arr[i + 1], &arr[high]); - return (i + 1); -} - -/* The main function that implements QuickSort -arr[] --> Array to be sorted, -low --> Starting index, -high --> Ending index */ -void quickSort(int arr[], int low, int high) -{ - if (low < high) - { - /* pi is partitioning index, arr[p] is now - at right place */ - int pi = partition(arr, low, high); - - // Separately sort elements before - // partition and after partition - quickSort(arr, low, pi - 1); - quickSort(arr, pi + 1, high); - } -} - -/* 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[] = {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/CPP/branch_03_huffmann.cpp b/CPP/branch_03_huffmann.cpp deleted file mode 100644 index cdecef4..0000000 --- a/CPP/branch_03_huffmann.cpp +++ /dev/null @@ -1,299 +0,0 @@ -#include -#include -using namespace std; - -// This constant can be avoided by explicitly -// calculating height of Huffman Tree -#define MAX_TREE_HT 100 - -// A Huffman tree node -struct MinHeapNode { - - // One of the input characters - char data; - - // Frequency of the character - unsigned freq; - - // Left and right child of this node - struct MinHeapNode *left, *right; -}; - -// A Min Heap: Collection of -// min-heap (or Huffman tree) nodes -struct MinHeap { - - // Current size of min heap - unsigned size; - - // capacity of min heap - unsigned capacity; - - // Attay of minheap node pointers - struct MinHeapNode** array; -}; - -// A utility function allocate a new -// min heap node with given character -// and frequency of the character -struct MinHeapNode* newNode(char data, unsigned freq) -{ - struct MinHeapNode* temp - = (struct MinHeapNode*)malloc -(sizeof(struct MinHeapNode)); - - temp->left = temp->right = NULL; - temp->data = data; - temp->freq = freq; - - return temp; -} - -// A utility function to create -// a min heap of given capacity -struct MinHeap* createMinHeap(unsigned capacity) - -{ - - struct MinHeap* minHeap - = (struct MinHeap*)malloc(sizeof(struct MinHeap)); - - // current size is 0 - minHeap->size = 0; - - minHeap->capacity = capacity; - - minHeap->array - = (struct MinHeapNode**)malloc(minHeap-> -capacity * sizeof(struct MinHeapNode*)); - return minHeap; -} - -// A utility function to -// swap two min heap nodes -void swapMinHeapNode(struct MinHeapNode** a, - struct MinHeapNode** b) - -{ - - struct MinHeapNode* t = *a; - *a = *b; - *b = t; -} - -// The standard minHeapify function. -void minHeapify(struct MinHeap* minHeap, int idx) - -{ - - int smallest = idx; - int left = 2 * idx + 1; - int right = 2 * idx + 2; - - if (left < minHeap->size && minHeap->array[left]-> -freq < minHeap->array[smallest]->freq) - smallest = left; - - if (right < minHeap->size && minHeap->array[right]-> -freq < minHeap->array[smallest]->freq) - smallest = right; - - if (smallest != idx) { - swapMinHeapNode(&minHeap->array[smallest], - &minHeap->array[idx]); - minHeapify(minHeap, smallest); - } -} - -// A utility function to check -// if size of heap is 1 or not -int isSizeOne(struct MinHeap* minHeap) -{ - - return (minHeap->size == 1); -} - -// A standard function to extract -// minimum value node from heap -struct MinHeapNode* extractMin(struct MinHeap* minHeap) - -{ - - struct MinHeapNode* temp = minHeap->array[0]; - minHeap->array[0] - = minHeap->array[minHeap->size - 1]; - - --minHeap->size; - minHeapify(minHeap, 0); - - return temp; -} - -// A utility function to insert -// a new node to Min Heap -void insertMinHeap(struct MinHeap* minHeap, - struct MinHeapNode* minHeapNode) - -{ - - ++minHeap->size; - int i = minHeap->size - 1; - - while (i && minHeapNode->freq < minHeap->array[(i - 1) / 2]->freq) { - - minHeap->array[i] = minHeap->array[(i - 1) / 2]; - i = (i - 1) / 2; - } - - minHeap->array[i] = minHeapNode; -} - -// A standard function to build min heap -void buildMinHeap(struct MinHeap* minHeap) - -{ - - int n = minHeap->size - 1; - int i; - - for (i = (n - 1) / 2; i >= 0; --i) - minHeapify(minHeap, i); -} - -// A utility function to print an array of size n -void printArr(int arr[], int n) -{ - int i; - for (i = 0; i < n; ++i) - cout<< arr[i]; - - cout<<"\n"; -} - -// Utility function to check if this node is leaf -int isLeaf(struct MinHeapNode* root) - -{ - - return !(root->left) && !(root->right); -} - -// Creates a min heap of capacity -// equal to size and inserts all character of -// data[] in min heap. Initially size of -// min heap is equal to capacity -struct MinHeap* createAndBuildMinHeap(char data[], int freq[], int size) - -{ - - struct MinHeap* minHeap = createMinHeap(size); - - for (int i = 0; i < size; ++i) - minHeap->array[i] = newNode(data[i], freq[i]); - - minHeap->size = size; - buildMinHeap(minHeap); - - return minHeap; -} - -// The main function that builds Huffman tree -struct MinHeapNode* buildHuffmanTree(char data[], int freq[], int size) - -{ - struct MinHeapNode *left, *right, *top; - - // Step 1: Create a min heap of capacity - // equal to size. Initially, there are - // modes equal to size. - struct MinHeap* minHeap = createAndBuildMinHeap(data, freq, size); - - // Iterate while size of heap doesn't become 1 - while (!isSizeOne(minHeap)) { - - // Step 2: Extract the two minimum - // freq items from min heap - left = extractMin(minHeap); - right = extractMin(minHeap); - - // Step 3: Create a new internal - // node with frequency equal to the - // sum of the two nodes frequencies. - // Make the two extracted node as - // left and right children of this new node. - // Add this node to the min heap - // '$' is a special value for internal nodes, not used - top = newNode('$', left->freq + right->freq); - - top->left = left; - top->right = right; - - insertMinHeap(minHeap, top); - } - - // Step 4: The remaining node is the - // root node and the tree is complete. - return extractMin(minHeap); -} - -// Prints huffman codes from the root of Huffman Tree. -// It uses arr[] to store codes -void printCodes(struct MinHeapNode* root, int arr[], int top) - -{ - - // Assign 0 to left edge and recur - if (root->left) { - - arr[top] = 0; - printCodes(root->left, arr, top + 1); - } - - // Assign 1 to right edge and recur - if (root->right) { - - arr[top] = 1; - printCodes(root->right, arr, top + 1); - } - - // If this is a leaf node, then - // it contains one of the input - // characters, print the character - // and its code from arr[] - if (isLeaf(root)) { - - cout<< root->data <<": "; - printArr(arr, top); - } -} - -// The main function that builds a -// Huffman Tree and print codes by traversing -// the built Huffman Tree -void HuffmanCodes(char data[], int freq[], int size) - -{ - // Construct Huffman Tree - struct MinHeapNode* root - = buildHuffmanTree(data, freq, size); - - // Print Huffman codes using - // the Huffman tree built above - int arr[MAX_TREE_HT], top = 0; - - printCodes(root, arr, top); -} - -// Driver program to test above functions -int main() -{ - - char arr[] = { 'a', 'b', 'c', 'd', 'e', 'f' }; - int freq[] = { 5, 9, 12, 13, 16, 45 }; - - int size = sizeof(arr) / sizeof(arr[0]); - - HuffmanCodes(arr, freq, size); - - return 0; -} diff --git a/CPP/branch_04_borukva.cpp b/CPP/branch_04_borukva.cpp deleted file mode 100644 index fc95afb..0000000 --- a/CPP/branch_04_borukva.cpp +++ /dev/null @@ -1,218 +0,0 @@ -#include - -// a structure to represent a weighted edge in graph -struct Edge -{ - int src, dest, weight; -}; - -// a structure to represent a connected, undirected -// and weighted graph as a collection of edges. -struct Graph -{ - // V-> Number of vertices, E-> Number of edges - int V, E; - - // graph is represented as an array of edges. - // Since the graph is undirected, the edge - // from src to dest is also edge from dest - // to src. Both are counted as 1 edge here. - Edge* edge; -}; - -// A structure to represent a subset for union-find -struct subset -{ - int parent; - int rank; -}; - -// Function prototypes for union-find (These functions are defined -// after boruvkaMST() ) -int find(struct subset subsets[], int i); -void Union(struct subset subsets[], int x, int y); - -// The main function for MST using Boruvka's algorithm -void boruvkaMST(struct Graph* graph) -{ - // Get data of given graph - int V = graph->V, E = graph->E; - Edge *edge = graph->edge; - - // Allocate memory for creating V subsets. - struct subset *subsets = new subset[V]; - - // An array to store index of the cheapest edge of - // subset. The stored index for indexing array 'edge[]' - int *cheapest = new int[V]; - - // Create V subsets with single elements - for (int v = 0; v < V; ++v) - { - subsets[v].parent = v; - subsets[v].rank = 0; - cheapest[v] = -1; - } - - // Initially there are V different trees. - // Finally there will be one tree that will be MST - int numTrees = V; - int MSTweight = 0; - - // Keep combining components (or sets) until all - // compnentes are not combined into single MST. - while (numTrees > 1) - { - // Everytime initialize cheapest array - for (int v = 0; v < V; ++v) - { - cheapest[v] = -1; - } - - // Traverse through all edges and update - // cheapest of every component - for (int i=0; i edge[i].weight) - cheapest[set1] = i; - - if (cheapest[set2] == -1 || - edge[cheapest[set2]].weight > edge[i].weight) - cheapest[set2] = i; - } - } - - // Consider the above picked cheapest edges and add them - // to MST - for (int i=0; iV = V; - graph->E = E; - graph->edge = new Edge[E]; - return graph; -} - -// A utility function to find set of an element i -// (uses path compression technique) -int find(struct subset subsets[], int i) -{ - // find root and make root as parent of i - // (path compression) - if (subsets[i].parent != i) - subsets[i].parent = - find(subsets, subsets[i].parent); - - return subsets[i].parent; -} - -// A function that does union of two sets of x and y -// (uses union by rank) -void Union(struct subset subsets[], int x, int y) -{ - int xroot = find(subsets, x); - int yroot = find(subsets, y); - - // Attach smaller rank tree under root of high - // rank tree (Union by Rank) - if (subsets[xroot].rank < subsets[yroot].rank) - subsets[xroot].parent = yroot; - else if (subsets[xroot].rank > subsets[yroot].rank) - subsets[yroot].parent = xroot; - - // If ranks are same, then make one as root and - // increment its rank by one - else - { - subsets[yroot].parent = xroot; - subsets[xroot].rank++; - } -} - -// Driver program to test above functions -int main() -{ - /* Let us create following weighted graph - 10 - 0--------1 - | \ | - 6| 5\ |15 - | \ | - 2--------3 - 4 */ - int V = 4; // Number of vertices in graph - int E = 5; // Number of edges in graph - struct Graph* graph = createGraph(V, E); - - - // add edge 0-1 - graph->edge[0].src = 0; - graph->edge[0].dest = 1; - graph->edge[0].weight = 10; - - // add edge 0-2 - graph->edge[1].src = 0; - graph->edge[1].dest = 2; - graph->edge[1].weight = 6; - - // add edge 0-3 - graph->edge[2].src = 0; - graph->edge[2].dest = 3; - graph->edge[2].weight = 5; - - // add edge 1-3 - graph->edge[3].src = 1; - graph->edge[3].dest = 3; - graph->edge[3].weight = 15; - - // add edge 2-3 - graph->edge[4].src = 2; - graph->edge[4].dest = 3; - graph->edge[4].weight = 4; - - boruvkaMST(graph); - - return 0; -} diff --git a/CPP/day_of_programmer.cpp b/CPP/day_of_programmer.cpp deleted file mode 100644 index c287cea..0000000 --- a/CPP/day_of_programmer.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include -using namespace std; -int main() -{ - int y; - cin>>y; - if(y==1918) - {cout<<"26.09.1918";} - else if((y<1918 && y%4==0) || (y%4==0 && y%100!=0) || y%400==0) - { - cout<<"12.09."< -#include -#include - -// This is the recursive solution to our problem. -unsigned int fibonacci_naive(int n) { - if (n <= 1) - return n; - - return fibonacci_naive(n - 1) + fibonacci_naive(n - 2); -} - -/* - Here we are using Bottom-Up approach to solve the same problem. - - This simple optimization reduces time complexities from exponential to polynomial. -*/ -unsigned int fibonacci_fast(int n) { - // write your code here - std::vector fib = {0, 1}; - if (n == 0) - return fib[0]; - if (n == 1) - return fib[1]; - for (int index = 2; index <= n; ++index) - fib.push_back(fib[index - 1] + fib[index - 2]); - - return fib.back(); -} -/* - * Here we are using memorization approach to solve the same problem. - * - * This simple optimization reduces time complexities, but memory complexity increases, - * this method is very util when you need to compute various numbers, once you store - * the result and compute them only once -*/ -unsigned int fibonacci_memorization(int n) { - static std::vector table; // our cache - if (n <= 1) { - return n; - } else if (n >= table.size()) { - table.resize(n + 1); - } - - if (table[n] == 0) { - //recalc if we don't have a value - table[n] = fibonacci_memorization(n - 1) + fibonacci_memorization(n - 2); - } - return table[n]; -} - -/* - * Here we are using a equation to compute fib(n) - * fib(n) = ((1 + √5)/2)^(n+1)/√5 + 1/2 - * High values can break this, return 0 -*/ -unsigned int fibonacci_sublinear(int n) { - const double sqrt5 = std::sqrt(5); - double phi = (1 + sqrt(5)) / 2; - return (std::pow(phi, n) / sqrt5); -} - -/* - * Here we are using a equation to compute fib(n) - * fib(n) = ((1 + √5)/2)^(n+1)/√5 + 1/2 - * but precompute values, algo making 1/sqrt5 to mutiply and diferenciate - * to fibonacci_sublinear function - * High values can break this, return 0 -*/ -unsigned int fibonacci_const_sublinear(int n) { - const double inversesqrt5 = 0.44721359549995793928183473374626; - const double phi = 1.6180339887498948482045868343656; - return (std::pow(phi, n) * inversesqrt5 + 0.5); -} - -/* - * Here we are using iterative method to compute fib(n) -*/ -unsigned int fibonacci_iterative(int n) { - int n1 = 0, n2 = 1, fib, i; - if (n <= 1) - return n; - for (i = 2; i <= n; i++) { - fib = n1 + n2; - n1 = n2; - n2 = fib; - } - return fib; -} - -/* - * Here we are using matrix based method to compute fib(n) - * The matrix representation gives the following closed expression for the Fibonacci numbers: - * |1 1|^n = |fib(n+1) fib(n)| - * |1 0| |fib(n) fib(n-1)| -*/ - -//declare functions used in this method -void multiply(int F[2][2], int M[2][2]); -void power(int F[2][2], int n); - -unsigned int fibonacci_matrix(int n) { - int F[2][2] = {{1, 1}, {1, 0}}; - if (n == 0) - return 0; - power(F, n - 1); - return F[0][0]; -} - -/* function to realize power operation in a 2x2 matrix*/ -void power(int F[2][2], int n) { - if (n == 0 || n == 1) - return; - int M[2][2] = {{1, 1}, {1, 0}}; - - power(F, n / 2); - multiply(F, F); - - if (n % 2 != 0) - multiply(F, M); -} - -/* function to realize multiply operation in 2x2 matrix*/ -void multiply(int F[2][2], int M[2][2]) { - int x = F[0][0] * M[0][0] + F[0][1] * M[1][0]; - int y = F[0][0] * M[0][1] + F[0][1] * M[1][1]; - int z = F[1][0] * M[0][0] + F[1][1] * M[1][0]; - int w = F[1][0] * M[0][1] + F[1][1] * M[1][1]; - - F[0][0] = x; - F[0][1] = y; - F[1][0] = z; - F[1][1] = w; -} - -int main() { - int n = 0; - std::cin >> n; - - //std::cout << fibonacci_naive(n) << '\n'; - std::cout << fibonacci_fast(n) << '\n'; - std::cout << fibonacci_memorization(n) << '\n'; - std::cout << fibonacci_sublinear(n) << '\n'; - std::cout << fibonacci_const_sublinear(n) << '\n'; - std::cout << fibonacci_iterative(n) << '\n'; - std::cout << fibonacci_matrix(n) << '\n'; - return 0; -} diff --git a/CPP/fibonacci/fibonacci_huge.cpp b/CPP/fibonacci/fibonacci_huge.cpp deleted file mode 100644 index 352242e..0000000 --- a/CPP/fibonacci/fibonacci_huge.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* -Problem Description - Task : - Given two integers n and m, output Fn mod m (i.e, the remainder of Fn when divided by m). - - Input Format : - The input consists of two integers n and m given on the same line (separated by a space). - - Constraints : - 1 ≤ n ≤ 10^18, 2 ≤ m ≤ 10^5. - Output Format : - Output Fn mod m. - - Time Limit : 1 sec - - Memory Limit : 512MB - -Sample - Input : - 1 239 || 2816213588 30524 - Output : - 1 || 10249 - -Source : Algorithmic ToolBox by University of California San Diego & - National Research University Higher School of Economics (Coursera) - - Programming Assinment (Week 2) - -Detailed Explatnaion : https://medium.com/competitive/huge-fibonacci-number-modulo-m-6b4926a5c836 - -*/ - - - - -#include - -using std::cin; -using std::cout; - - - -long long get_pisano_period_length(long long m) { - long long F1 = 0, F2 = 1, F = F1 + F2; - for (int i = 0; i < m * m; i++) { - F = (F1 + F2) % m; - F1 = F2; - F2 = F; - if (F1 == 0 && F2 == 1) return i + 1; - } -} - -long long get_fibonacci_huge_fast(long long n, long long m) { - long long remainder = n % get_pisano_period_length(m); - - long long F1 = 0, F2 = 1, F = remainder; - for (int i = 1; i < remainder; i++) { - F = (F1 + F2) % m; - F1 = F2; - F2 = F; - } - return F % m; -} - -int main() { - long long n, m; - - std::cin >> n >> m; - std::cout << get_fibonacci_huge_fast(n, m) << '\n'; -} diff --git a/CPP/fork.cpp b/CPP/fork.cpp deleted file mode 100644 index 94bb81a..0000000 --- a/CPP/fork.cpp +++ /dev/null @@ -1,57 +0,0 @@ -//program to use the fork function of the STL - -#include -#include -#include -#include -#include -#include -using namespace std; - -int fibo(int n) -{ - int i; - if(n==0) return 0; - if(n==1) return 1; - else return fibo(n-1)+fibo(n-2); - -} -void fact(int n) -{ - long int prod=1; - for(;n>0;n--) - prod*=n; - cout<<"Factorial n = "<>n; - int pid=fork(); - if(pid<0) { cout<<"Child process can not be created!"< -#include -#include -#include -#include - -typedef std::vector> matrix; - -static int calc_cost(const matrix& a, const matrix& b) { - int tmp = 0; - for (size_t i = 0, j; i < a.size(); ++i) { - for (j = 0; j < a[i].size(); ++j) { - tmp += std::abs(a[i][j] - b[i][j]); - } - } - return tmp; -} - -int main() { - - static const size_t size = 3; - - matrix grid(size, std::vector(size)); - - for (auto& r : grid) { - for (auto& e : r) { - std::cin >> e; - } - } - - int cost = std::numeric_limits::max(); - - std::vector all = { - {{8, 1, 6}, {3, 5, 7}, {4, 9, 2}}, - {{6, 1, 8}, {7, 5, 3}, {2, 9, 4}}, - {{4, 9, 2}, {3, 5, 7}, {8, 1, 6}}, - {{2, 9, 4}, {7, 5, 3}, {6, 1, 8}}, - {{8, 3, 4}, {1, 5, 9}, {6, 7, 2}}, - {{4, 3, 8}, {9, 5, 1}, {2, 7, 6}}, - {{6, 7, 2}, {1, 5, 9}, {8, 3, 4}}, - {{2, 7, 6}, {9, 5, 1}, {4, 3, 8}} - }; - - for (auto& m : all) - cost = std::min(cost, calc_cost(grid, m)); - - - std::cout << cost << '\n'; - - - return 0; -} diff --git a/CPP/graphs/bfs.cpp b/CPP/graphs/bfs.cpp deleted file mode 100644 index fa7a449..0000000 --- a/CPP/graphs/bfs.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include -#include - -using namespace std; - -class Graph -{ - int V; - - - list *adj; -public: - Graph(int V); // Constructor - - - void addEdge(int v, int w); - - - void BFS(int s); -}; - -Graph::Graph(int V) -{ - this->V = V; - adj = new list[V]; -} - -void Graph::addEdge(int v, int w) -{ - adj[v].push_back(w); -} - -void Graph::BFS(int s) -{ - - bool *visited = new bool[V]; - for(int i = 0; i < V; i++) - visited[i] = false; - - - list queue; - - visited[s] = true; - queue.push_back(s); - - // 'i' will be used to get all adjacent - // vertices of a vertex - list::iterator i; - - while(!queue.empty()) - { - s = queue.front(); - cout << s << " "; - queue.pop_front(); - - - for (i = adj[s].begin(); i != adj[s].end(); ++i) - { - if (!visited[*i]) - { - visited[*i] = true; - queue.push_back(*i); - } - } - } -} - - -int main() -{ - - Graph g(4); - g.addEdge(0, 3); - g.addEdge(0, 2); - g.addEdge(1, 2); - g.addEdge(2, 0); - g.addEdge(2, 3); - g.addEdge(3, 3); - - cout << " Breadth First Traversal " - << "(starting from vertex 2) \n"; - g.BFS(2); - - return 0; -} diff --git a/CPP/graphs/dijkstra.cpp b/CPP/graphs/dijkstra.cpp deleted file mode 100644 index b15ce6f..0000000 --- a/CPP/graphs/dijkstra.cpp +++ /dev/null @@ -1,83 +0,0 @@ -#include - -typedef long long ll; - -#define pb push_back -#define MS(x,y) memset((x),(y),sizeof((x))) -#define mn 1000000 - -using namespace std; - -vector> pat[1001]; - -vector dijkstra(int s) { - vector dist(1001, INT_MAX); - dist[s] = 0; - - priority_queue> pq; - pq.push({0, s}); - - bool vis[1001]; - MS(vis, 0); - - while (!pq.empty()) { - int i = pq.top().second; - - pq.pop(); - - if (vis[i]) continue; - - vis[i] = true; - - for (auto it:pat[i]) { - int next = it.first, distBtwn = it.second; - - if (dist[next] > dist[i]+distBtwn) { - dist[next] = dist[i]+distBtwn; - - pq.push({-dist[next], next}); - } - } - } - - return dist; -} - -int main() -{ - int n,m; - - cin>>n>>m; - - for (int i = 0; i>a>>b>>c; - - pat[a].pb({b,c}); - } - - int s; - - cin>>s; - - vector dist = dijkstra(s); - - for (int i = 0; i -#include - -using std::vector; - -int get_max_index(vector weights, vector values) { - int max_i = 0; - double max = 0; - - for (int i = 0; i < weights.size(); i++) { - if (weights[i] != 0 && (double) values[i] / weights[i] > max) { - max = (double) values[i] / weights[i]; - max_i = i; - } - } - return max_i; -} - -double get_optimal_value(int capacity, vector weights, vector values) { - double value = 0.0; - - for (int i = 0; i < weights.size(); i++) { - if (capacity == 0) return value; - int index = get_max_index(weights, values); - int a = std::min(capacity, weights[index]); - value += a * (double) values[index] / weights[index]; - weights[index] -= a; - capacity -= a; - } - - return value; -} - -int main() { - int n; - int capacity; - std::cin >> n >> capacity; - vector values(n); - vector weights(n); - for (int i = 0; i < n; i++) { - std::cin >> values[i] >> weights[i]; - } - - double optimal_value = get_optimal_value(capacity, weights, values); - - std::cout.precision(10); - std::cout << optimal_value << std::endl; - return 0; -} diff --git a/CPP/greedyAlgorithms/fractional_knapsack/fractional_knapsack.txt b/CPP/greedyAlgorithms/fractional_knapsack/fractional_knapsack.txt deleted file mode 100644 index 55d4d9f..0000000 --- a/CPP/greedyAlgorithms/fractional_knapsack/fractional_knapsack.txt +++ /dev/null @@ -1,43 +0,0 @@ -Problem Introduction - A thief finds much more loot than his bag can fit. Help him to find the most valuable - combination of items assuming that any fraction of a loot item can be put into his bag. - -Problem Description - Task : The goal of this code problem is to implement an algorithm for the fractional knapsack - problem. - - Input Format : The first line of the input contains the number n of items and the capacity W - of a knapsack. The next n lines define the values and weights of the items. - The i-th line contains integers vi and wi the value and the weight of i-th item, - respectively. - - Constarints : 1 ≤ n ≤ 10^3, 0 ≤ W ≤ 2·10^6; 0 ≤ vi ≤ 2·10^6, 0 < wi ≤ 2·10^6 for all 1 ≤ i ≤ n. - All the numbers are integers. - - Output Format : Output the maximal value of fractions of items that fit into the knapsack. The - absolute value of the difference between the answer of your program and the - optimal value should be at most 10−3. To ensure this, output your answer with at - least four digits after the decimal point (otherwise your answer, while being - computed correctly, can turn out to be wrong because of rounding issues). - - Time Limit : 1 sec - - Memory Limit : 512MB - -Sample Output - Input : - 3 50 - 60 20 - 100 50 - 120 30 - - Output : - 180.0000 - - Explanation : To achieve the value 180, we take the first item and the third item into the bag. - - -Source : Algorithmic ToolBox by University of California San Diego & - National Research University Higher School of Economics (Coursera) - - Programming Assinment (Week 3) diff --git a/CPP/hello world b/CPP/hello world deleted file mode 100644 index c2bff56..0000000 --- a/CPP/hello world +++ /dev/null @@ -1,7 +0,0 @@ -#include -using namespace std; -int main() -{ - cout<<"Hello World!"; - return 0; -} diff --git a/CPP/inherited_code.cpp b/CPP/inherited_code.cpp deleted file mode 100644 index c9b9810..0000000 --- a/CPP/inherited_code.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include -#include -#include -#include -using namespace std; - -/* Define the exception here */ -class BadLengthException : public exception { -public: - BadLengthException(int length) - { - len=length; - } - - virtual const int what() - { - return len; - } -private: - int len=0; -}; - -bool checkUsername(string username) { - bool isValid = true; - int n = username.length(); - if(n < 5) { - throw BadLengthException(n); - } - for(int i = 0; i < n-1; i++) { - if(username[i] == 'w' && username[i+1] == 'w') { - isValid = false; - } - } - return isValid; -} - -int main() { - int T; cin >> T; - while(T--) { - string username; - cin >> username; - try { - bool isValid = checkUsername(username); - if(isValid) { - cout << "Valid" << '\n'; - } else { - cout << "Invalid" << '\n'; - } - } catch (BadLengthException e) { - cout << "Too short: " << e.what() << '\n'; - } - } - return 0; -} diff --git a/CPP/linklist.cpp b/CPP/linklist.cpp deleted file mode 100644 index b77490d..0000000 --- a/CPP/linklist.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include -using namespace std; - -// Representation of a node -struct Node { - int data; - Node* next; -}; - -// Function to insert node -void insert(Node** root, int item) -{ - Node* temp = new Node; - Node* ptr; - temp->data = item; - temp->next = NULL; - - if (*root == NULL) - *root = temp; - else { - ptr = *root; - while (ptr->next != NULL) - ptr = ptr->next; - ptr->next = temp; - } -} - -void display(Node* root) -{ - while (root != NULL) { - cout << root->data << " "; - root = root->next; - } -} - -Node *arrayToList(int arr[], int n) -{ - Node *root = NULL; - for (int i = 0; i < n; i++) - insert(&root, arr[i]); -return root; -} - -// Driver code -int main() -{ - int arr[] = { 1, 2, 3, 4, 5 }; - int n = sizeof(arr) / sizeof(arr[0]); - Node* root = arrayToList(arr, n); - display(root); - return 0; -} diff --git a/CPP/rajat.c++ b/CPP/rajat.c++ deleted file mode 100644 index f1ea5b9..0000000 --- a/CPP/rajat.c++ +++ /dev/null @@ -1 +0,0 @@ -#algorithms diff --git a/CPP/search/README.md b/CPP/search/README.md deleted file mode 100644 index 8b13789..0000000 --- a/CPP/search/README.md +++ /dev/null @@ -1 +0,0 @@ - diff --git a/CPP/search/binary_search.cpp b/CPP/search/binary_search.cpp deleted file mode 100644 index e172294..0000000 --- a/CPP/search/binary_search.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#include - -using namespace std; - -// A function implementing Binary search on a sorted array. -int BinarySearch(int a[], int start, int end, int item, int iter) -{ - int i, mid; - iter++; - // Assigning middle of the array. - mid = start + (end-start+1)/2; - // If value is less than value at start index more than end index then item is not in the array. - if(item > a[end] || item < a[start] || mid == end) - { - cout<<"\nNot found"; - return -1; - } - // Return the mid index. - else if(item == a[mid]) - { - return mid; - } - // Return the start index. - else if(item == a[start]) - { - return start; - } - // Return the end index. - else if(item == a[end]) - { - return end; - } - // According to the item value choose the partion to proceed further. - else if(item > a[mid]) - BinarySearch(a, mid, 19, item, iter); - else - BinarySearch(a, start, mid, item, iter); -} - -int main() -{ - int n, i, flag=0, Bindex, a[20]={1, 9, 18, 24, 27, 35, 38, 41, 49, 53, 55, 66, 67, 72, 75, 77, 81, 89, 90, 97}; - cout<<"\nEnter the number of element in the search sequence: "; - cin>>n; - int s[n]; - for(i = 0; i < n; i++) - cin>>s[i]; - - // Get the index of the first value in the search sequence found in data set array. - Bindex = BinarySearch(a, 0, 19, s[0], 0); - - if(Bindex == -1) - { - // if return index is -1 then not found. - cout<<"\nNot found."; - return 0; - } - else - { - // If first value found then check for others sequentially. - for(i = Bindex; i < n+Bindex; i++) - if(a[i] != s[i-Bindex]) - flag = 5; - - if(flag == 5) - cout<<"\nNot found."; - else - cout<<"\nSequence found between index "< -#include - -/* Function to fill Vector */ -void make_vector(std::vector& v) -{ - int num, val; - - std::cout << "Enter the number of elements in vector "; - std::cin >> num; - for (int i = 0; i < num; i++) - { - std::cin >> val; - v.push_back(val); - } -} - -/* Linear Search Function */ -int lin_search(std::vector v, int val) -{ - int key = -1; - for (int i = 0; i < v.size(); i++) - { - if (v[i] == val) - { - key = i; - break; - } - } - return key; -} - -int main() -{ - int key, val; - std::vector v; - - make_vector(v); - std::cout << "Enter the number : "; - std::cin >> val; - key = lin_search(v, val); - if (key != -1) - std::cout << "\nElement " << val - << " is at position " << ++key; - else - std::cout << "\nElement " << val - << " is not present"; -} diff --git a/CPP/search/segment_tree.cpp b/CPP/search/segment_tree.cpp deleted file mode 100644 index 23f0a68..0000000 --- a/CPP/search/segment_tree.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include - -typedef long long ll; - -#define pb push_back -#define MS(x,y) memset((x),(y),sizeof((x))) -#define mn 1000000 - -using namespace std; - -int tree[1000001]; - -void update (int pos, int value, int interval_index, int interval_left, int interval_right) { - if (interval_left > pos || interval_right < pos || interval_left > interval_right) return; - - if (interval_left == interval_right) { - if (interval_left == pos) tree[interval_index] = value; - - return; - } - - int mid = (interval_left + interval_right) / 2; - update(pos, value, 2*interval_index, interval_left, mid); - update(pos, value, 2*interval_index+1, mid+1, interval_right); - - tree[interval_index] = tree[2*interval_index] + tree[2*interval_index+1]; -} - -int query (int from, int to, int interval_index, int interval_left, int interval_right) { - if (interval_left > to || interval_right < from || interval_left > interval_right) return 0; - - if (from <= interval_left && interval_right <= to) return tree[interval_index]; - - int mid = (interval_left + interval_right) / 2; - - return query(from, to, 2*interval_index, interval_left, mid) + query(from, to, 2*interval_index+1, mid+1, interval_right); -} - -int main() -{ - MS(tree, 0); - - int n; - - cin>>n; - - int niza[n]; - - for (int i = 0; i>niza[i]; - - update(i, niza[i], 1, 0, n-1); - } - - int m; - - cin>>m; - - for (int i = 0; i>a>>b>>c; - - if (a == 0) { - //change, c na pos b - - update(b, c, 1, 0, n-1); - } else { - //query b to c - - cout< -using namespace std; - -// To check if array is sorted or not -bool isSorted(int a[], int n) -{ - while ( --n > 1 ) - if (a[n] < a[n-1]) - return false; - return true; -} - -// To generate permuatation of the array -void shuffle(int a[], int n) -{ - for (int i=0; i < n; i++) - swap(a[i], a[rand()%n]); -} - -// Sorts array a[0..n-1] using Bogo sort -void bogosort(int a[], int n) -{ - // if array is not sorted then shuffle - // the array again - while ( !isSorted(a, n) ) - shuffle(a, n); -} - -// prints the array -void printArray(int a[], int n) -{ - for (int i=0; i - -using namespace std; - -// Sort arr[] of size n using Bubble Sort. -void BubbleSort (int arr[], int n) -{ - int i, j; - for (i = 0; i < n; ++i) - { - for (j = 0; j < n-i-1; ++j) - { - // Comparing consecutive data and switching values if value at j > j+1. - if (arr[j] > arr[j+1]) - { - arr[j] = arr[j]+arr[j+1]; - arr[j+1] = arr[j]-arr[j + 1]; - arr[j] = arr[j]-arr[j + 1]; - } - } - // Value at n-i-1 will be maximum of all the values below this index. - } -} - -int main() -{ - int n, i; - cout<<"\nEnter the number of data element to be sorted: "; - cin>>n; - - int arr[n]; - for(i = 0; i < n; i++) - { - cout<<"Enter element "<>arr[i]; - } - - BubbleSort(arr, n); - - // Display the sorted data. - cout<<"\nSorted Data "; - for (i = 0; i < n; i++) - cout<<"->"< -using namespace std; - -struct process{ - int arr_t, bur_t, comp_t, tat, wait_t; - string pro_id; -}; - -bool compare_arr_t(process a,process b) -{ - return a.arr_t>n; - process p[10]; - cout<<"\nEnter the arrival time and burst time respectively of each process::\n"; - for(i=0;i(i); - p[i].pro_id = 'A' + c; - cout<<"P"<>p[i].arr_t; - cout<<"\tBurst Time: "; - cin>>p[i].bur_t; - } - //cout<<"\n"; - sort(p,p+n,compare_arr_t); - for(i=0;i - -using namespace std; - -// A function to heapify the array. -void MaxHeapify(int a[], int i, int n) -{ - int j, temp; - temp = a[i]; - j = 2*i; - - while (j <= n) - { - if (j < n && a[j+1] > a[j]) - j = j+1; - // Break if parent value is already greater than child value. - if (temp > a[j]) - break; - // Switching value with the parent node if temp < a[j]. - else if (temp <= a[j]) - { - a[j/2] = a[j]; - j = 2*j; - } - } - a[j/2] = temp; - return; -} -void HeapSort(int a[], int n) -{ - int i, temp; - for (i = n; i >= 2; i--) - { - // Storing maximum value at the end. - temp = a[i]; - a[i] = a[1]; - a[1] = temp; - // Building max heap of remaining element. - MaxHeapify(a, 1, i - 1); - } -} -void Build_MaxHeap(int a[], int n) -{ - int i; - for(i = n/2; i >= 1; i--) - MaxHeapify(a, i, n); -} -int main() -{ - int n, i; - cout<<"\nEnter the number of data element to be sorted: "; - cin>>n; - n++; - int arr[n]; - for(i = 1; i < n; i++) - { - cout<<"Enter element "<>arr[i]; - } - // Building max heap. - Build_MaxHeap(arr, n-1); - HeapSort(arr, n-1); - - // Printing the sorted data. - cout<<"\nSorted Data "; - - for (i = 1; i < n; i++) - cout<<"->"< - -using namespace std; - -// Sort arr[] of size n using Bubble Sort. -void BubbleSort (int arr[], int n) -{ - int i, j; - for (i = 0; i < n; ++i) - { - for (j = 0; j < n-i-1; ++j) - { - // Comparing consecutive data and switching values if value at j > j+1. - if (arr[j] > arr[j+1]) - { - arr[j] = arr[j]+arr[j+1]; - arr[j+1] = arr[j]-arr[j + 1]; - arr[j] = arr[j]-arr[j + 1]; - } - } - // Value at n-i-1 will be maximum of all the values below this index. - } -} - -int main() -{ - int n, i; - cout<<"\nEnter the number of data element to be sorted: "; - cin>>n; - - int arr[n]; - for(i = 0; i < n; i++) - { - cout<<"Enter element "<>arr[i]; - } - - BubbleSort(arr, n); - - // Display the sorted data. - cout<<"\nSorted Data "; - for (i = 0; i < n; i++) - cout<<"->"<>num; - // Inserting num in the list. - head = InsertinList(head, num); - } - - // Display the sorted data. - cout<<"\nSorted Data "; - while(head != NULL) - { - cout<<"->"<data; - head = head->next; - } - - return 0; -} diff --git a/CPP/sorting/merge_sort.cpp b/CPP/sorting/merge_sort.cpp deleted file mode 100644 index 935b658..0000000 --- a/CPP/sorting/merge_sort.cpp +++ /dev/null @@ -1,92 +0,0 @@ -#include - -using namespace std; - -// A function to merge the two half into a sorted data. -void Merge(int *a, int low, int high, int mid) -{ - // We have low to mid and mid+1 to high already sorted. - int i, j, k, temp[high-low+1]; - i = low; - k = 0; - j = mid + 1; - - // Merge the two parts into temp[]. - while (i <= mid && j <= high) - { - if (a[i] < a[j]) - { - temp[k] = a[i]; - k++; - i++; - } - else - { - temp[k] = a[j]; - k++; - j++; - } - } - - // Insert all the remaining values from i to mid into temp[]. - while (i <= mid) - { - temp[k] = a[i]; - k++; - i++; - } - - // Insert all the remaining values from j to high into temp[]. - while (j <= high) - { - temp[k] = a[j]; - k++; - j++; - } - - - // Assign sorted data stored in temp[] to a[]. - for (i = low; i <= high; i++) - { - a[i] = temp[i-low]; - } -} - -// A function to split array into two parts. -void MergeSort(int *a, int low, int high) -{ - int mid; - if (low < high) - { - mid=(low+high)/2; - // Split the data into two half. - MergeSort(a, low, mid); - MergeSort(a, mid+1, high); - - // Merge them to get sorted output. - Merge(a, low, high, mid); - } -} - -int main() -{ - int n, i; - cout<<"\nEnter the number of data element to be sorted: "; - cin>>n; - - int arr[n]; - for(i = 0; i < n; i++) - { - cout<<"Enter element "<>arr[i]; - } - - MergeSort(arr, 0, n-1); - - // Printing the sorted data. - cout<<"\nSorted Data "; - for (i = 0; i < n; i++) - cout<<"->"< -#include -#include - -using std::vector; -using std::swap; - -vector quick_sort_partition3(vector &a, int l, int r) { - int x = a[l]; - int p_l = l; - int i = l; - int p_e = r; - vector m(2); - while (i <= p_e) { - if (a[i] < x) { - swap(a[p_l], a[i]); - p_l++; - i++; - } else if (a[i] == x) { - i++; - } else { - swap(a[i], a[p_e]); - p_e -= 1; - } - m[0] = p_l; - m[1] = p_e; - } - return m; -} - -int partition2(vector &a, int l, int r) { - int x = a[l]; - int j = l; - for (int i = l + 1; i <= r; i++) { - if (a[i] <= x) { - j++; - swap(a[i], a[j]); - } - } - swap(a[l], a[j]); - return j; -} - -void randomized_quick_sort(vector &a, int l, int r) { - if (l >= r) { - return; - } - - int k = l + rand() % (r - l + 1); - swap(a[l], a[k]); - vector m = quick_sort_partition3(a, l, r); - - randomized_quick_sort(a, l, m[0] - 1); - randomized_quick_sort(a, m[1] + 1, r); -} - -int main() { - int n; - std::cin >> n; - vector a(n); - for (size_t i = 0; i < a.size(); ++i) { - std::cin >> a[i]; - } - randomized_quick_sort(a, 0, a.size() - 1); - for (size_t i = 0; i < a.size(); ++i) { - std::cout << a[i] << ' '; - } -} diff --git a/CPP/sorting/quick_sort.cpp b/CPP/sorting/quick_sort.cpp deleted file mode 100644 index 312f9c8..0000000 --- a/CPP/sorting/quick_sort.cpp +++ /dev/null @@ -1,87 +0,0 @@ -#include -#include - -using namespace std; - -// Swapping two values. -void swap(int *a, int *b) -{ - int temp; - temp = *a; - *a = *b; - *b = temp; -} - -// Partitioning the array on the basis of values at high as pivot value. -int Partition(int a[], int low, int high) -{ - int pivot, index, i; - index = low; - pivot = high; - - // Getting index of pivot. - for(i=low; i < high; i++) - { - if(a[i] < a[pivot]) - { - swap(&a[i], &a[index]); - index++; - } - } - // Swapping value at high and at the index obtained. - swap(&a[pivot], &a[index]); - - return index; -} - -// Random selection of pivot. -int RandomPivotPartition(int a[], int low, int high) -{ - int pvt, n, temp; - n = rand(); - // Randomizing the pivot value in the given subpart of array. - pvt = low + n%(high-low+1); - - // Swapping pvt value from high, so pvt value will be taken as pivot while partitioning. - swap(&a[high], &a[pvt]); - - return Partition(a, low, high); -} - -// Implementing QuickSort algorithm. -int QuickSort(int a[], int low, int high) -{ - int pindex; - if(low < high) - { - // Partitioning array using randomized pivot. - pindex = RandomPivotPartition(a, low, high); - // Recursively implementing QuickSort. - QuickSort(a, low, pindex-1); - QuickSort(a, pindex+1, high); - } - return 0; -} - -int main() -{ - int n, i; - cout<<"\nEnter the number of data element to be sorted: "; - cin>>n; - - int arr[n]; - for(i = 0; i < n; i++) - { - cout<<"Enter element "<>arr[i]; - } - - QuickSort(arr, 0, n-1); - - // Printing the sorted data. - cout<<"\nSorted Data "; - for (i = 0; i < n; i++) - cout<<"->"< -using namespace std; - -int getMax(int arr[], int n) -{ - int mx = arr[0]; - for (int i = 1; i < n; i++) - if (arr[i] > mx) - mx = arr[i]; - return mx; -} - -//Counting Sort -void countSort(int arr[], int n, int exp) -{ - int output[n]; // output array - int i, count[10] = {0}; - - // Store count of occurrences in count[] - for (i = 0; i < n; i++) - count[ (arr[i]/exp)%10 ]++; - - // Change count[i] so that count[i] now contains actual - // position of this digit in output[] - for (i = 1; i < 10; i++) - count[i] += count[i - 1]; - - // Build the output array - for (i = n - 1; i >= 0; i--) - { - output[count[ (arr[i]/exp)%10 ] - 1] = arr[i]; - count[ (arr[i]/exp)%10 ]--; - } - - // Copy the output array to arr[], so that arr[] now - // contains sorted numbers according to current digit - for (i = 0; i < n; i++) - arr[i] = output[i]; -} - -// Radix Sort -void radixsort(int arr[], int n) -{ - // Find the maximum number to know number of digits - int m = getMax(arr, n); - - // Do counting sort for every digit. Note that instead - // of passing digit number, exp is passed. exp is 10^i - // where i is current digit number - for (int exp = 1; m/exp > 0; exp *= 10) - countSort(arr, n, exp); -} - -void print(int arr[], int n) -{ - for (int i = 0; i < n; i++) - cout << arr[i] << " "; -} - -int main() -{ - int arr[] = {170, 45, 75, 90, 802, 24, 2, 66}; - int n = sizeof(arr)/sizeof(arr[0]); - radixsort(arr, n); - print(arr, n); - return 0; -} diff --git a/CPP/sorting/selection_sort.cpp b/CPP/sorting/selection_sort.cpp deleted file mode 100644 index 101a7f3..0000000 --- a/CPP/sorting/selection_sort.cpp +++ /dev/null @@ -1,48 +0,0 @@ - -// C program for implementation of selection sort -#include - -void swap(int *xp, int *yp) -{ - int temp = *xp; - *xp = *yp; - *yp = temp; -} - -void selectionSort(int arr[], int n) -{ - int i, j, min_idx; - - // One by one move boundary of unsorted subarray - for (i = 0; i < n-1; i++) - { - // Find the minimum element in unsorted array - min_idx = i; - for (j = i+1; j < n; j++) - if (arr[j] < arr[min_idx]) - min_idx = j; - - // Swap the found minimum element with the first element - swap(&arr[min_idx], &arr[i]); - } -} - -/* Function to print an array */ -void printArray(int arr[], int size) -{ - int i; - for (i=0; i < size; i++) - printf("%d ", arr[i]); - printf("\n"); -} - -// Driver program to test above functions -int main() -{ - int arr[] = {64, 25, 12, 22, 11}; - int n = sizeof(arr)/sizeof(arr[0]); - selectionSort(arr, n); - printf("Sorted array: \n"); - printArray(arr, n); - return 0; -} diff --git a/CPP/test_1015.cpp b/CPP/test_1015.cpp deleted file mode 100644 index cdecef4..0000000 --- a/CPP/test_1015.cpp +++ /dev/null @@ -1,299 +0,0 @@ -#include -#include -using namespace std; - -// This constant can be avoided by explicitly -// calculating height of Huffman Tree -#define MAX_TREE_HT 100 - -// A Huffman tree node -struct MinHeapNode { - - // One of the input characters - char data; - - // Frequency of the character - unsigned freq; - - // Left and right child of this node - struct MinHeapNode *left, *right; -}; - -// A Min Heap: Collection of -// min-heap (or Huffman tree) nodes -struct MinHeap { - - // Current size of min heap - unsigned size; - - // capacity of min heap - unsigned capacity; - - // Attay of minheap node pointers - struct MinHeapNode** array; -}; - -// A utility function allocate a new -// min heap node with given character -// and frequency of the character -struct MinHeapNode* newNode(char data, unsigned freq) -{ - struct MinHeapNode* temp - = (struct MinHeapNode*)malloc -(sizeof(struct MinHeapNode)); - - temp->left = temp->right = NULL; - temp->data = data; - temp->freq = freq; - - return temp; -} - -// A utility function to create -// a min heap of given capacity -struct MinHeap* createMinHeap(unsigned capacity) - -{ - - struct MinHeap* minHeap - = (struct MinHeap*)malloc(sizeof(struct MinHeap)); - - // current size is 0 - minHeap->size = 0; - - minHeap->capacity = capacity; - - minHeap->array - = (struct MinHeapNode**)malloc(minHeap-> -capacity * sizeof(struct MinHeapNode*)); - return minHeap; -} - -// A utility function to -// swap two min heap nodes -void swapMinHeapNode(struct MinHeapNode** a, - struct MinHeapNode** b) - -{ - - struct MinHeapNode* t = *a; - *a = *b; - *b = t; -} - -// The standard minHeapify function. -void minHeapify(struct MinHeap* minHeap, int idx) - -{ - - int smallest = idx; - int left = 2 * idx + 1; - int right = 2 * idx + 2; - - if (left < minHeap->size && minHeap->array[left]-> -freq < minHeap->array[smallest]->freq) - smallest = left; - - if (right < minHeap->size && minHeap->array[right]-> -freq < minHeap->array[smallest]->freq) - smallest = right; - - if (smallest != idx) { - swapMinHeapNode(&minHeap->array[smallest], - &minHeap->array[idx]); - minHeapify(minHeap, smallest); - } -} - -// A utility function to check -// if size of heap is 1 or not -int isSizeOne(struct MinHeap* minHeap) -{ - - return (minHeap->size == 1); -} - -// A standard function to extract -// minimum value node from heap -struct MinHeapNode* extractMin(struct MinHeap* minHeap) - -{ - - struct MinHeapNode* temp = minHeap->array[0]; - minHeap->array[0] - = minHeap->array[minHeap->size - 1]; - - --minHeap->size; - minHeapify(minHeap, 0); - - return temp; -} - -// A utility function to insert -// a new node to Min Heap -void insertMinHeap(struct MinHeap* minHeap, - struct MinHeapNode* minHeapNode) - -{ - - ++minHeap->size; - int i = minHeap->size - 1; - - while (i && minHeapNode->freq < minHeap->array[(i - 1) / 2]->freq) { - - minHeap->array[i] = minHeap->array[(i - 1) / 2]; - i = (i - 1) / 2; - } - - minHeap->array[i] = minHeapNode; -} - -// A standard function to build min heap -void buildMinHeap(struct MinHeap* minHeap) - -{ - - int n = minHeap->size - 1; - int i; - - for (i = (n - 1) / 2; i >= 0; --i) - minHeapify(minHeap, i); -} - -// A utility function to print an array of size n -void printArr(int arr[], int n) -{ - int i; - for (i = 0; i < n; ++i) - cout<< arr[i]; - - cout<<"\n"; -} - -// Utility function to check if this node is leaf -int isLeaf(struct MinHeapNode* root) - -{ - - return !(root->left) && !(root->right); -} - -// Creates a min heap of capacity -// equal to size and inserts all character of -// data[] in min heap. Initially size of -// min heap is equal to capacity -struct MinHeap* createAndBuildMinHeap(char data[], int freq[], int size) - -{ - - struct MinHeap* minHeap = createMinHeap(size); - - for (int i = 0; i < size; ++i) - minHeap->array[i] = newNode(data[i], freq[i]); - - minHeap->size = size; - buildMinHeap(minHeap); - - return minHeap; -} - -// The main function that builds Huffman tree -struct MinHeapNode* buildHuffmanTree(char data[], int freq[], int size) - -{ - struct MinHeapNode *left, *right, *top; - - // Step 1: Create a min heap of capacity - // equal to size. Initially, there are - // modes equal to size. - struct MinHeap* minHeap = createAndBuildMinHeap(data, freq, size); - - // Iterate while size of heap doesn't become 1 - while (!isSizeOne(minHeap)) { - - // Step 2: Extract the two minimum - // freq items from min heap - left = extractMin(minHeap); - right = extractMin(minHeap); - - // Step 3: Create a new internal - // node with frequency equal to the - // sum of the two nodes frequencies. - // Make the two extracted node as - // left and right children of this new node. - // Add this node to the min heap - // '$' is a special value for internal nodes, not used - top = newNode('$', left->freq + right->freq); - - top->left = left; - top->right = right; - - insertMinHeap(minHeap, top); - } - - // Step 4: The remaining node is the - // root node and the tree is complete. - return extractMin(minHeap); -} - -// Prints huffman codes from the root of Huffman Tree. -// It uses arr[] to store codes -void printCodes(struct MinHeapNode* root, int arr[], int top) - -{ - - // Assign 0 to left edge and recur - if (root->left) { - - arr[top] = 0; - printCodes(root->left, arr, top + 1); - } - - // Assign 1 to right edge and recur - if (root->right) { - - arr[top] = 1; - printCodes(root->right, arr, top + 1); - } - - // If this is a leaf node, then - // it contains one of the input - // characters, print the character - // and its code from arr[] - if (isLeaf(root)) { - - cout<< root->data <<": "; - printArr(arr, top); - } -} - -// The main function that builds a -// Huffman Tree and print codes by traversing -// the built Huffman Tree -void HuffmanCodes(char data[], int freq[], int size) - -{ - // Construct Huffman Tree - struct MinHeapNode* root - = buildHuffmanTree(data, freq, size); - - // Print Huffman codes using - // the Huffman tree built above - int arr[MAX_TREE_HT], top = 0; - - printCodes(root, arr, top); -} - -// Driver program to test above functions -int main() -{ - - char arr[] = { 'a', 'b', 'c', 'd', 'e', 'f' }; - int freq[] = { 5, 9, 12, 13, 16, 45 }; - - int size = sizeof(arr) / sizeof(arr[0]); - - HuffmanCodes(arr, freq, size); - - return 0; -} diff --git a/CPP/test_1016.cpp b/CPP/test_1016.cpp deleted file mode 100644 index bb62215..0000000 --- a/CPP/test_1016.cpp +++ /dev/null @@ -1,77 +0,0 @@ -// hackerrank climbing the leaderboard -#include -using namespace std; -#define MAX 50000 - -struct other_players { - int score; - int rank; -}; - -struct alice { - int points; - int position; -}; - -void give_rankings(struct other_players p[],int players){ - p[0].rank = 1; - for(int i=1;i=0;k--){ - if(q[i].points >=p[0].score){ - q[i].position = p[0].rank; - } - - else if(q[i].points >= p[k].score && q[i].points < p[k-1].score){ - q[i].position = p[k].rank; - k = 0; - } - else { - } - } - } -} - -int main () { - int players; - int alice_played; - struct other_players p[MAX]; - struct alice q[MAX]; - - cin >> players; - for(int i=0;i> p[i].score; - } - give_rankings(p,players); - - cin >> alice_played; - - for(int i=0;i> q[i].points; - } - - for(int i=0;i -using namespace std; -#define MAX 5000 - -int queen_attack(int size,int queen_row,int queen_column,int obstacles,int r[],int c[]){ - int count = 0; - char chess[MAX][MAX]; - for(int i=0;i=0;i--){ - - if(chess[size-queen_row][i] == 'O'){ - i = 0; - } - else if(chess[size-queen_row][i] == 'X'){ - count = count+1; - } - else {} - } // 2nd left side - - for(int i=1;size-queen_row+i=0;i++){ - if(chess[size-queen_row-i][queen_column-1] == 'O'){ - i = size-queen_row; - } - else if(chess[size-queen_row-i][queen_column-1] == 'X'){ - count = count+1; - } - else {} - } // 4th up side - - for(int i=1;queen_column-1+i=0;i++){ - if(chess[size-queen_row-i][queen_column-1-i] == 'O'){ - i = size-queen_row; - } - else if(chess[size-queen_row-i][queen_column-1-i] == 'X'){ - count = count+1; - } - else {} - } // 6th left up - - for(int i=1;size-queen_row-i>=0;i++){ - if(chess[size-queen_row-i][queen_column-1+i] == 'O'){ - i = size-queen_row; - } - else if(chess[size-queen_row-i][queen_column-1+i] == 'X'){ - count = count+1; - } - else {} - } // 7th right up - - for(int i=1;queen_column-1-i>=0;i++){ - if(chess[size-queen_row+i][queen_column-1-i] == 'O'){ - i = queen_column+1; - } - else if(chess[size-queen_row+i][queen_column-1-i] == 'X'){ - count = count+1; - } - else {} - } // 8th left down - return count; - } - -int main() { - -int size; -int obstacles; - -cin >> size >> obstacles; -int queen_row,queen_column; -int r[MAX],c[MAX]; - -cin >> queen_row >> queen_column; -for(int i=0;i> r[i] >> c[i]; -} -int result = queen_attack(size,queen_row,queen_column,obstacles,r,c); -cout << result; -return 0; -} diff --git a/CPP/test_1018 b/CPP/test_1018 deleted file mode 100644 index cbaf4b2..0000000 --- a/CPP/test_1018 +++ /dev/null @@ -1,30 +0,0 @@ -// Sherlock and Squares -#include -using namespace std; -#define MAX 200 -#include - -int find_out(int a,int b){ - int count = 0; - for(int i=a;i<=b;i++){ - if(pow(i,0.5) == int(pow(i,0.5))){ - count = count+1; - } - } - return count; -} - -int main () { - int test_cases; - cin >> test_cases; - int a,b; - int result[MAX]; - for(int i=0;i> a >> b; - result[i] = find_out(a,b); - } - for(int i=0;i -using namespace std; - -char square[10] = {'o','1','2','3','4','5','6','7','8','9'}; - -int checkwin(); -void board(); - -int main() -{ - int player = 1,i,choice; - - char mark; - do - { - board(); - player=(player%2)?1:2; - - cout << "Player " << player << ", enter a number: "; - cin >> choice; - - mark=(player == 1) ? 'X' : 'O'; - - if (choice == 1 && square[1] == '1') - - square[1] = mark; - else if (choice == 2 && square[2] == '2') - - square[2] = mark; - else if (choice == 3 && square[3] == '3') - - square[3] = mark; - else if (choice == 4 && square[4] == '4') - - square[4] = mark; - else if (choice == 5 && square[5] == '5') - - square[5] = mark; - else if (choice == 6 && square[6] == '6') - - square[6] = mark; - else if (choice == 7 && square[7] == '7') - - square[7] = mark; - else if (choice == 8 && square[8] == '8') - - square[8] = mark; - else if (choice == 9 && square[9] == '9') - - square[9] = mark; - else - { - cout<<"Invalid move "; - - player--; - cin.ignore(); - cin.get(); - } - i=checkwin(); - - player++; - }while(i==-1); - board(); - if(i==1) - - cout<<"==>\aPlayer "<<--player<<" win "; - else - cout<<"==>\aGame draw"; - - cin.ignore(); - cin.get(); - return 0; -} - - -int checkwin() -{ - if (square[1] == square[2] && square[2] == square[3]) - - return 1; - else if (square[4] == square[5] && square[5] == square[6]) - - return 1; - else if (square[7] == square[8] && square[8] == square[9]) - - return 1; - else if (square[1] == square[4] && square[4] == square[7]) - - return 1; - else if (square[2] == square[5] && square[5] == square[8]) - - return 1; - else if (square[3] == square[6] && square[6] == square[9]) - - return 1; - else if (square[1] == square[5] && square[5] == square[9]) - - return 1; - else if (square[3] == square[5] && square[5] == square[7]) - - return 1; - else if (square[1] != '1' && square[2] != '2' && square[3] != '3' - && square[4] != '4' && square[5] != '5' && square[6] != '6' - && square[7] != '7' && square[8] != '8' && square[9] != '9') - - return 0; - else - return -1; -} - - - - -void board() -{ - system("cls"); - cout << "\n\n\tTic Tac Toe\n\n"; - - cout << "Player 1 (X) - Player 2 (O)" << endl << endl; - cout << endl; - - cout << " | | " << endl; - cout << " " << square[1] << " | " << square[2] << " | " << square[3] << endl; - - cout << "_____|_____|_____" << endl; - cout << " | | " << endl; - - cout << " " << square[4] << " | " << square[5] << " | " << square[6] << endl; - - cout << "_____|_____|_____" << endl; - cout << " | | " << endl; - - cout << " " << square[7] << " | " << square[8] << " | " << square[9] << endl; - - cout << " | | " << endl << endl; -} - diff --git a/CPP/towerofhanoi b/CPP/towerofhanoi deleted file mode 100644 index 0447138..0000000 --- a/CPP/towerofhanoi +++ /dev/null @@ -1,75 +0,0 @@ -#include -using namespace std; -//declares the stack to mimic recursion - - -int main() -{ - int n; - cout<<"Enter the number of disks in the tower: "; - cin>>n; - char beg='A'; - char aux='B'; - char end='C'; - if(n<100){ - int stn[100]; -char stbeg[100];//This are the stacks for imitating recursive behaviour. -char staux[100]; -char stend[100]; -char stadd[100]; -char add,temp,temp2; - int top=-1; - M: - if(n==1) - { - cout< -#include -#include -#include -#include -using namespace std; -#include -#include -using namespace std; - -int professor_id=0; -int student_id=0; -class Person -{ - public: - string name; - int age,score,id; - virtual void putdata()=0; - virtual void getdata()=0; -}; -class Professor : public Person -{ - void putdata() - { - cout<>name>>age>>score; - } -}; -class Student : public Person -{ - void putdata() - { - cout<>name>>age; - score=0; - for(int i=0,x;i<6;i++) - cin>>x,score+=x; - } -}; - -int main(){ int n, val; - cin>>n; //The number of objects that is going to be created. - Person *per[n]; - - for(int i = 0;i < n;i++){ - - cin>>val; - if(val == 1){ - // If val is 1 current object is of type Professor - per[i] = new Professor; - - } - else per[i] = new Student; // Else the current object is of type Student - - per[i]->getdata(); // Get the data from the user. - - } - - for(int i=0;iputdata(); // Print the required output for each object. - - return 0; - -} diff --git a/Circular_linked_list b/Circular_linked_list deleted file mode 100644 index c996a62..0000000 --- a/Circular_linked_list +++ /dev/null @@ -1,137 +0,0 @@ -// Write a C Program to implement CIRCULAR LINKED LIST(one way).This Program must include following functions in it. -// a.Write a function to CONSTRUCT a circular linked list. -// b.Write a function to INSERT an element at the beginning of the created linked list(step a). -// c.Write a function to INSERT an element at the end of the circular linked list. -// d.Write a function to DELETE an element from the beginning of the circular linked list. -// e.Write a function to DELETE an element from the end of the circular linkrd list. -// f.Write a function for 'DISPLAY' operation which prints the content of the circular linked list. - - - - -#include -#include -struct cr - { - int data; - struct cr *next; - } - s1,*node,*start,*end,*temp; - -int count=0; -void construct() - { - start=NULL;node=NULL; - } -void insertb() -{ -int x; -printf("Enter the element:"); scanf("%d",&x); -count++; -node=(struct cr *)malloc(sizeof(s1)); -node->data=x; -if(start==NULL) - { - start=node; - start->next=start; - end=node; - } -else - { - node->next=start; - end->next=node; - start=node; - } -} -void inserte(){ -int x; -printf("Enter the element:"); scanf("%d",&x); -count++; -node=(struct cr *)malloc(sizeof(s1)); -node->data=x; -if(start==NULL) - { - start=node; - start->next=start; - end=node; - } -else - { - node->next=start; - end->next=node; - end=node; - } -} -void deletee() -{ -if(start==NULL) - printf("Queue Underflow\n"); -else if(start==end) - { - temp=end; - free(temp); - start=NULL; - end=NULL; - } -else - { - temp=end; - count--; -for(node=start;node->next->next!=start;node=node->next); - end=node; - end->next=start; - free(temp); - } -} -void deleteb() -{ -if(start==NULL) - printf("Queue Underflow\n"); -else if(start==end) - { - temp=end; - free(temp); - start=NULL; - end=NULL; - } -else - { - temp=start; - count--; - start=start->next; - end->next=start; - free(temp); - } -} -void display() -{ -int i; -if(start==NULL) - printf("Queue underflow!\n"); -else - { - printf("\nThe elements are:\n"); - for(node=start,i=0;inext) - printf("%d ",node->data); - } -} -void main() -{ -int ch; -construct(); -while(1) -{ -printf("\n\n***Circular Queue***\n1.Insert at beginning\n2.Insert at end\n3.Delete from begining\n4.Delete from end\n5.Display\n6.Exit\nEnter your choice:\n"); -scanf("%d",&ch); -switch(ch) - { - case 1: insertb(); break; - case 2: inserte(); break; - case 3: deleteb(); break; - case 4: deletee(); break; - case 5: display(); break; - case 6: exit(0); break; - default: printf("\nWrong Choice!!\n"); - } -} -} diff --git a/OS/roundRobinScheduling.cpp b/OS/roundRobinScheduling.cpp deleted file mode 100644 index ff9450e..0000000 --- a/OS/roundRobinScheduling.cpp +++ /dev/null @@ -1,165 +0,0 @@ -#include -#include -using namespace std; -int front = -1; -int rear = -1; -int arr[5000]; -class AB{ -public: - int n,at,bt,ct,tat,wt,btt,v; - void input() - { - cout<<"Enter the Process No:-"; cin>>n; - cout<<"Enter the AT:-"; cin>>at; - cout<<"Enter the BT:-"; cin>>bt; - - } -}; - -void enqueue(int a) -{ if(rear==4999) - {printf("QUEUE OVERFLOW\n");} - -else{ - if(front==-1) - {front=0;} - rear++; - arr[rear]=a; - } - -} - -int dequeue() -{ - if(rear==-1||front>rear) - {cout<<"Hii\n";} - else - front++; - return arr[front-1]; - -} -void display() -{ - if(rear==-1||front==rear+1) - {printf("The queue is empty\n");} - else{ - printf("The queue is :-\n"); - for(int i=front;i<=rear;i++) - { - printf("%d\n",arr[i]); - } -} -} - -int main() -{ int nn,nnn; - cout<<"Enter the no of process:-"; - cin>>nn; nnn=nn+1; - - AB a[nnn],temp; - int i,j,sum=0,z,k=1,b,s,y=0; - float s1=0,s2=0; - for(i=1;i<=nn;i++) - { - a[i].input(); - a[i].btt=a[i].bt; - sum=sum+a[i].btt; - } - - - cout<<"Enter the Time Quantum :-"; - cin>>z; - - for(i=0;ia[j+1].at) - { - temp=a[j]; - a[j]=a[j+1]; - a[j+1]=temp; - } - } - } - -for(i=1;i<=nn;i++) -{ - a[i].v=i; -} - - - if(a[1].at==0) - { - for(i=1;i<=nn;i++) - { - if(a[i].at==0) - {enqueue(a[i].v); k++;} - } - } - - else - { enqueue(a[1].v); k++;} - - b=a[1].at; - //while(y= z) - { a[s].btt -= z; b += z;} - - else - { b += a[s].btt; a[s].btt = 0; } - - - - - - for(i=k;i<=nn;i++) - { - if(a[i].at<=b) - { - enqueue(a[i].v); - k++; - } - } - - - if(a[s].btt != 0) - { - //cout<<"\n"< -#include - -struct Node -{ - int data; - struct Node *next; -}*front = NULL,*rear = NULL; - -void insert(int); -void delete(); -void display(); - -void main() -{ - int choice, value; - - printf("\n:: Queue Implementation using Linked List ::\n"); - while(1){ - printf("\n****** MENU ******\n"); - printf("1. Insert\n2. Delete\n3. Display\n4. Exit\n"); - printf("Enter your choice: "); - scanf("%d",&choice); - switch(choice){ - case 1: printf("Enter the value to be insert: "); - scanf("%d", &value); - insert(value); - break; - case 2: delete(); break; - case 3: display(); break; - case 4: exit(0); - default: printf("\nWrong selection!!! Please try again!!!\n"); - } - } -} -void insert(int value) -{ - struct Node *newNode; - newNode = (struct Node*)malloc(sizeof(struct Node)); - newNode->data = value; - newNode -> next = NULL; - if(front == NULL) - front = rear = newNode; - else{ - rear -> next = newNode; - rear = newNode; - } - printf("\nInsertion is Success!!!\n"); -} -void delete() -{ - if(front == NULL) - printf("\nQueue is Empty!!!\n"); - else{ - struct Node *temp = front; - front = front -> next; - printf("\nDeleted element: %d\n", temp->data); - free(temp); - } -} -void display() -{ - if(front == NULL) - printf("\nQueue is Empty!!!\n"); - else{ - struct Node *temp = front; - while(temp->next != NULL){ - printf("%d\t",temp->data); - temp = temp -> next; - } - printf("%d\tNULL\n",temp->data); - } -} diff --git a/README.md b/README.md deleted file mode 100644 index 012a3e3..0000000 --- a/README.md +++ /dev/null @@ -1,46 +0,0 @@ -# Hacktoberfest 2020! -The goal of this repo is to help beginners who are doing their first pull requests. Feel free to join! - -## Past contributors -[2019 Hacktoberfest participants](https://github.com/DGIIIT/Hacktober/wiki/2019-Hactober-Participants) - -## Contributing guidelines - - [code of conduct](https://dgiiit.github.io/conduct.html) - - - -# How to Create a Pull Request - -## Method one (easy, prefered for small changes) - - - Click on the fork on the top to fork this repo. - - Go to your repo where you forked the project. - - Goto any folder where you would like to add your file - - Click "create new file" - - Add name of file with extension ex: .c,.cpp - - Add code (comments are optional) - - Click commit/propose new file - - Then you will see a "Pull Request" icon just under colored line - - Click on it and open Pull Request - - -## Method two (for large projects & many devs) - - - Click on the fork on the top to fork this repo. - - Go to your repo where you forked the project. - - Hit the clone button on your forked repo and copy the given link. - - On your terminal / command prompt, type "git clone [put the link here]". - - Change the index file in the folder. - - Afterward, on your terminal / command prompt, type "git add index.html"; then 'git commit -m "[type a message]" '. - - Create a remote to link the repository on github to your local workspace. use "git remote add [remote-name] [put the github link here]" - - Push the commit. For example, type "git push [remote-name] master". - - Go back to the original repo. - - Hit "new pull request" and compare between forks. - - Confirm the pull request and that's it! - -### Installation - -Make sure [git](https://git-scm.com/book/id/v2/Getting-Started-Installing-Git) is installed. -for remote git you should configure your ssh fingerprint. - ->> **Author**: Saichethan M. Reddy diff --git a/Sort.py b/Sort.py deleted file mode 100644 index 76e3e50..0000000 --- a/Sort.py +++ /dev/null @@ -1,293 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -# In[ ]: - - -import matplotlib.pyplot as plt -import random -from random import randint -import time -import sys -sys.setrecursionlimit(10000) - -def randList(limit): - mylist=[] - for i in range(0, limit): - x= random.randint(1, 100) - mylist.append(x) - return mylist - -def bubble(list): - - l=len(list) - - for i in range(l-1): - - for j in range(0, l-i-1): - - if list[j]>list[j+1]: - - list[j], list[j+1]= list[j+1], list[j] - - - -def insertion(list): - - l=len(list) - - for i in range(1,l): - - current = list[i] - - position = i - - - - while position > 0 and list[position -1] > current: - - list[position] = list[position -1 ] - - position -= 1 - - list[position] = current - - return list - -def merge(list): - if len(list) > 1: - mid = len(list) // 2 - leftHalf = list[:mid] - rightHalf = list[mid:] - - merge(leftHalf) - merge(rightHalf) - - i = 0 - j = 0 - k = 0 - while i < len(leftHalf) and j < len(rightHalf): - if leftHalf[i] < rightHalf[j]: - list[k] = leftHalf[i] - i = i + 1 - else: - list[k] = rightHalf[j] - j = j + 1 - k = k + 1 - - while i < len(leftHalf): - list[k] = leftHalf[i] - i = i + 1 - k = k + 1 - - while j < len(rightHalf): - list[k] = rightHalf[j] - j = j + 1 - k = k + 1 - return list - -def partition(nums, low, high): - pivot = nums[(low + high) // 2] - i = low - 1 - j = high + 1 - while True: - i += 1 - while nums[i] < pivot: - i += 1 - - j -= 1 - while nums[j] > pivot: - j -= 1 - - if i >= j: - return j - nums[i], nums[j] = nums[j], nums[i] - - -def quick_sort(nums): - def _quick_sort(items, low, high): - if low < high: - split_index = partition(items, low, high) - _quick_sort(items, low, split_index) - _quick_sort(items, split_index + 1, high) - - _quick_sort(nums, 0, len(nums) - 1) - - -def partition(alist, start, end): - pivot = randint(start, end) - temp = alist[end] - alist[end] = alist[pivot] - alist[pivot] = temp - pIndex = start - - for i in range(start, end): - if alist[i] <= alist[end]: - temp = alist[i] - alist[i] = alist[pIndex] - alist[pIndex] = temp - pIndex += 1 - temp1 = alist[end] - alist[end] = alist[pIndex] - alist[pIndex] = temp1 - - return pIndex - -def quicksort(alist, start, end): - if start < end: - pIndex = partition(alist, start, end) - quicksort(alist, start, pIndex-1) - quicksort(alist, pIndex+1, end) - - return alist - - - - - -p=2000 - -x1=[] - -y1=[] - -x2=[] - -y2=[] - -x3=[] - -y3=[] - -x4=[] - -y4=[] - -x5=[] - -y5=[] - -for i in range(0, 10): - - li1=randList(p) - - li2=li1[:] - - li3=li1[:] - - li4=li1[:] - - li5=li1[:] - - - t11=time.clock() - - insertion(li1) - - t12=time.clock() - - t1=t12-t11 - - - - t21=time.clock() - - bubble(li2) - - t22=time.clock() - - t2=t22-t21 - - - t31=time.clock() - - merge(li3) - - t32=time.clock() - - t3=t32-t31 - - - t41=time.clock() - - quick_sort(li4) - - t42=time.clock() - - t4=t42-t41 - - - t51=time.clock() - - quicksort(li5) - - t52=time.clock() - - t5=t52-t51 - - - x1.append(p) - - y1.append(t1) - - x2.append(p) - - y2.append(t2) - - x3.append(p) - - y3.append(t3) - - x4.append(p) - - y4.append(t4) - - x5.append(p) - - y5.append(t5) - - - p=p+1000 - - - -#%matplotlib inline - -plt.plot(x2, y2, 'blue',label='Bubble Sort') - -plt.plot(x1, y1, 'red',label='Insertion Sort') - -plt.plot(x3, y3, 'green',label='Merge Sort') - -plt.plot(x4, y4, 'black',label='Quick Sort') - -plt.xlabel('limit') - -plt.ylabel('time') - -plt.title('Complexity Graph') - -plt.legend() - -plt.show() - -plt.plot(x4, y4, 'black',label='Quick Sort') - -plt.plot(x5, y5, 'red',label='Quick Sort random') - -plt.xlabel('limit') - -plt.ylabel('time') - -plt.title('Complexity Graph') - -plt.legend() - -plt.show() - - -# In[ ]: - - - - diff --git a/_config.yml b/_config.yml deleted file mode 100644 index c419263..0000000 --- a/_config.yml +++ /dev/null @@ -1 +0,0 @@ -theme: jekyll-theme-cayman \ No newline at end of file diff --git a/age.py b/age.py deleted file mode 100644 index 6f03069..0000000 --- a/age.py +++ /dev/null @@ -1,21 +0,0 @@ -print("Choose option\n1 for age\n2 for year of birth") -x= int(input()) -if x==1: - print("Enter your age") - a=int(input()) -else: - print("Enter year of birth") - a=int(input()) -if a<200: - print(f"after {100-a} years you will be 100 years") - age=2019-a -elif 1920 -using namespace std; - -/* A Binary Search based function to -get index of ceiling of x in -arr[low..high] */ -int ceilSearch(int arr[], int low, int high, int x) -{ - int mid; - - /* If x is smaller than or equal - to the first element, - then return the first element */ - if(x <= arr[low]) - return low; - - /* If x is greater than the - last element, then return -1 */ - if(x > arr[high]) - return -1; - - /* get the index of middle - element of arr[low..high]*/ - mid = (low + high)/2; /* low + (high – low)/2 */ - - /* If x is same as middle - element, then return mid */ - if(arr[mid] == x) - return mid; - - /* If x is greater than arr[mid], - then either arr[mid + 1] - is ceiling of x, or ceiling - lies in arr[mid+1...high] */ - if(arr[mid] < x) - { - if(mid + 1 <= high && x <= arr[mid+1]) - return mid + 1; - else - return ceilSearch(arr, mid+1, high, x); - } - - /* If x is smaller than arr[mid], then either arr[mid] - is ceiling of x or ceiling lies in arr[mid-1...high] */ - if (mid - 1 >= low && x > arr[mid-1]) - return mid; - else - return ceilSearch(arr, low, mid - 1, x); -} - -/* Reverses arr[0..i] */ -void flip(int arr[], int i) -{ - int temp, start = 0; - while (start < i) - { - temp = arr[start]; - arr[start] = arr[i]; - arr[i] = temp; - start++; - i--; - } -} - -/* Function to sort an array using -insertion sort, binary search and flip */ -void insertionSort(int arr[], int size) -{ - int i, j; - - // Start from the second element - // and one by one insert arr[i] - // in already sorted arr[0..i-1] - for(i = 1; i < size; i++) - { - // Find the smallest element in arr[0..i-1] - // which is also greater than - // or equal to arr[i] - int j = ceilSearch(arr, 0, i-1, arr[i]); - - // Check if there was no element - // greater than arr[i] - if (j != -1) - { - // Put arr[i] before arr[j] using - // following four flip operations - flip(arr, j-1); - flip(arr, i-1); - flip(arr, i); - flip(arr, j); - } - } -} - -/* A utility function to print an array of size n */ -void printArray(int arr[], int n) -{ - int i; - for (i = 0; i < n; ++i) - cout< -using namespace std; - -void printKclosest(int arr[], int n, int x, - int k) -{ - // Make a max heap of difference with - // first k elements. - priority_queue > pq; - for (int i = 0; i < k; i++) - pq.push({ abs(arr[i] - x), i }); - - // Now process remaining elements. - for (int i = k; i < n; i++) { - - int diff = abs(arr[i] - x); - - // If difference with current - // element is more than root, - // then ignore it. - if (diff > pq.top().first) - continue; - - // Else remove root and insert - pq.pop(); - pq.push({ diff, i }); - } - - // Print contents of heap. - while (pq.empty() == false) { - cout << arr[pq.top().second] << " "; - pq.pop(); - } -} - -// Driver program to test above functions -int main() -{ - int arr[] = { -10, -50, 20, 17, 80 }; - int x = 20, k = 2; - int n = sizeof(arr) / sizeof(arr[0]); - printKclosest(arr, n, x, k); - return 0; -} diff --git a/johnsonsAlgorithm.cpp b/johnsonsAlgorithm.cpp deleted file mode 100644 index fd417ea..0000000 --- a/johnsonsAlgorithm.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include -#define INF 9999 -using namespace std; -int min(int a, int b); -int cost[10][10], adj[10][10]; -inline int min(int a, int b){ - return (a> vert; - cout << "Enter no of edges: "; - cin >> edge; - cout << "Enter the EDGE Costs:\n"; - for (k = 1; k <= edge; k++) { //take the input and store it into adj and cost matrix - cin >> i >> j >> c; - adj[i][j] = cost[i][j] = c; - } - for (i = 1; i <= vert; i++) - for (j = 1; j <= vert; j++) { - if (adj[i][j] == 0 && i != j) - adj[i][j] = INF; //if there is no edge, put infinity - } - for (k = 1; k <= vert; k++) - for (i = 1; i <= vert; i++) - for (j = 1; j <= vert; j++) - adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]); //find minimum path from i to j through k - cout << "Resultant adj matrix\n"; - for (i = 1; i <= vert; i++) { - for (j = 1; j <= vert; j++) { - if (adj[i][j] != INF) - cout << adj[i][j] << " "; - } - cout << "\n"; - } -} \ No newline at end of file diff --git a/orthogonal.cpp b/orthogonal.cpp deleted file mode 100644 index 4538954..0000000 --- a/orthogonal.cpp +++ /dev/null @@ -1,43 +0,0 @@ -// C++ program to check if two -// circles are orthogonal or not - -#include -using namespace std; - -// Function to Check if the given -// circles are orthogonal -bool orthogonality(int x1, int y1, int x2, - int y2, int r1, int r2) -{ - - // calculating the square - // of the distance between C1 and C2 - int dsquare = (x1 - x2) * (x1 - x2) - + (y1 - y2) * (y1 - y2); - - // Check if the given - // circles are orthogonal - if (dsquare == r1 * r1 + r2 * r2) - return true; - else - return false; -} - -// Driver code -int main() -{ - int x1 = 4, y1 = 3; - int x2 = 0, y2 = 1; - int r1 = 2, r2 = 4; - - bool f = orthogonality(x1, y1, x2, - y2, r1, r2); - - if (f) - cout << "Given circles are" - << " orthogonal."; - else - cout << "Given circles are" - << " not orthogonal."; - return 0; -} diff --git a/python/electronic_shop.py b/python/electronic_shop.py deleted file mode 100644 index 12aacbc..0000000 --- a/python/electronic_shop.py +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/python3 - -import os -import sys - -# -# Complete the getMoneySpent function below. -# -def getMoneySpent(keyboards, drives, b): - # - # Write your code here. - # - new=[0] - for i in keyboards: - sum1=0 - for j in drives: - sum1=i+j - if sum1<=b: - new.append(sum1) - sum1=0 - max1=new[0] - for i in new: - if max1<=i: - max1=i - - if max1==0: - return -1 - else: - return max1 - - -if __name__ == '__main__': - fptr = open(os.environ['OUTPUT_PATH'], 'w') - - bnm = input().split() - - b = int(bnm[0]) - - n = int(bnm[1]) - - m = int(bnm[2]) - - keyboards = list(map(int, input().rstrip().split())) - - drives = list(map(int, input().rstrip().split())) - - # - # The maximum amount of money she can spend on a keyboard and USB drive, or -1 if she can't purchase both items - # - - moneySpent = getMoneySpent(keyboards, drives, b) - - fptr.write(str(moneySpent) + '\n') - - fptr.close() diff --git a/python/game_of_stones.py b/python/game_of_stones.py deleted file mode 100644 index 1b1dc04..0000000 --- a/python/game_of_stones.py +++ /dev/null @@ -1,34 +0,0 @@ -#python3 - -import math -import os -import random -import re -import sys - -# gameOfStones function. -def gameOfStones(n): - if n==1: - return 'Second' - elif n>=2 and n<7: - return 'First' - elif n>=7: - if n%7<2: - return 'Second' - else: return 'First' - - - -if __name__ == '__main__': - fptr = open(os.environ['OUTPUT_PATH'], 'w') - - t = int(input()) - - for t_itr in range(t): - n = int(input()) - - result = gameOfStones(n) - - fptr.write(result + '\n') - - fptr.close() diff --git a/python/palidrome.py b/python/palidrome.py deleted file mode 100644 index 1f1ee01..0000000 --- a/python/palidrome.py +++ /dev/null @@ -1,18 +0,0 @@ -print("Enter the how Many number you want take") -n= int(input()) -x={} -a={} -print("Enter the number") -for i in range(0,n): - x[i]=input() - a[i]=x[i] -for i in range(0,n): - for j in range(0,15): - s=x[i] - t=s[::-1] - if x[i]==t: - print(f"Next Palindrome of {a[i]} is : {int(x[i])}") - break - else: - x[i]=int(x[i]) + 1 - x[i]=str(x[i]) diff --git a/python/tictaktoe.py b/python/tictaktoe.py deleted file mode 100644 index 4e20ba7..0000000 --- a/python/tictaktoe.py +++ /dev/null @@ -1,102 +0,0 @@ -def end(): - print("Do you want play again!\npess 1 for yes, otherwise anynumber") - z=int(input()) - if z==1: - tik() - else: - print("Good Bye!") -print("Do you want play TIK TAK TOE game!") -print("Press 1 for yes, otherwise anynumber") -n=int(input()) -if n==1: - def tik(): - flag=True - while flag: - print("Welcome in TIK TAK TOE game") - print("see all position!") - def disp(board): - print(" -------------") - print(' | '+board[0]+' | '+board[1]+' | '+board[2]+' | ') - print(" -------------") - print(' | '+board[3]+' | '+board[4]+' | '+board[5]+' | ') - print(" -------------") - print(' | '+board[6]+' | '+board[7]+' | '+board[8]+' | ') - print(" -------------") - num=['1','2','3','4','5','6','7','8','9'] - disp(num) - t=True - while t: - print("Player1: Select x or o") - s1=input() - if s1=="x": - s2="o" - t=False - elif s1=="o": - s2="x" - t=False - else: - print("Please Choose correct option!") - t=True - while flag: - print("Player1: Enter the position") - def player(s1): - n1=int(input()) - if n1<=9: - if num[n1-1]!="x" and num[n1-1]!="o": - num[n1-1]=s1 - disp(num) - else: - print("choose right place") - player(s1) - else: - print("Please Choose number less than 10") - player(s1) - player(s1) - def check(num): - mylist=[(num[0],num[1],num[2]),(num[3],num[4],num[5]),(num[6],num[7],num[8]),(num[0],num[3],num[6]),(num[1],num[4],num[7]),(num[2],num[5],num[8]),(num[0],num[4],num[8]),(num[2],num[4],num[6])] - win=0 - for c in mylist: - for z in c: - if z=="x": - win+=1 - else: - win=0 - break - if win==3 and s1=="x": - print("Player1 won the match") - win=0 - end() - elif win==3 and s1=="o": - print("Player2 won the match") - win=0 - end() - for c in mylist: - for z in c: - if z=="o": - win+=1 - else: - win=0 - break - if win==3 and s1=="o": - print("Player1 won the match") - win=0 - end() - elif win==3 and s1=="x": - print("Player2 won the match") - win=0 - end() - for ch in range(0,9): - if num[ch]=="x" or num[ch]=="o": - win+=1 - if win>8: - print("Game Over!") - end() - else: - win=0 - check(num) - print("Player2: Enter the position") - player(s2) - check(num) - tik() -else: - print("Outside from game!") \ No newline at end of file diff --git a/python/time_conversion.py b/python/time_conversion.py deleted file mode 100644 index 64d5626..0000000 --- a/python/time_conversion.py +++ /dev/null @@ -1,39 +0,0 @@ -#python3 - -import os -import sys - -def timeConversion(s): - x=s[0:2] - y=int(x) - if s[-2:]=='PM': - if y==12: - y=12 - z=str(y) - time=z+s[2:8] - else: - y+=12 - z=str(y) - time=z+s[2:8] - return time - if (s[-2:]=='AM' and y==12): - y=00 - z=str(y) - time=z+z+s[2:8] - return time - else: - return s[0:8] - - - - -if __name__ == '__main__': - f = open(os.environ['OUTPUT_PATH'], 'w') - - s = input() - - result = timeConversion(s) - - f.write(result + '\n') - - f.close() diff --git a/python/water_gun_snake_game.py b/python/water_gun_snake_game.py deleted file mode 100644 index 9d45c19..0000000 --- a/python/water_gun_snake_game.py +++ /dev/null @@ -1,41 +0,0 @@ -import random -y=0 -d=0 -com=0 -def lt(): - lst = ["snake","gun","water"] - a=random.choice(lst) - return a -for t in range(10): - a = lt() - x = input("s for Snake\nw for Water\ng for gun\nChoose one of them : ") - print(f"Computer choose : {a}") - if x == "s" and a == "gun": - print("Computer won the game!") - com+=1 - elif x == "g" and a == "snake": - print("you won the game!") - y+=1 - elif x == "g" and a == "water": - print("Computer won the game!") - com+=1 - elif x == "w" and a == "gun": - print("you won the game!") - y+=1 - elif x=="s" and a=="water": - print("you won the game!") - y+=1 - elif x== "w" and a=="snake": - print("Computer won the game!") - com+=1 - else: - print("Draw") - d+=1 -print("\nREsult:") -print(f"Computer won the {com} game in 10 games") -print(f"You won the {y} game in 10 games") -print(f"{d} game Draw in 10 games") -if com>y: - print("Computer is Winner!") -else: - print("You are Winner!") \ No newline at end of file diff --git a/selection_sort b/selection_sort deleted file mode 100644 index 75c93fa..0000000 --- a/selection_sort +++ /dev/null @@ -1,52 +0,0 @@ -#include - -//Function to swap the elements -void swap(int *xp, int *yp) -{ - int temp = *xp; - *xp = *yp; - *yp = temp; -} - -//Function for selection sort -void selectionSort(int arr[], int n) -{ - int i, j, min_idx; - - // One by one move boundary of unsorted subarray - for (i = 0; i < n-1; i++) - { - // Find the minimum element in unsorted array - min_idx = i; - for (j = i+1; j < n; j++) - if (arr[j] < arr[min_idx]) - min_idx = j; - - // Swap the found minimum element with the first element - swap(&arr[min_idx], &arr[i]); - } -} - - - -// Driver program to test above functions -int main() -{ - int number_of_elements; - printf("Enter the size of the array: \n"); - scanf("%d",&number_of_elements); - int array_unsorted[number_of_elements]; - int i; - printf("Enter the array elements: \n"); - for(i=0;i