diff --git a/insertion_sort.cs b/C#/insertion_sort.cs similarity index 100% rename from insertion_sort.cs rename to C#/insertion_sort.cs diff --git a/Bubble_sort.c b/C/Bubble_sort.c similarity index 100% rename from Bubble_sort.c rename to C/Bubble_sort.c diff --git a/C_Program_to_Swap_Two_Numbers.c b/C/C_Program_to_Swap_Two_Numbers.c similarity index 100% rename from C_Program_to_Swap_Two_Numbers.c rename to C/C_Program_to_Swap_Two_Numbers.c diff --git a/CircularQueue.c b/C/CircularQueue.c similarity index 96% rename from CircularQueue.c rename to C/CircularQueue.c index b5e56d0..daa2158 100644 --- a/CircularQueue.c +++ b/C/CircularQueue.c @@ -1,200 +1,200 @@ -/* -CIRCULAR QUEUE : ADT using Array of integer -[MARKS: 15] - -Prob 2: Write the abstract data type for Circular Queue using array. - -- enqueue - -- dequeue - -- peek : CHECK THE WHO IS AT THE FRONT - --isFull - --IsEmpty - - -Code by : Arnab Chakraborty -Github : https://github.com/ArnabC27 -*/ - -#include -#include - -struct Queue -{ - int front, rear, size, cap; - int *arr; -}; -typedef struct Queue queue; - -queue* createQueue(int cap) -{ - queue* q = (queue*)malloc(sizeof(queue)); - q->front = 0; - q->size = 0; - q->cap = cap; - q->rear = q->cap - 1; - q->arr = (int*)malloc(q->cap * sizeof(int)); - return q; -} - -int isFull(queue* q) -{ - return q->size == q->cap; -} - -int isEmpty(queue* q) -{ - return q->size == 0; -} - -void enqueue(queue* q, int x) -{ - if(isFull(q)) - { - printf("Queue is Full!!!\n"); - return; - } - q->rear = (q->rear + 1) % q->cap; - q->arr[q->rear] = x; - q->size = q->size + 1; - printf("%d is Enqueued to the Queue\n", x); -} - -int dequeue(queue* q) -{ - if(isEmpty(q)) - return -1; - int item = q->arr[q->front]; - q->front = (q->front + 1) % q->cap; - q->size = q->size - 1; - return item; -} - -void printQueue(queue* q) -{ - int i, j; - if(isEmpty(q)) - { - printf("\nQueue is Empty!!!\n"); - return; - } - else - { - if(q->front > q->rear) - { - for(i = 0; i <= q->rear; i++) - { - if(i == q->rear) - printf("%d <- REAR\n", q->arr[i]); - else - printf("%d\n", q->arr[i]); - } - for(i = q->rear+1; i < q->front; i++) - printf("|__|\n"); - for(j = q->front; j <= q->size; j++) - { - if(j < q->cap) - { - if(j == q->front) - printf("%d <- FRONT\n", q->arr[j]); - else - printf("%d\n", q->arr[j]); - } - } - } - else - { - for(i = q->front; i <= q->rear; i++) - { - if(i == q->front && i == q->rear) - printf("%d\t<- FRONT and REAR\n", q->arr[i]); - else if(i == q->front) - printf("%d\t<- FRONT\n", q->arr[i]); - else if(i == q->rear) - printf("%d\t<- REAR\n", q->arr[i]); - else - printf("%d\n", q->arr[i]); - } - } - printf("\n"); - } -} - -int peek(queue* q) -{ - if(isEmpty(q)) - { - printf("Queue is Empty!!!\n"); - return -1; - } - return q->arr[q->front]; -} - -int main() -{ - printf("----------CIRCULAR QUEUE IMPLEMENTATION----------\n"); - int cap, ch, x, cont = 1, a; - printf("Enter maximum capacity of the Queue you want to create : "); - scanf("%d", &cap); - if(cap >= 1) - { - queue* q = createQueue(cap); - - while(cont == 1) - { - printf("\nOperations on Queue that can be performed here :\n"); - printf("1. Check if Queue is Empty\n"); - printf("2. Check if Queue is Full\n"); - printf("3. Insert an element into the Queue\n"); - printf("4. Delete an element from the Queue\n"); - printf("5. Print the whole Queue\n"); - printf("6. Print the element at the Front of the Queue\n"); - printf("Enter your choice(1-6) : "); - scanf("%d", &ch); - printf("\n"); - - switch(ch) - { - case 1 : - if(isEmpty(q)) - printf("Queue is Empty!!!\n"); - else - printf("Queue is Not Empty!!!\n"); - break; - case 2 : - if(isFull(q)) - printf("Queue is Full!!!\n"); - else - printf("Queue is Not Full!!!\n"); - break; - case 3 : - printf("Enter an Integer you want to Insert into the Queue : "); - scanf("%d", &x); - enqueue(q, x); - break; - case 4 : - a = dequeue(q); - if(a != -1) - printf("Element deleted : %d\n", a); - break; - case 5 : - printf("Queue Status :\n"); - printQueue(q); - break; - case 6 : - printf("Element present at Front of Queue : %d\n", peek(q)); - break; - default : - printf("Invalid Choice!!!\n"); - } - - printf("Do you want to Continue? (1-YES / 0-NO) : "); - scanf("%d", &cont); - } - } - else - printf("Queue capacity should be greater than 0!!!\n"); +/* +CIRCULAR QUEUE : ADT using Array of integer +[MARKS: 15] + +Prob 2: Write the abstract data type for Circular Queue using array. + +- enqueue + +- dequeue + +- peek : CHECK THE WHO IS AT THE FRONT + +-isFull + +-IsEmpty + + +Code by : Arnab Chakraborty +Github : https://github.com/ArnabC27 +*/ + +#include +#include + +struct Queue +{ + int front, rear, size, cap; + int *arr; +}; +typedef struct Queue queue; + +queue* createQueue(int cap) +{ + queue* q = (queue*)malloc(sizeof(queue)); + q->front = 0; + q->size = 0; + q->cap = cap; + q->rear = q->cap - 1; + q->arr = (int*)malloc(q->cap * sizeof(int)); + return q; +} + +int isFull(queue* q) +{ + return q->size == q->cap; +} + +int isEmpty(queue* q) +{ + return q->size == 0; +} + +void enqueue(queue* q, int x) +{ + if(isFull(q)) + { + printf("Queue is Full!!!\n"); + return; + } + q->rear = (q->rear + 1) % q->cap; + q->arr[q->rear] = x; + q->size = q->size + 1; + printf("%d is Enqueued to the Queue\n", x); +} + +int dequeue(queue* q) +{ + if(isEmpty(q)) + return -1; + int item = q->arr[q->front]; + q->front = (q->front + 1) % q->cap; + q->size = q->size - 1; + return item; +} + +void printQueue(queue* q) +{ + int i, j; + if(isEmpty(q)) + { + printf("\nQueue is Empty!!!\n"); + return; + } + else + { + if(q->front > q->rear) + { + for(i = 0; i <= q->rear; i++) + { + if(i == q->rear) + printf("%d <- REAR\n", q->arr[i]); + else + printf("%d\n", q->arr[i]); + } + for(i = q->rear+1; i < q->front; i++) + printf("|__|\n"); + for(j = q->front; j <= q->size; j++) + { + if(j < q->cap) + { + if(j == q->front) + printf("%d <- FRONT\n", q->arr[j]); + else + printf("%d\n", q->arr[j]); + } + } + } + else + { + for(i = q->front; i <= q->rear; i++) + { + if(i == q->front && i == q->rear) + printf("%d\t<- FRONT and REAR\n", q->arr[i]); + else if(i == q->front) + printf("%d\t<- FRONT\n", q->arr[i]); + else if(i == q->rear) + printf("%d\t<- REAR\n", q->arr[i]); + else + printf("%d\n", q->arr[i]); + } + } + printf("\n"); + } +} + +int peek(queue* q) +{ + if(isEmpty(q)) + { + printf("Queue is Empty!!!\n"); + return -1; + } + return q->arr[q->front]; +} + +int main() +{ + printf("----------CIRCULAR QUEUE IMPLEMENTATION----------\n"); + int cap, ch, x, cont = 1, a; + printf("Enter maximum capacity of the Queue you want to create : "); + scanf("%d", &cap); + if(cap >= 1) + { + queue* q = createQueue(cap); + + while(cont == 1) + { + printf("\nOperations on Queue that can be performed here :\n"); + printf("1. Check if Queue is Empty\n"); + printf("2. Check if Queue is Full\n"); + printf("3. Insert an element into the Queue\n"); + printf("4. Delete an element from the Queue\n"); + printf("5. Print the whole Queue\n"); + printf("6. Print the element at the Front of the Queue\n"); + printf("Enter your choice(1-6) : "); + scanf("%d", &ch); + printf("\n"); + + switch(ch) + { + case 1 : + if(isEmpty(q)) + printf("Queue is Empty!!!\n"); + else + printf("Queue is Not Empty!!!\n"); + break; + case 2 : + if(isFull(q)) + printf("Queue is Full!!!\n"); + else + printf("Queue is Not Full!!!\n"); + break; + case 3 : + printf("Enter an Integer you want to Insert into the Queue : "); + scanf("%d", &x); + enqueue(q, x); + break; + case 4 : + a = dequeue(q); + if(a != -1) + printf("Element deleted : %d\n", a); + break; + case 5 : + printf("Queue Status :\n"); + printQueue(q); + break; + case 6 : + printf("Element present at Front of Queue : %d\n", peek(q)); + break; + default : + printf("Invalid Choice!!!\n"); + } + + printf("Do you want to Continue? (1-YES / 0-NO) : "); + scanf("%d", &cont); + } + } + else + printf("Queue capacity should be greater than 0!!!\n"); } \ No newline at end of file diff --git a/FactLargeNo.c b/C/FactLargeNo.c similarity index 100% rename from FactLargeNo.c rename to C/FactLargeNo.c diff --git a/HuffmanCoding.c b/C/HuffmanCoding.c similarity index 100% rename from HuffmanCoding.c rename to C/HuffmanCoding.c diff --git a/Queue.c b/C/Queue.c similarity index 95% rename from Queue.c rename to C/Queue.c index 1155e69..f3b19c1 100644 --- a/Queue.c +++ b/C/Queue.c @@ -1,184 +1,184 @@ -/* -QUEUE : ADT using Array of integer -[MARKS: 15] - -Prob 1: Implement the abstract data type of queue - -- enqueue - -- dequeue - -- peek : CHECK THE WHO IS AT THE FRONT - --isFull - --IsEmpty - - -Code by : Arnab Chakraborty -Github : https://github.com/ArnabC27 -*/ - -#include -#include - -struct Queue -{ - int front, rear, cap; - int *arr; -}; -typedef struct Queue queue; - -queue* createQueue(int cap) -{ - queue* q = (queue*)malloc(sizeof(queue)); - q->front = -1; - q->rear = -1; - q->cap = cap; - q->arr = (int*)malloc(q->cap * sizeof(int)); - return q; -} - -int isFull(queue* q) -{ - return q->rear == q->cap - 1; -} - -int isEmpty(queue* q) -{ - return q->front == -1 || q->front > q->rear; -} - -void enqueue(queue* q, int x) -{ - if(isFull(q)) - { - printf("Queue Overflow!!!\n"); - return; - } - else - { - if(q->front == -1) - q->front = 0; - q->rear = q->rear + 1; - q->arr[q->rear] = x; - } - printf("%d is Enqueued to the Queue\n", x); -} - -int dequeue(queue* q) -{ - if(isEmpty(q)) - { - printf("Queue Underflow!!!\n"); - return -1; - } - return q->arr[q->front++]; -} - -void printQueue(queue* q) -{ - int i, j; - if(isEmpty(q)) - { - printf("\nQueue is Empty!!!\n"); - return; - } - else - { - for(i = 0; i < q->front; i++) - printf("|__|\n"); - for(j = q->front; j <= q->rear; j++) - { - if(j == q->front && j == q->rear) - printf("%d\t<- FRONT and REAR\n", q->arr[j]); - else if(j == q->front) - printf("%d\t<- FRONT\n", q->arr[j]); - else if(j == q->rear) - printf("%d\t<- REAR\n", q->arr[j]); - else - printf("%d\n", q->arr[j]); - } - } -} - -int peek(queue* q) -{ - if(isEmpty(q)) - { - printf("Queue is Empty!!!\n"); - return -1; - } - return q->arr[q->front]; -} - -int main() -{ - printf("----------QUEUE IMPLEMENTATION----------\n"); - int cap, ch, x, cont = 1, a; - printf("Enter maximum capacity of the Queue you want to create : "); - scanf("%d", &cap); - if(cap >= 1) - { - queue* q = createQueue(cap); - - while(cont == 1) - { - printf("\nOperations on Queue that can be performed here :\n"); - printf("1. Check if Queue is Empty\n"); - printf("2. Check if Queue is Full\n"); - printf("3. Insert an element into the Queue\n"); - printf("4. Delete an element from the Queue\n"); - printf("5. Print the whole Queue\n"); - printf("6. Print the element at the Front of the Queue\n"); - printf("7. Re-initialize the Queue\n"); - printf("Enter your choice(1-7) : "); - scanf("%d", &ch); - printf("\n"); - - switch(ch) - { - case 1 : - if(isEmpty(q)) - printf("Queue is Empty!!!\n"); - else - printf("Queue is Not Empty!!!\n"); - break; - case 2 : - if(isFull(q)) - printf("Queue is Full!!!\n"); - else - printf("Queue is Not Full!!!\n"); - break; - case 3 : - printf("Enter an Integer you want to Insert into the Queue : "); - scanf("%d", &x); - enqueue(q, x); - break; - case 4 : - a = dequeue(q); - if(a != -1) - printf("Element deleted : %d\n", a); - break; - case 5 : - printf("Queue Status :\n"); - printQueue(q); - break; - case 6 : - printf("Element present at Front of Queue : %d\n", peek(q)); - break; - case 7 : - q = createQueue(cap); - printf("Queue is Re-intialized!!!\n"); - break; - default : - printf("Invalid Choice!!!\n"); - } - - printf("Do you want to Continue? (1-YES / 0-NO) : "); - scanf("%d", &cont); - } - } - else - printf("Queue capacity should be greater than 0!!!\n"); +/* +QUEUE : ADT using Array of integer +[MARKS: 15] + +Prob 1: Implement the abstract data type of queue + +- enqueue + +- dequeue + +- peek : CHECK THE WHO IS AT THE FRONT + +-isFull + +-IsEmpty + + +Code by : Arnab Chakraborty +Github : https://github.com/ArnabC27 +*/ + +#include +#include + +struct Queue +{ + int front, rear, cap; + int *arr; +}; +typedef struct Queue queue; + +queue* createQueue(int cap) +{ + queue* q = (queue*)malloc(sizeof(queue)); + q->front = -1; + q->rear = -1; + q->cap = cap; + q->arr = (int*)malloc(q->cap * sizeof(int)); + return q; +} + +int isFull(queue* q) +{ + return q->rear == q->cap - 1; +} + +int isEmpty(queue* q) +{ + return q->front == -1 || q->front > q->rear; +} + +void enqueue(queue* q, int x) +{ + if(isFull(q)) + { + printf("Queue Overflow!!!\n"); + return; + } + else + { + if(q->front == -1) + q->front = 0; + q->rear = q->rear + 1; + q->arr[q->rear] = x; + } + printf("%d is Enqueued to the Queue\n", x); +} + +int dequeue(queue* q) +{ + if(isEmpty(q)) + { + printf("Queue Underflow!!!\n"); + return -1; + } + return q->arr[q->front++]; +} + +void printQueue(queue* q) +{ + int i, j; + if(isEmpty(q)) + { + printf("\nQueue is Empty!!!\n"); + return; + } + else + { + for(i = 0; i < q->front; i++) + printf("|__|\n"); + for(j = q->front; j <= q->rear; j++) + { + if(j == q->front && j == q->rear) + printf("%d\t<- FRONT and REAR\n", q->arr[j]); + else if(j == q->front) + printf("%d\t<- FRONT\n", q->arr[j]); + else if(j == q->rear) + printf("%d\t<- REAR\n", q->arr[j]); + else + printf("%d\n", q->arr[j]); + } + } +} + +int peek(queue* q) +{ + if(isEmpty(q)) + { + printf("Queue is Empty!!!\n"); + return -1; + } + return q->arr[q->front]; +} + +int main() +{ + printf("----------QUEUE IMPLEMENTATION----------\n"); + int cap, ch, x, cont = 1, a; + printf("Enter maximum capacity of the Queue you want to create : "); + scanf("%d", &cap); + if(cap >= 1) + { + queue* q = createQueue(cap); + + while(cont == 1) + { + printf("\nOperations on Queue that can be performed here :\n"); + printf("1. Check if Queue is Empty\n"); + printf("2. Check if Queue is Full\n"); + printf("3. Insert an element into the Queue\n"); + printf("4. Delete an element from the Queue\n"); + printf("5. Print the whole Queue\n"); + printf("6. Print the element at the Front of the Queue\n"); + printf("7. Re-initialize the Queue\n"); + printf("Enter your choice(1-7) : "); + scanf("%d", &ch); + printf("\n"); + + switch(ch) + { + case 1 : + if(isEmpty(q)) + printf("Queue is Empty!!!\n"); + else + printf("Queue is Not Empty!!!\n"); + break; + case 2 : + if(isFull(q)) + printf("Queue is Full!!!\n"); + else + printf("Queue is Not Full!!!\n"); + break; + case 3 : + printf("Enter an Integer you want to Insert into the Queue : "); + scanf("%d", &x); + enqueue(q, x); + break; + case 4 : + a = dequeue(q); + if(a != -1) + printf("Element deleted : %d\n", a); + break; + case 5 : + printf("Queue Status :\n"); + printQueue(q); + break; + case 6 : + printf("Element present at Front of Queue : %d\n", peek(q)); + break; + case 7 : + q = createQueue(cap); + printf("Queue is Re-intialized!!!\n"); + break; + default : + printf("Invalid Choice!!!\n"); + } + + printf("Do you want to Continue? (1-YES / 0-NO) : "); + scanf("%d", &cont); + } + } + else + printf("Queue capacity should be greater than 0!!!\n"); } \ No newline at end of file diff --git a/Stack.c b/C/Stack.c similarity index 95% rename from Stack.c rename to C/Stack.c index f9d2faf..e4a3217 100644 --- a/Stack.c +++ b/C/Stack.c @@ -1,143 +1,143 @@ -/* -Note: Write the program with user input as menu driven program. - -1. Implement ADT of stack using ARRAY with user define data type stack (structure) [Marks: 10] - - - Push, Pop and so on as you feel best - -Code by : Arnab Chakraborty -Github : https://github.com/ArnabC27 -*/ - -#include -#include - -struct Stack -{ - int top; - int cap; - int* arr; -}; -typedef struct Stack stack; - -stack* createStack(int cap) -{ - stack* s = (stack*)malloc(sizeof(stack)); - s->cap = cap; - s->top = -1; - s->arr = (int*)malloc(s->cap * sizeof(int)); - return s; -} - -int isFull(stack* s) -{ - return s->top == s->cap-1; -} - -int isEmpty(stack* s) -{ - return s->top == -1; -} - -void push(stack* s, int x) -{ - if(isFull(s)) - { - printf("Stack Overflow\n"); - return; - } - s->arr[++s->top] = x; - printf("%d pushed into the Stack\n", x); -} - -int pop(stack* s) -{ - if(isEmpty(s)) - { - printf("Stack Underflow\n"); - return -1; - } - return s->arr[s->top--]; -} - -void printStack(stack* s) -{ - int i; - if(isEmpty(s)) - { - printf("Stack is Empty\n"); - return; - } - else - { - for(i = s->top; i >= 0; i--) - { - if(i == s->top) - printf("%d <- TOP\n", s->arr[i]); - else - printf("%d\n", s->arr[i]); - } - } -} - -int main() -{ - printf("----------STACK IMPLEMENTATION----------\n"); - int cap, ch, x, cont = 1, a; - printf("Enter maximum capacity of the Stack you want to create : "); - scanf("%d", &cap); - if(cap >= 1) - { - stack* s = createStack(cap); - - while(cont == 1) - { - printf("\nOperations on Stack that can be performed here :\n"); - printf("1. Check if Stack is Empty\n"); - printf("2. Check if Stack is Full\n"); - printf("3. Push an element into the Stack\n"); - printf("4. Pop an element from the Stack\n"); - printf("5. Print the whole Stack\n"); - printf("Enter your choice(1-5) : "); - scanf("%d", &ch); - printf("\n"); - - switch(ch) - { - case 1 : - if(isEmpty(s)) - printf("Stack is Empty\n"); - else - printf("Stack is not Empty\n"); - break; - case 2 : - if(isFull(s)) - printf("Stack is Full\n"); - else - printf("Stack is not Full\n"); - break; - case 3 : - printf("Enter an integer you want to Push into the Stack : "); - scanf("%d", &x); - push(s,x); - break; - case 4 : - a = pop(s); - if(a != -1) - printf("Element popped : %d", a); - break; - case 5 : - printf("Stack Status :\n"); - printStack(s); - break; - default : - printf("Wrong choice of option!!!\n"); - } - - printf("\nDo you want to continue? (1-YES / 0-NO) : "); - scanf("%d", &cont); - } - } - else - printf("Stack capacity should be greater than 0!!!\n"); +/* +Note: Write the program with user input as menu driven program. + +1. Implement ADT of stack using ARRAY with user define data type stack (structure) [Marks: 10] + + - Push, Pop and so on as you feel best + +Code by : Arnab Chakraborty +Github : https://github.com/ArnabC27 +*/ + +#include +#include + +struct Stack +{ + int top; + int cap; + int* arr; +}; +typedef struct Stack stack; + +stack* createStack(int cap) +{ + stack* s = (stack*)malloc(sizeof(stack)); + s->cap = cap; + s->top = -1; + s->arr = (int*)malloc(s->cap * sizeof(int)); + return s; +} + +int isFull(stack* s) +{ + return s->top == s->cap-1; +} + +int isEmpty(stack* s) +{ + return s->top == -1; +} + +void push(stack* s, int x) +{ + if(isFull(s)) + { + printf("Stack Overflow\n"); + return; + } + s->arr[++s->top] = x; + printf("%d pushed into the Stack\n", x); +} + +int pop(stack* s) +{ + if(isEmpty(s)) + { + printf("Stack Underflow\n"); + return -1; + } + return s->arr[s->top--]; +} + +void printStack(stack* s) +{ + int i; + if(isEmpty(s)) + { + printf("Stack is Empty\n"); + return; + } + else + { + for(i = s->top; i >= 0; i--) + { + if(i == s->top) + printf("%d <- TOP\n", s->arr[i]); + else + printf("%d\n", s->arr[i]); + } + } +} + +int main() +{ + printf("----------STACK IMPLEMENTATION----------\n"); + int cap, ch, x, cont = 1, a; + printf("Enter maximum capacity of the Stack you want to create : "); + scanf("%d", &cap); + if(cap >= 1) + { + stack* s = createStack(cap); + + while(cont == 1) + { + printf("\nOperations on Stack that can be performed here :\n"); + printf("1. Check if Stack is Empty\n"); + printf("2. Check if Stack is Full\n"); + printf("3. Push an element into the Stack\n"); + printf("4. Pop an element from the Stack\n"); + printf("5. Print the whole Stack\n"); + printf("Enter your choice(1-5) : "); + scanf("%d", &ch); + printf("\n"); + + switch(ch) + { + case 1 : + if(isEmpty(s)) + printf("Stack is Empty\n"); + else + printf("Stack is not Empty\n"); + break; + case 2 : + if(isFull(s)) + printf("Stack is Full\n"); + else + printf("Stack is not Full\n"); + break; + case 3 : + printf("Enter an integer you want to Push into the Stack : "); + scanf("%d", &x); + push(s,x); + break; + case 4 : + a = pop(s); + if(a != -1) + printf("Element popped : %d", a); + break; + case 5 : + printf("Stack Status :\n"); + printStack(s); + break; + default : + printf("Wrong choice of option!!!\n"); + } + + printf("\nDo you want to continue? (1-YES / 0-NO) : "); + scanf("%d", &cont); + } + } + else + printf("Stack capacity should be greater than 0!!!\n"); } \ No newline at end of file diff --git a/Taskmanager.c b/C/Taskmanager.c similarity index 100% rename from Taskmanager.c rename to C/Taskmanager.c diff --git a/binary_search.c b/C/binary_search.c similarity index 100% rename from binary_search.c rename to C/binary_search.c diff --git a/binarytree.c b/C/binarytree.c similarity index 100% rename from binarytree.c rename to C/binarytree.c diff --git a/combinationFormula.c b/C/combinationFormula.c similarity index 100% rename from combinationFormula.c rename to C/combinationFormula.c diff --git a/double_linked_list.c b/C/double_linked_list.c similarity index 100% rename from double_linked_list.c rename to C/double_linked_list.c diff --git a/efficientExponent.c b/C/efficientExponent.c similarity index 100% rename from efficientExponent.c rename to C/efficientExponent.c diff --git a/greedyalgorithum.c b/C/greedyalgorithum.c similarity index 100% rename from greedyalgorithum.c rename to C/greedyalgorithum.c diff --git a/guessTheNumber.c b/C/guessTheNumber.c similarity index 100% rename from guessTheNumber.c rename to C/guessTheNumber.c diff --git a/infix-to-postfix.c b/C/infix-to-postfix.c similarity index 100% rename from infix-to-postfix.c rename to C/infix-to-postfix.c diff --git a/insertionsort.c b/C/insertionsort.c similarity index 100% rename from insertionsort.c rename to C/insertionsort.c diff --git a/is_real_number.c b/C/is_real_number.c similarity index 100% rename from is_real_number.c rename to C/is_real_number.c diff --git a/linked_list.c b/C/linked_list.c similarity index 100% rename from linked_list.c rename to C/linked_list.c diff --git a/manojbank.c b/C/manojbank.c similarity index 94% rename from manojbank.c rename to C/manojbank.c index a72f998..8de9bf7 100644 --- a/manojbank.c +++ b/C/manojbank.c @@ -1,190 +1,190 @@ -#include -#include -#include - - - // maximum 3 attempts -void login(); -void menu(); -void checkbalance(); -void withdraw(); -void deposit(); -void proceed(); -float read(); -void write(float n); - -float total = 6000; - -void main() -{ - login(); -} - -void write(float n) -{ - FILE *fp; - fp = fopen("balance.txt","a"); - fprintf(fp,"\n%f",n); - fclose(fp); -} - - -float read() -{ - FILE *fp; - float n; - fp = fopen("balance.txt","r"); - if(fp == NULL) - { - printf("Internal Error!"); - exit(0); - } - while(fscanf(fp,"%f",&n) == 1); - fclose(fp); - return n; -} - -void proceed() -{ - char ch; - printf("\nPress Y to continue... "); - scanf(" %c",&ch); - system("cls"); - if(ch == 'Y' || ch == 'y') - { - menu(); - } - else - { - exit(0); - } -} - -void deposit() -{ - float da; - float n = read(); - printf("Enter Amount to Deposit : "); - scanf("%f",&da); - if(da<=10000) - { - total = total + da; - n += da; - printf("\nDeposited Amount = $%.2f\n",da); - printf("\nTotal Balance = $%.2f\n",n); - write(n); - } - else - { - printf("\nAmount must not be greater than 10k!\n"); - } -} - -void withdraw() -{ - float wa; - float n = read(); - printf("Enter Amount to Withdraw : "); - scanf("%f",&wa); - if(wa <= n) - { - if(wa <= 5000) - { - if((int)wa%500 == 0) - { - total = total - wa; - n -= wa; - printf("\nWithdraw Amount = $%.2f\n",wa); - printf("\nTotal Available Balance = $%.2f\n",n); - write(n); - } - else - { - printf("\nAmount must be Multiple of 500!\n"); - } - } - else - { - printf("\nAmount Exceeds Per Transaction Limit!\n"); - } - } - else - { - printf("\nInsufficient Balance!\n"); - } -} - -void checkbalance() -{ - printf("Your Total Balance is $%.2f",read()); -} - -void menu() -{ - int n; - printf("************* Welcome to Manoj International Bank ***************\n"); - printf("Options:\n1. Check Balance\n2. Withdraw\n3. Deposit\n4. Exit\n Select : "); - scanf("%d",&n); - system("cls"); - switch(n) - { - case 1: - - checkbalance(); - break; - case 2: - - withdraw(); - break; - case 3: - - deposit(); - break; - case 4: - - printf("Exit"); - break; - default: - printf("\nInvalid Option!\n"); - } - proceed(); -} - - -void login() -{ - char susr[20] = "manoj"; - char spwd[20] = "manoj@123"; - char usr[20],pwd[20]; - int i,flag=0; - for(i=1;i<=3;i++) - { - printf("Attempt Remaining %d\n",(4-i)); - printf("Enter your user Name : "); - gets(usr); - printf("Enter your user Password : "); - gets(pwd); - - if((strcmp(susr,usr)==0)&&(strcmp(spwd,pwd)==0)) - { - flag = 1; - printf("\nWelcome %s!\n\n\n",usr); - menu(); - } - else - { - flag = 0; - printf("\nLogin Failed!\n"); - } - } - - if(flag == 1) - { - printf("\nWelcome %s\n",usr); - } - else - { - - printf("\nYour Account is Locked!\n"); - } +#include +#include +#include + + + // maximum 3 attempts +void login(); +void menu(); +void checkbalance(); +void withdraw(); +void deposit(); +void proceed(); +float read(); +void write(float n); + +float total = 6000; + +void main() +{ + login(); +} + +void write(float n) +{ + FILE *fp; + fp = fopen("balance.txt","a"); + fprintf(fp,"\n%f",n); + fclose(fp); +} + + +float read() +{ + FILE *fp; + float n; + fp = fopen("balance.txt","r"); + if(fp == NULL) + { + printf("Internal Error!"); + exit(0); + } + while(fscanf(fp,"%f",&n) == 1); + fclose(fp); + return n; +} + +void proceed() +{ + char ch; + printf("\nPress Y to continue... "); + scanf(" %c",&ch); + system("cls"); + if(ch == 'Y' || ch == 'y') + { + menu(); + } + else + { + exit(0); + } +} + +void deposit() +{ + float da; + float n = read(); + printf("Enter Amount to Deposit : "); + scanf("%f",&da); + if(da<=10000) + { + total = total + da; + n += da; + printf("\nDeposited Amount = $%.2f\n",da); + printf("\nTotal Balance = $%.2f\n",n); + write(n); + } + else + { + printf("\nAmount must not be greater than 10k!\n"); + } +} + +void withdraw() +{ + float wa; + float n = read(); + printf("Enter Amount to Withdraw : "); + scanf("%f",&wa); + if(wa <= n) + { + if(wa <= 5000) + { + if((int)wa%500 == 0) + { + total = total - wa; + n -= wa; + printf("\nWithdraw Amount = $%.2f\n",wa); + printf("\nTotal Available Balance = $%.2f\n",n); + write(n); + } + else + { + printf("\nAmount must be Multiple of 500!\n"); + } + } + else + { + printf("\nAmount Exceeds Per Transaction Limit!\n"); + } + } + else + { + printf("\nInsufficient Balance!\n"); + } +} + +void checkbalance() +{ + printf("Your Total Balance is $%.2f",read()); +} + +void menu() +{ + int n; + printf("************* Welcome to Manoj International Bank ***************\n"); + printf("Options:\n1. Check Balance\n2. Withdraw\n3. Deposit\n4. Exit\n Select : "); + scanf("%d",&n); + system("cls"); + switch(n) + { + case 1: + + checkbalance(); + break; + case 2: + + withdraw(); + break; + case 3: + + deposit(); + break; + case 4: + + printf("Exit"); + break; + default: + printf("\nInvalid Option!\n"); + } + proceed(); +} + + +void login() +{ + char susr[20] = "manoj"; + char spwd[20] = "manoj@123"; + char usr[20],pwd[20]; + int i,flag=0; + for(i=1;i<=3;i++) + { + printf("Attempt Remaining %d\n",(4-i)); + printf("Enter your user Name : "); + gets(usr); + printf("Enter your user Password : "); + gets(pwd); + + if((strcmp(susr,usr)==0)&&(strcmp(spwd,pwd)==0)) + { + flag = 1; + printf("\nWelcome %s!\n\n\n",usr); + menu(); + } + else + { + flag = 0; + printf("\nLogin Failed!\n"); + } + } + + if(flag == 1) + { + printf("\nWelcome %s\n",usr); + } + else + { + + printf("\nYour Account is Locked!\n"); + } } \ No newline at end of file diff --git a/recordofdtuusingfile.c b/C/recordofdtuusingfile.c similarity index 100% rename from recordofdtuusingfile.c rename to C/recordofdtuusingfile.c diff --git a/stackoperationusingarray.c b/C/stackoperationusingarray.c similarity index 100% rename from stackoperationusingarray.c rename to C/stackoperationusingarray.c diff --git a/time.c b/C/time.c similarity index 92% rename from time.c rename to C/time.c index 3782e53..57dd71a 100644 --- a/time.c +++ b/C/time.c @@ -1,126 +1,126 @@ -#include -#include -#include - -void morning_walk() -{ - int a=8,g; - - for(g=5;g +#include +#include + +void morning_walk() +{ + int a=8,g; + + for(g=5;g -using namespace std; - -int findMinX(int num[], int rem[], int k) -{ - int x = 1; - - while (true) - { - int j; - for (j=0; j +using namespace std; + +int findMinX(int num[], int rem[], int k) +{ + int x = 1; + + while (true) + { + int j; + for (j=0; j -//covid cpp -using namespace std; - -int main() -{ - int t = 0; - cin>>t; - for (int i = 0; i < t; i++) - { - int size = 0; - cin>>size; - vector v(size, 0); - for (int j = 0; j < size; j++) - cin>>v[j]; - int a = -1, flag = 0; - for(int j = 0; j < size; j++) - { - if(v[j] == 1) - { - if(a == -1) - a = j; - else - { - if(j - a < 6) - { - flag = 1; - break; - } - else - { - a = j; - } - } - } - } - if(flag) - cout<<"NO"< +//covid cpp +using namespace std; + +int main() +{ + int t = 0; + cin>>t; + for (int i = 0; i < t; i++) + { + int size = 0; + cin>>size; + vector v(size, 0); + for (int j = 0; j < size; j++) + cin>>v[j]; + int a = -1, flag = 0; + for(int j = 0; j < size; j++) + { + if(v[j] == 1) + { + if(a == -1) + a = j; + else + { + if(j - a < 6) + { + flag = 1; + break; + } + else + { + a = j; + } + } + } + } + if(flag) + cout<<"NO"< -using namespace std; - -#define fastio \ - ios_base::sync_with_stdio(false); \ - cin.tie(0); \ - cout.tie(0); -#define ll long long -#define M 1000000007 - -int Find_KthLargest(vector vec, int k) { - priority_queue > pq (vec.begin(),vec.begin()+k); - for(int i=k;i vec ={7,4,6,3,9,1}; - int k=3; - cout< +using namespace std; + +#define fastio \ + ios_base::sync_with_stdio(false); \ + cin.tie(0); \ + cout.tie(0); +#define ll long long +#define M 1000000007 + +int Find_KthLargest(vector vec, int k) { + priority_queue > pq (vec.begin(),vec.begin()+k); + for(int i=k;i vec ={7,4,6,3,9,1}; + int k=3; + cout< -using namespace std; -void merge(vector& nums1, int m, vector& nums2, int n) { - - int i=m-1,j=n-1,k=m+n-1; - while(i>=0&&j>=0) - { - if(nums1[i]>nums2[j]) - { - nums1[k]=nums1[i]; - i--; - k--; - } - else - { - nums1[k]=nums2[j]; - j--; - k--; - } - } - while(i>=0) - nums1[k--]=nums1[i--]; - while(j>=0) - nums1[k--]=nums2[j--]; -} -int main(){ - int n,m; - cout<<"Enter Length of two arrays: "; - - cin>>n>>m; - vectornums1(n+m),nums2(m); - - cout<<"Enter values in first array"; - for(int i=0;i>nums1[i]; - } - - cout<<"Enter values in second array"; - for(int i=0;i>nums2[i]; - } - - merge(nums1,n,nums2,m); - cout<<"The Merged Sorted arrays are: "; - for(int i=0;i +using namespace std; +void merge(vector& nums1, int m, vector& nums2, int n) { + + int i=m-1,j=n-1,k=m+n-1; + while(i>=0&&j>=0) + { + if(nums1[i]>nums2[j]) + { + nums1[k]=nums1[i]; + i--; + k--; + } + else + { + nums1[k]=nums2[j]; + j--; + k--; + } + } + while(i>=0) + nums1[k--]=nums1[i--]; + while(j>=0) + nums1[k--]=nums2[j--]; +} +int main(){ + int n,m; + cout<<"Enter Length of two arrays: "; + + cin>>n>>m; + vectornums1(n+m),nums2(m); + + cout<<"Enter values in first array"; + for(int i=0;i>nums1[i]; + } + + cout<<"Enter values in second array"; + for(int i=0;i>nums2[i]; + } + + merge(nums1,n,nums2,m); + cout<<"The Merged Sorted arrays are: "; + for(int i=0;i - using namespace std; - - stacks; - stackt; - - void push(int val) { - s.push(val); - if(t.empty()) - t.push(val); - else{ - if(val>n; - - for(int i=0;i>num; - push(num); - } - - cout<<"The current minimum is : "< + using namespace std; + + stacks; + stackt; + + void push(int val) { + s.push(val); + if(t.empty()) + t.push(val); + else{ + if(val>n; + + for(int i=0;i>num; + push(num); + } + + cout<<"The current minimum is : "< -using namespace std; - -class rsa -{ - int p, q; - double n, phi, e=2, g, d; - long msg, encrypted, decrypted, enc; - - public: - void pipeline() - { - input(); - algorithm(); - output(); - } - - void input() - { - cout<<"Enter the value of p : "; - cin>>p; - - cout<<"Enter the value of q : "; - cin>>q; - - cout<<"Enter the message : "; - cin>>msg; - } - - int gcd(int a, int b) - { - if(a==0) - return b; - return gcd(b%a, a); - } - - int mod(int m, int k, int n) - { - int result=1; - - m=m%n; - - if(m==0) - return 0; - - while(k>0) - { - if(k%2==1) - result=(result*m)%n; - - k/=2; - m=(m*m)%n; - } - return result; - } - - void algorithm() - { - n=p*q; - phi=(p-1)*(q-1); - - while(e +using namespace std; + +class rsa +{ + int p, q; + double n, phi, e=2, g, d; + long msg, encrypted, decrypted, enc; + + public: + void pipeline() + { + input(); + algorithm(); + output(); + } + + void input() + { + cout<<"Enter the value of p : "; + cin>>p; + + cout<<"Enter the value of q : "; + cin>>q; + + cout<<"Enter the message : "; + cin>>msg; + } + + int gcd(int a, int b) + { + if(a==0) + return b; + return gcd(b%a, a); + } + + int mod(int m, int k, int n) + { + int result=1; + + m=m%n; + + if(m==0) + return 0; + + while(k>0) + { + if(k%2==1) + result=(result*m)%n; + + k/=2; + m=(m*m)%n; + } + return result; + } + + void algorithm() + { + n=p*q; + phi=(p-1)*(q-1); + + while(e -using namespace std; -struct ListNode { - int val; - ListNode *next; - ListNode() : val(0), next(nullptr) {} - ListNode(int x) : val(x), next(nullptr) {} - ListNode(int x, ListNode *next) : val(x), next(next) {} - }; - -class Solution { -public: - ListNode* rotateRight(ListNode* head, int k) { - - if(head==NULL || head->next==NULL) { - return head; - } - int size=0; - - ListNode *temp=head; - while(temp->next!=NULL) { - size++; - temp=temp->next; - - } - size++; - temp->next=head; - ListNode *cur=head; - k=k%size; - for(int i=0;inext; - } - ListNode* res=cur; - res=res->next; - cur->next=NULL; - return res; - } -}; - -int main() { -ListNode *root=new ListNode(5); -root->next=new ListNode(7); -root->next->next=new ListNode(8); -Solution obj; -ListNode result=obj.rotateList(root,2); -return 0; +#include +using namespace std; +struct ListNode { + int val; + ListNode *next; + ListNode() : val(0), next(nullptr) {} + ListNode(int x) : val(x), next(nullptr) {} + ListNode(int x, ListNode *next) : val(x), next(next) {} + }; + +class Solution { +public: + ListNode* rotateRight(ListNode* head, int k) { + + if(head==NULL || head->next==NULL) { + return head; + } + int size=0; + + ListNode *temp=head; + while(temp->next!=NULL) { + size++; + temp=temp->next; + + } + size++; + temp->next=head; + ListNode *cur=head; + k=k%size; + for(int i=0;inext; + } + ListNode* res=cur; + res=res->next; + cur->next=NULL; + return res; + } +}; + +int main() { +ListNode *root=new ListNode(5); +root->next=new ListNode(7); +root->next->next=new ListNode(8); +Solution obj; +ListNode result=obj.rotateList(root,2); +return 0; } \ No newline at end of file diff --git a/SCC.cpp b/CPP/SCC.cpp similarity index 96% rename from SCC.cpp rename to CPP/SCC.cpp index ad754d5..2661cbf 100644 --- a/SCC.cpp +++ b/CPP/SCC.cpp @@ -1,108 +1,108 @@ -#include - -using namespace std; - -void dfs(vector > &edges, bool* visited, int a, int n, stack* s) -{ - visited[a] = true; - for(int i = 0; i < edges[a].size(); i++) - { - if(visited[edges[a][i]] == false) - { - dfs(edges, visited, edges[a][i], n, s); - } - } - s->push(a); -} -void dfs2(vector > &redges, bool* visited, int a, int n, vector &v) -{ - visited[a] = true; - v.push_back(a); - for(int i = 0; i < redges[a].size(); i++) - { - if(visited[redges[a][i]] == false) - { - dfs2(redges, visited, redges[a][i], n, v); - } - } -} - -vector > component(vector > &edges, vector > &redges, bool* visited, int n) -{ - vector > output; - stack* s = new stack; - for(int i = 0; i < n; i++) - if(visited[i] == false) - dfs(edges, visited, i, n, s); - for(int i = 0; i < n; i++) - visited[i] = false; - while(!s->empty()) - { - int a = s->top(); - s->pop(); - if(visited[a] == false) - { - vector v; - dfs2(redges, visited, a, n , v); - output.push_back(v); - } - } - return output; -} - -int main() -{ - while(true) - { - int n = 0, e = 0; - cin>>n; - if(n == 0) - break; - cin>>e; - vector > edges(n), redges(n); - int a, b; - for(int i = 0; i < e; i++) - { - cin>>a>>b; - edges[a - 1].push_back(b - 1); - redges[b - 1].push_back(a - 1); - } - bool* visited = new bool[n]; - for (int i = 0; i < n; i++) - { - visited[i] = false; - } - vector > output = component(edges, redges, visited, n); - vector > bottoms; - for (int i = 0; i < output.size(); i++) - { - bool flag = true; - for(int j = 0; j < output[i].size(); j++) - { - if(!flag) - break; - int a = output[i][j]; - for(int k = 0; k < edges[a].size(); k++) - { - if(output[i].end() == find(output[i].begin(), output[i].end(), edges[a][k])) - { - flag = false; - break; - } - } - } - if(flag) - bottoms.push_back(output[i]); - } - for(int i = 0; i < bottoms.size(); i++) - { - for(int j = 0; j < bottoms[i].size(); j++) - { - int a = bottoms[i][j]; - cout<<++a<<" "; - } - cout< + +using namespace std; + +void dfs(vector > &edges, bool* visited, int a, int n, stack* s) +{ + visited[a] = true; + for(int i = 0; i < edges[a].size(); i++) + { + if(visited[edges[a][i]] == false) + { + dfs(edges, visited, edges[a][i], n, s); + } + } + s->push(a); +} +void dfs2(vector > &redges, bool* visited, int a, int n, vector &v) +{ + visited[a] = true; + v.push_back(a); + for(int i = 0; i < redges[a].size(); i++) + { + if(visited[redges[a][i]] == false) + { + dfs2(redges, visited, redges[a][i], n, v); + } + } +} + +vector > component(vector > &edges, vector > &redges, bool* visited, int n) +{ + vector > output; + stack* s = new stack; + for(int i = 0; i < n; i++) + if(visited[i] == false) + dfs(edges, visited, i, n, s); + for(int i = 0; i < n; i++) + visited[i] = false; + while(!s->empty()) + { + int a = s->top(); + s->pop(); + if(visited[a] == false) + { + vector v; + dfs2(redges, visited, a, n , v); + output.push_back(v); + } + } + return output; +} + +int main() +{ + while(true) + { + int n = 0, e = 0; + cin>>n; + if(n == 0) + break; + cin>>e; + vector > edges(n), redges(n); + int a, b; + for(int i = 0; i < e; i++) + { + cin>>a>>b; + edges[a - 1].push_back(b - 1); + redges[b - 1].push_back(a - 1); + } + bool* visited = new bool[n]; + for (int i = 0; i < n; i++) + { + visited[i] = false; + } + vector > output = component(edges, redges, visited, n); + vector > bottoms; + for (int i = 0; i < output.size(); i++) + { + bool flag = true; + for(int j = 0; j < output[i].size(); j++) + { + if(!flag) + break; + int a = output[i][j]; + for(int k = 0; k < edges[a].size(); k++) + { + if(output[i].end() == find(output[i].begin(), output[i].end(), edges[a][k])) + { + flag = false; + break; + } + } + } + if(flag) + bottoms.push_back(output[i]); + } + for(int i = 0; i < bottoms.size(); i++) + { + for(int j = 0; j < bottoms[i].size(); j++) + { + int a = bottoms[i][j]; + cout<<++a<<" "; + } + cout< -#include -using namespace std; -//you can directly use stl swap for swapping it will make your code more functioning -/*void swap(int &a, int &b) -{ int temp; - temp = a; - a = b; - b = temp; -} */ - -void display(int *arr, int n) { - for(int i = 0; i> n; - int array[n]; - cout << "Enter elements:" << endl; - for(int i = 0; i> array[i]; - } - - SelectionSort(arr, n); - cout << "Array after Sorting: "; - display(arr, n); -} +#include +#include +using namespace std; +//you can directly use stl swap for swapping it will make your code more functioning +/*void swap(int &a, int &b) +{ int temp; + temp = a; + a = b; + b = temp; +} */ + +void display(int *arr, int n) { + for(int i = 0; i> n; + int array[n]; + cout << "Enter elements:" << endl; + for(int i = 0; i> array[i]; + } + + SelectionSort(arr, n); + cout << "Array after Sorting: "; + display(arr, n); +} diff --git a/SimpleSnakeGame.cpp b/CPP/SimpleSnakeGame.cpp similarity index 100% rename from SimpleSnakeGame.cpp rename to CPP/SimpleSnakeGame.cpp diff --git a/SinglyLinkedList.cpp b/CPP/SinglyLinkedList.cpp similarity index 100% rename from SinglyLinkedList.cpp rename to CPP/SinglyLinkedList.cpp diff --git a/Stack_LinkedList.cpp b/CPP/Stack_LinkedList.cpp similarity index 100% rename from Stack_LinkedList.cpp rename to CPP/Stack_LinkedList.cpp diff --git a/Subarray_with_a_sum.cpp b/CPP/Subarray_with_a_sum.cpp similarity index 94% rename from Subarray_with_a_sum.cpp rename to CPP/Subarray_with_a_sum.cpp index b1d36ef..662ac32 100644 --- a/Subarray_with_a_sum.cpp +++ b/CPP/Subarray_with_a_sum.cpp @@ -1,46 +1,46 @@ -/* This program checks and finds whether a subarray with a given sum exists in an array or not. */ - - - -#include -using namespace std; - -int main() { - int t; - cin>>t; - while(t--) - { - int n; - long long int s,s1=0; - cin>>n>>s; - int ar[n]; - for(int i=0;i>ar[i]; - int i,j,v=0; - i=0; - j=0; - s1=ar[0]; - while(i<=j&&js&&i +using namespace std; + +int main() { + int t; + cin>>t; + while(t--) + { + int n; + long long int s,s1=0; + cin>>n>>s; + int ar[n]; + for(int i=0;i>ar[i]; + int i,j,v=0; + i=0; + j=0; + s1=ar[0]; + while(i<=j&&js&&i -using namespace std; -int main() { - int t = 0; - cin>>t; - for(int i = 0; i < t; i++) - { - int n = 0, cows = 0; - map m; - cin>>n>>cows; - vector position(n, 0); - for(int i = 0; i < n; i++) - cin>>position[i]; - sort(position.begin(), position.end()); - m[position[0]] = 1; - m[position[n - 1]] = 1; - long long Min = position[n - 1] - position[0]; - for(int i = 2; i < cows; i++) - { - long long bigDis = LONG_MIN, bestPos = 0; - auto itr = m.begin(); - itr++; - for(; itr != m.end(); itr++) - { - long long a = itr->first; - itr--; - long long b = (itr)->first; - itr++; - long long mid = (a + b)/2; - long long x = lower_bound(position.begin(), position.end(), mid) - position.begin(); - if(abs(position[x] - mid) > abs(position[x - 1] - mid)) - x--; - if(position.at(x) == a || position.at(x) == b) - continue; - long long res = min(abs(a - position[x]), abs(b - position[x])); - if(res > bigDis) - { - bigDis = res; - bestPos = position.at(x); - } - } - m[bestPos] = 1; - Min = min(bigDis, Min); - } - cout< +using namespace std; +int main() { + int t = 0; + cin>>t; + for(int i = 0; i < t; i++) + { + int n = 0, cows = 0; + map m; + cin>>n>>cows; + vector position(n, 0); + for(int i = 0; i < n; i++) + cin>>position[i]; + sort(position.begin(), position.end()); + m[position[0]] = 1; + m[position[n - 1]] = 1; + long long Min = position[n - 1] - position[0]; + for(int i = 2; i < cows; i++) + { + long long bigDis = LONG_MIN, bestPos = 0; + auto itr = m.begin(); + itr++; + for(; itr != m.end(); itr++) + { + long long a = itr->first; + itr--; + long long b = (itr)->first; + itr++; + long long mid = (a + b)/2; + long long x = lower_bound(position.begin(), position.end(), mid) - position.begin(); + if(abs(position[x] - mid) > abs(position[x - 1] - mid)) + x--; + if(position.at(x) == a || position.at(x) == b) + continue; + long long res = min(abs(a - position[x]), abs(b - position[x])); + if(res > bigDis) + { + bigDis = res; + bestPos = position.at(x); + } + } + m[bestPos] = 1; + Min = min(bigDis, Min); + } + cout< -#include -using namespace std; - -class crt -{ - vectorbi, ni, Ni, yi; - int n, N=1, x=0; - - public: - - int pipeline() - { - input(); - if(relativePrime()==0) - return 0; - calcNi(); - inverse(); - return output(); - } - - void input() - { - int r, d; - - cout<<"Enter the number of divisiors or remainders : "; - cin>>n; - - cout<>d>>r; - ni.push_back(d); - bi.push_back(r); - } - } - - int gcd(int num1, int num2) - { - if (num2==0) - return num1; - return gcd(num2, num1%num2); - } - - int relativePrime() - { - for(int i=0; i>n; + + cout<>d>>r; + ni.push_back(d); + bi.push_back(r); + } + } + + int gcd(int num1, int num2) + { + if (num2==0) + return num1; + return gcd(num2, num1%num2); + } + + int relativePrime() + { + for(int i=0; i + +using namespace std; + +int whoWins(int h, int x, int y, bool p) +{ + if(h < 0) + return 0; + if(h == 1 || h == x || h == y) + if(p) + return 1; + else + return 0; + return whoWins(h - 1, x, y, ~p) || whoWins(h - x, x, y, ~p) || whoWins(h - y, x, y, ~p); +} + +int main(int argc, char const *argv[]) +{ + int h,x,y; + cin>>h>>x>>y; + if(whoWins(h, x, y, true) == 1) + cout<<"Beerus"< -using namespace std; - -class Graph -{ - int V; - vector< vector >adj; - bool isCyclicUtil(int v,vector &visited,int parent); - -public: - Graph(int V); - void addEdge(int v,int w); - bool isCyclic(); -}; - -Graph::Graph(int V) -{ - this->V=V; - adj=vector< vector >(V); -} - -void Graph::addEdge(int v,int w) -{ - adj[v].push_back(w); - adj[w].push_back(v); -} - -bool Graph::isCyclicUtil(int v,vector &visited,int parent) -{ - visited[v]=true; - vector::iterator i; - for(i=adj[v].begin();i!=adj[v].end();++i) - { - if(!visited[*i]) - { - if(isCyclicUtil(*i,visited,v)) return true; - } - else if(*i!=parent) return true; - } - return false; -} - -bool Graph::isCyclic() -{ - vector visited(V); - for(int i=0;i>n; - cout<<"Enter number of edges:"<>e; - Graph g(n); - cout<<"Enter edges:"<> a >> b; - g.addEdge(a,b); - } - g.isCyclic()? cout << "Cycle detected!\n": - cout << "No cycle detected!\n"; - return 0; -} - - -/* - ------- OUTPUT 1: ------ - -Enter number of nodes: -5 -Enter number of edges: -5 -Enter edges: -0 1 -1 2 -2 3 -2 4 -3 4 -Cycle detected! - -Nodes: 0,1,2,3,4 - - 0 - / - 1----2 - / \ - 3---4 - - -Edges: {0,1}, {1,2}, {2,3}, {2,4}, {3,4}. - -Cycle: 2 - / \ - 3---4 - -Cycle detected. - - - ------ OUTPUT 2: ----- - - -Enter number of nodes: -5 -Enter number of edges: -4 -Enter edges: -0 1 -1 2 -2 3 -2 4 -No cycle detected! - -Nodes: 0,1,2,3,4 - - 0----1 - | - | - 2 - / \ - 3 4 - -Edges: {0,1}, {1,2}, {2,3}, {3,4}. - -Graph doesn't contain a cycle. - - - - -*/ -//dfs cycle detection -//directedd graph -#include -using namespace std; -void make(vectorv[],int x,int y){ - v[x].push_back(y); - -} -bool cycle(vectorv[],int i,bool visted[],bool stk[]){ - if(visted[i]==false){ - visted[i]=true; - stk[i]=true; - for(auto x: v[i]){ - if(visted[x]==false && cycle(v,x,visted,stk)){ - return true; - } - else if(visted[x]==true && stk[x]==true){ - return true; - } - } - } - stk[i]=false; - return false; -} -bool iscyclic(vectorv[],int n){ - bool visted[n]={false}; - bool stk[n]={false}; - for(int i=0;i>n; - vectorv[n]; - int edges; - cin>>edges; - while(edges--){ - int x,y; - cin>>x>>y; - make(v,x,y); - } - if(iscyclic(v,n)){ - cout<<"yes"; - } - else{ - cout<<"no"; - } - -} +#include +using namespace std; + +class Graph +{ + int V; + vector< vector >adj; + bool isCyclicUtil(int v,vector &visited,int parent); + +public: + Graph(int V); + void addEdge(int v,int w); + bool isCyclic(); +}; + +Graph::Graph(int V) +{ + this->V=V; + adj=vector< vector >(V); +} + +void Graph::addEdge(int v,int w) +{ + adj[v].push_back(w); + adj[w].push_back(v); +} + +bool Graph::isCyclicUtil(int v,vector &visited,int parent) +{ + visited[v]=true; + vector::iterator i; + for(i=adj[v].begin();i!=adj[v].end();++i) + { + if(!visited[*i]) + { + if(isCyclicUtil(*i,visited,v)) return true; + } + else if(*i!=parent) return true; + } + return false; +} + +bool Graph::isCyclic() +{ + vector visited(V); + for(int i=0;i>n; + cout<<"Enter number of edges:"<>e; + Graph g(n); + cout<<"Enter edges:"<> a >> b; + g.addEdge(a,b); + } + g.isCyclic()? cout << "Cycle detected!\n": + cout << "No cycle detected!\n"; + return 0; +} + + +/* + +------ OUTPUT 1: ------ + +Enter number of nodes: +5 +Enter number of edges: +5 +Enter edges: +0 1 +1 2 +2 3 +2 4 +3 4 +Cycle detected! + +Nodes: 0,1,2,3,4 + + 0 + / + 1----2 + / \ + 3---4 + + +Edges: {0,1}, {1,2}, {2,3}, {2,4}, {3,4}. + +Cycle: 2 + / \ + 3---4 + +Cycle detected. + + + +----- OUTPUT 2: ----- + + +Enter number of nodes: +5 +Enter number of edges: +4 +Enter edges: +0 1 +1 2 +2 3 +2 4 +No cycle detected! + +Nodes: 0,1,2,3,4 + + 0----1 + | + | + 2 + / \ + 3 4 + +Edges: {0,1}, {1,2}, {2,3}, {3,4}. + +Graph doesn't contain a cycle. + + + + +*/ +//dfs cycle detection +//directedd graph +#include +using namespace std; +void make(vectorv[],int x,int y){ + v[x].push_back(y); + +} +bool cycle(vectorv[],int i,bool visted[],bool stk[]){ + if(visted[i]==false){ + visted[i]=true; + stk[i]=true; + for(auto x: v[i]){ + if(visted[x]==false && cycle(v,x,visted,stk)){ + return true; + } + else if(visted[x]==true && stk[x]==true){ + return true; + } + } + } + stk[i]=false; + return false; +} +bool iscyclic(vectorv[],int n){ + bool visted[n]={false}; + bool stk[n]={false}; + for(int i=0;i>n; + vectorv[n]; + int edges; + cin>>edges; + while(edges--){ + int x,y; + cin>>x>>y; + make(v,x,y); + } + if(iscyclic(v,n)){ + cout<<"yes"; + } + else{ + cout<<"no"; + } + +} diff --git a/defish_images.cpp b/CPP/defish_images.cpp similarity index 100% rename from defish_images.cpp rename to CPP/defish_images.cpp diff --git a/deleteNode.cpp b/CPP/deleteNode.cpp similarity index 100% rename from deleteNode.cpp rename to CPP/deleteNode.cpp diff --git a/divide-et-impera-sumofarray.cpp b/CPP/divide-et-impera-sumofarray.cpp similarity index 100% rename from divide-et-impera-sumofarray.cpp rename to CPP/divide-et-impera-sumofarray.cpp diff --git a/divide_and_conquer_minmax.cpp b/CPP/divide_and_conquer_minmax.cpp similarity index 100% rename from divide_and_conquer_minmax.cpp rename to CPP/divide_and_conquer_minmax.cpp diff --git a/djkshtra_algo.cpp b/CPP/djkshtra_algo.cpp similarity index 100% rename from djkshtra_algo.cpp rename to CPP/djkshtra_algo.cpp diff --git a/dutchflag.cpp b/CPP/dutchflag.cpp similarity index 94% rename from dutchflag.cpp rename to CPP/dutchflag.cpp index e7d839c..a20198c 100644 --- a/dutchflag.cpp +++ b/CPP/dutchflag.cpp @@ -1,37 +1,37 @@ -//dutchflag problem to sort an array having three types of elements only. -#include -using namespace std; - -void dutchflagsorting(int a[], int n) -{ - int low = 0; - int high = n - 1; - int mid = 0; - while (mid <= high) { - switch (a[mid]) { - case 0: - swap(a[low++], a[mid++]); - break; - case 1: - mid++; - break; - case 2: - swap(a[mid], a[high--]); - break; - } - } -} - - -int main() -{ - int arr[] = { 0, 1, 2, 0, 1, 2, 1, 2, 0, 0, 2, 1 }; - int n = sizeof(arr) / sizeof(arr[0]); - dutchflagsorting(arr, n); - for(auto it:arr){ - cout< +using namespace std; + +void dutchflagsorting(int a[], int n) +{ + int low = 0; + int high = n - 1; + int mid = 0; + while (mid <= high) { + switch (a[mid]) { + case 0: + swap(a[low++], a[mid++]); + break; + case 1: + mid++; + break; + case 2: + swap(a[mid], a[high--]); + break; + } + } +} + + +int main() +{ + int arr[] = { 0, 1, 2, 0, 1, 2, 1, 2, 0, 0, 2, 1 }; + int n = sizeof(arr) / sizeof(arr[0]); + dutchflagsorting(arr, n); + for(auto it:arr){ + cout< -using namespace std; -long long helper(int A[], int start, int end) -{ - if(start >= end) - return 0; - int mid = (end + start) / 2; - long long count = 0; - count += helper(A, start, mid); - count += helper(A, mid + 1, end); - int i = start, j = mid + 1, k = 0; - int copy[end - start + 1]; - while(i <= mid && j <= end) - { - if(A[j] < A[i]) - { - count += end - i + 1; - copy[k] = A[j]; - j++; - } - else if(A[j] > A[i]) - { - copy[k] = A[i]; - i++; - } - k++; - } - while(i <= mid) - { - copy[k] = A[i]; - i++; - k++; - } - while(j <= end) - { - copy[k] = A[j]; - j++; - k++; - } - for(int l = 0; l <= (end - start); l++) - A[start + i] = copy[i]; - return count; -} -long long solve(int A[], int n) -{ - return helper(A, 0, n - 1); -} -int main(int argc, char const *argv[]) -{ - int A[] = {2, 5, 1, 3, 4}; - solve(A, 5); - for(int i = 0; i < 5; i++) - cout< +using namespace std; +long long helper(int A[], int start, int end) +{ + if(start >= end) + return 0; + int mid = (end + start) / 2; + long long count = 0; + count += helper(A, start, mid); + count += helper(A, mid + 1, end); + int i = start, j = mid + 1, k = 0; + int copy[end - start + 1]; + while(i <= mid && j <= end) + { + if(A[j] < A[i]) + { + count += end - i + 1; + copy[k] = A[j]; + j++; + } + else if(A[j] > A[i]) + { + copy[k] = A[i]; + i++; + } + k++; + } + while(i <= mid) + { + copy[k] = A[i]; + i++; + k++; + } + while(j <= end) + { + copy[k] = A[j]; + j++; + k++; + } + for(int l = 0; l <= (end - start); l++) + A[start + i] = copy[i]; + return count; +} +long long solve(int A[], int n) +{ + return helper(A, 0, n - 1); +} +int main(int argc, char const *argv[]) +{ + int A[] = {2, 5, 1, 3, 4}; + solve(A, 5); + for(int i = 0; i < 5; i++) + cout<0) - { - if(k&1) - res=(res*v)%MOD; - k>>=1; - v=(v*v)%MOD; - } - return res; +int modexp(ll v,int k) +{ + // res = v**k %MOD; + ll res=1; + while(k>0) + { + if(k&1) + res=(res*v)%MOD; + k>>=1; + v=(v*v)%MOD; + } + return res; } \ No newline at end of file diff --git a/modular exponent loop.cpp b/CPP/modular exponent loop.cpp similarity index 100% rename from modular exponent loop.cpp rename to CPP/modular exponent loop.cpp diff --git a/modular exponent recursion.cpp b/CPP/modular exponent recursion.cpp similarity index 100% rename from modular exponent recursion.cpp rename to CPP/modular exponent recursion.cpp diff --git a/new.cpp b/CPP/new.cpp similarity index 100% rename from new.cpp rename to CPP/new.cpp diff --git a/no of div with seive.cpp b/CPP/no of div with seive.cpp similarity index 100% rename from no of div with seive.cpp rename to CPP/no of div with seive.cpp diff --git a/no of div without seive.cpp b/CPP/no of div without seive.cpp similarity index 100% rename from no of div without seive.cpp rename to CPP/no of div without seive.cpp diff --git a/palindromeORnot.cpp b/CPP/palindromeORnot.cpp similarity index 100% rename from palindromeORnot.cpp rename to CPP/palindromeORnot.cpp diff --git a/postfixevaluation.cpp b/CPP/postfixevaluation.cpp similarity index 100% rename from postfixevaluation.cpp rename to CPP/postfixevaluation.cpp diff --git a/prims_algo.cpp b/CPP/prims_algo.cpp similarity index 100% rename from prims_algo.cpp rename to CPP/prims_algo.cpp diff --git a/printallduplicates.cpp b/CPP/printallduplicates.cpp similarity index 100% rename from printallduplicates.cpp rename to CPP/printallduplicates.cpp diff --git a/questions.cpp b/CPP/questions.cpp similarity index 100% rename from questions.cpp rename to CPP/questions.cpp diff --git a/queues_implementation.cpp b/CPP/queues_implementation.cpp similarity index 100% rename from queues_implementation.cpp rename to CPP/queues_implementation.cpp diff --git a/queueusingstacks.cpp b/CPP/queueusingstacks.cpp similarity index 100% rename from queueusingstacks.cpp rename to CPP/queueusingstacks.cpp diff --git a/queueusingstacks2.cpp b/CPP/queueusingstacks2.cpp similarity index 100% rename from queueusingstacks2.cpp rename to CPP/queueusingstacks2.cpp diff --git a/quick_sort.cpp b/CPP/quick_sort.cpp similarity index 94% rename from quick_sort.cpp rename to CPP/quick_sort.cpp index b86460a..513f9a5 100644 --- a/quick_sort.cpp +++ b/CPP/quick_sort.cpp @@ -1,65 +1,65 @@ -#include - -using namespace std; -int partition(int input[],int si,int ei) -{ - int pivot=input[si]; - int count=0; - for(int i=si+1;i<=ei;i++) - { - if(input[i]<=pivot) - count++; - } - int pi=count+si; - input[si]=input[pi]; - input[pi]=pivot; - int i=si; - int j=ei; - while(i<=pi && j>=pi) - { - if(input[i]<=pivot) - i++; - else if(input[j]>pivot) - j--; - else - { - int temp; - temp=input[i]; - input[i]=input[j]; - input[j]=temp; - i++; - j--; - } - } - return pi; -} - -void qs(int input[],int si,int ei) -{ - if(si>=ei) - return; - int pi=partition(input,si,ei); - qs(input,si,pi-1); - qs(input,pi+1,ei); - -} - -void quickSort(int input[],int size) -{ - qs(input,0,size-1); - -} - -int main() -{ - int input[10],size; - cin>>size; - for(int i=0;i>input[i]; - quickSort(input,size); - cout<< "array after quick sort:"; - for(int i=0;i + +using namespace std; +int partition(int input[],int si,int ei) +{ + int pivot=input[si]; + int count=0; + for(int i=si+1;i<=ei;i++) + { + if(input[i]<=pivot) + count++; + } + int pi=count+si; + input[si]=input[pi]; + input[pi]=pivot; + int i=si; + int j=ei; + while(i<=pi && j>=pi) + { + if(input[i]<=pivot) + i++; + else if(input[j]>pivot) + j--; + else + { + int temp; + temp=input[i]; + input[i]=input[j]; + input[j]=temp; + i++; + j--; + } + } + return pi; +} + +void qs(int input[],int si,int ei) +{ + if(si>=ei) + return; + int pi=partition(input,si,ei); + qs(input,si,pi-1); + qs(input,pi+1,ei); + +} + +void quickSort(int input[],int size) +{ + qs(input,0,size-1); + +} + +int main() +{ + int input[10],size; + cin>>size; + for(int i=0;i>input[i]; + quickSort(input,size); + cout<< "array after quick sort:"; + for(int i=0;i -using namespace std; -bool isPossible(vector > &v, int x, int y, int a) -{ - int horBox = (x / 3) + 1; - int verBox = (y / 3) + 1; - for (int i = 0; i < 9; i++) - { - if (v[i][x] == a) - { - return false; - } - if (v[y][i] == a) - { - return false; - } - } - - for(int i = 3*(horBox-1); i < 3*horBox; i++) - { - for (int j = 3*(verBox-1); j < 3*verBox; j++) - { - if(v[j][i] == a) - return false; - } - } - return true; -} -bool sudokuHelper(int board[][9], vector > &v) -{ - int y = 0; - for(y = 0; y < 9; y++) - { - for(int i = 0; i < 9;) - { - if(board[y][i] != 0) - { - if(y == 8 && i == 8) - return true; - i++; - continue; - } - int j = v[y][i] + 1; - for(; j <= 9; j++) - { - if(isPossible(v, i, y, j)) - { - v[y][i] = j; - if(y == 8 && i == 8) - return true; - i++; - break; - } - } - if(j == 10) - { - v[y][i] = 0; - if(i == 0) - { - if(y == 0) - return false; - y--; - i = 8; - while(board[y][i] != 0) - { - i--; - if(i == 0) - { - if(y == 0) - return false; - y--; - i = 8; - } - } - continue; - } - i--; - while(board[y][i] != 0) - { - if(i == 0) - { - if(y == 0) - return false; - y--; - i = 8; - } - i--; - } - } - } - } - return false; -} -bool sudokuSolver(int board[][9]){ - vector > v(9, vector (9)); - for(int i = 0; i < 9; i++) - for(int j = 0; j < 9; j++) - v[i][j] = board[i][j]; - cout<>board[i][j]; - cout<<"__________________________________"< +using namespace std; +bool isPossible(vector > &v, int x, int y, int a) +{ + int horBox = (x / 3) + 1; + int verBox = (y / 3) + 1; + for (int i = 0; i < 9; i++) + { + if (v[i][x] == a) + { + return false; + } + if (v[y][i] == a) + { + return false; + } + } + + for(int i = 3*(horBox-1); i < 3*horBox; i++) + { + for (int j = 3*(verBox-1); j < 3*verBox; j++) + { + if(v[j][i] == a) + return false; + } + } + return true; +} +bool sudokuHelper(int board[][9], vector > &v) +{ + int y = 0; + for(y = 0; y < 9; y++) + { + for(int i = 0; i < 9;) + { + if(board[y][i] != 0) + { + if(y == 8 && i == 8) + return true; + i++; + continue; + } + int j = v[y][i] + 1; + for(; j <= 9; j++) + { + if(isPossible(v, i, y, j)) + { + v[y][i] = j; + if(y == 8 && i == 8) + return true; + i++; + break; + } + } + if(j == 10) + { + v[y][i] = 0; + if(i == 0) + { + if(y == 0) + return false; + y--; + i = 8; + while(board[y][i] != 0) + { + i--; + if(i == 0) + { + if(y == 0) + return false; + y--; + i = 8; + } + } + continue; + } + i--; + while(board[y][i] != 0) + { + if(i == 0) + { + if(y == 0) + return false; + y--; + i = 8; + } + i--; + } + } + } + } + return false; +} +bool sudokuSolver(int board[][9]){ + vector > v(9, vector (9)); + for(int i = 0; i < 9; i++) + for(int j = 0; j < 9; j++) + v[i][j] = board[i][j]; + cout<>board[i][j]; + cout<<"__________________________________"< using namespace std; @@ -22,10 +22,10 @@ int main() n2 = n2>>1; } cout << cnt << endl; - - int i; - cin >> i; - cout << __builtin_popcount(i) << endl; + + int i; + cin >> i; + cout << __builtin_popcount(i) << endl; return 0; } diff --git a/transformation_in_2D_triangle.cpp b/CPP/transformation_in_2D_triangle.cpp similarity index 100% rename from transformation_in_2D_triangle.cpp rename to CPP/transformation_in_2D_triangle.cpp diff --git a/version.cpp b/CPP/version.cpp similarity index 94% rename from version.cpp rename to CPP/version.cpp index 3daf567..3053679 100644 --- a/version.cpp +++ b/CPP/version.cpp @@ -1,41 +1,41 @@ -#include -#include -#include -#include - -using namespace std; - -struct TreeNode { - int val; - TreeNode *left; - TreeNode *right; - TreeNode(int x) : val(x), left(NULL), right(NULL) {} -}; - -TreeNode* helper(vector A, int a, int b) -{ - if(b >= a) - { - int mid = (b - a)/2; - TreeNode* root = new TreeNode(A[mid]); - root->left = helper(A, a, mid - 1); - root->right = helper(A, mid + 1, b); - } - else - return NULL; -} - - -TreeNode* sortedArrayToBST(vector A) { - return helper(A, 0, A.size() - 1); -} - -int main() -{ - vector v; - v.push_back(1); - // v.push_back(2); - // v.push_back(2147483647); - cout< +#include +#include +#include + +using namespace std; + +struct TreeNode { + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +TreeNode* helper(vector A, int a, int b) +{ + if(b >= a) + { + int mid = (b - a)/2; + TreeNode* root = new TreeNode(A[mid]); + root->left = helper(A, a, mid - 1); + root->right = helper(A, mid + 1, b); + } + else + return NULL; +} + + +TreeNode* sortedArrayToBST(vector A) { + return helper(A, 0, A.size() - 1); +} + +int main() +{ + vector v; + v.push_back(1); + // v.push_back(2); + // v.push_back(2147483647); + cout< - - - - - - Home - - - - - - - - - - - -
-
-
-
-
-
-

Statistics

- Highest paid cricketers in the world in 2020 -
-
-
-
-
- - - -

10. Kylian Mbappe – €27m
- Kylian Mbappé Lottin is a French professional footballer who plays as a forward for Ligue 1 club Paris Saint-Germain and the France national team. Considered one of the best players in the world, he is known for his finishing, dribbling, and speed.

-

9. Robert Lewandowski – €29m
- Robert Lewandowski is a Polish professional footballer who plays as a striker for Bayern Munich and is the captain of the Poland national team. He is renowned for his positioning, technique and finishing, and is widely regarded as one of the best strikers of his generation.

-

8. Raheem Sterling – €33m
- Raheem Shaquille Sterling is a professional footballer who plays as a winger and attacking midfielder for Premier League club Manchester City and the England national team. He is often considered to be one of the best players in the world

-

7. Andres Iniesta – €34m
- Andrés Iniesta Luján is a Spanish professional footballer who plays as a central midfielder for Japanese club Vissel Kobe. He spent most of his career at Barcelona, where he served as the captain for three seasons

-

6. Eden Hazard – €38m
- Eden Michael Hazard is a Belgian professional footballer who plays as a winger or attacking midfielder for Spanish club Real Madrid and captains the Belgium national team. Widely considered as one of the best players in the world, Hazard is known for his creativity, speed, acceleration, dribbling and passing.

-

5. Antoine Griezmann – €38m
-
Antoine Griezmann is a French professional footballer who plays as a forward for Spanish club Barcelona and the French national team.

-

4. Gareth Bale – €38m
- Gareth Frank Bale is a Welsh professional footballer who plays as a winger for Spanish club Real Madrid and the Wales national team.

-

3. Neymar – €95m
- Neymar da Silva Santos Júnior, commonly known as Neymar Jr. or simply Neymar, is a Brazilian professional footballer who plays as a forward for Ligue 1 club Paris Saint-Germain and the Brazil national team. He is widely considered as one of the best players in the world.

-

2. Cristiano Ronaldo – €118m
- One of the best players of this generation definitely deserves a top 3 place on this list. The 5 time Ballon d’Or winner has moved to Juventus in 2018 after 9 very successful seasons in Real Madrid. Even at the age of 35 Ronaldo earns over €100m per-year.

-

1. Lionel Messi – €131m
- Everyone could have guessed who’s the No. 1 on this list. The little magician has won everything for Barcelona. The 6 time Ballon d’Or winner is regarded as the best by many. So, the best player also deserves the highest salary.

- - -
-
-
-
-
-
    -
  • - - - - -
  • -
  • - - - - -
  • -
  • - - - - -
  • -
- -
-
-
-
-
- - - - - - + + + + + + + Home + + + + + + + + + + + +
+
+
+
+
+
+

Statistics

+ Highest paid cricketers in the world in 2020 +
+
+
+
+
+ + + +

10. Kylian Mbappe – €27m
+ Kylian Mbappé Lottin is a French professional footballer who plays as a forward for Ligue 1 club Paris Saint-Germain and the France national team. Considered one of the best players in the world, he is known for his finishing, dribbling, and speed.

+

9. Robert Lewandowski – €29m
+ Robert Lewandowski is a Polish professional footballer who plays as a striker for Bayern Munich and is the captain of the Poland national team. He is renowned for his positioning, technique and finishing, and is widely regarded as one of the best strikers of his generation.

+

8. Raheem Sterling – €33m
+ Raheem Shaquille Sterling is a professional footballer who plays as a winger and attacking midfielder for Premier League club Manchester City and the England national team. He is often considered to be one of the best players in the world

+

7. Andres Iniesta – €34m
+ Andrés Iniesta Luján is a Spanish professional footballer who plays as a central midfielder for Japanese club Vissel Kobe. He spent most of his career at Barcelona, where he served as the captain for three seasons

+

6. Eden Hazard – €38m
+ Eden Michael Hazard is a Belgian professional footballer who plays as a winger or attacking midfielder for Spanish club Real Madrid and captains the Belgium national team. Widely considered as one of the best players in the world, Hazard is known for his creativity, speed, acceleration, dribbling and passing.

+

5. Antoine Griezmann – €38m
+
Antoine Griezmann is a French professional footballer who plays as a forward for Spanish club Barcelona and the French national team.

+

4. Gareth Bale – €38m
+ Gareth Frank Bale is a Welsh professional footballer who plays as a winger for Spanish club Real Madrid and the Wales national team.

+

3. Neymar – €95m
+ Neymar da Silva Santos Júnior, commonly known as Neymar Jr. or simply Neymar, is a Brazilian professional footballer who plays as a forward for Ligue 1 club Paris Saint-Germain and the Brazil national team. He is widely considered as one of the best players in the world.

+

2. Cristiano Ronaldo – €118m
+ One of the best players of this generation definitely deserves a top 3 place on this list. The 5 time Ballon d’Or winner has moved to Juventus in 2018 after 9 very successful seasons in Real Madrid. Even at the age of 35 Ronaldo earns over €100m per-year.

+

1. Lionel Messi – €131m
+ Everyone could have guessed who’s the No. 1 on this list. The little magician has won everything for Barcelona. The 6 time Ballon d’Or winner is regarded as the best by many. So, the best player also deserves the highest salary.

+ + +
+
+
+
+
+
    +
  • + + + + +
  • +
  • + + + + +
  • +
  • + + + + +
  • +
+ +
+
+
+
+
+ + + + + + \ No newline at end of file diff --git a/ArrayOfObject in Java b/JAVA/ArrayOfObject in Java.java similarity index 100% rename from ArrayOfObject in Java rename to JAVA/ArrayOfObject in Java.java diff --git a/Gt.java b/JAVA/Gt.java similarity index 100% rename from Gt.java rename to JAVA/Gt.java diff --git a/KaratsubaAlgo.java b/JAVA/KaratsubaAlgo.java similarity index 100% rename from KaratsubaAlgo.java rename to JAVA/KaratsubaAlgo.java diff --git a/MeanMedian2.java b/JAVA/MeanMedian2.java similarity index 100% rename from MeanMedian2.java rename to JAVA/MeanMedian2.java diff --git a/PrimeCheck.java b/JAVA/PrimeCheck.java similarity index 100% rename from PrimeCheck.java rename to JAVA/PrimeCheck.java diff --git a/RandomGuess4.java b/JAVA/RandomGuess4.java similarity index 100% rename from RandomGuess4.java rename to JAVA/RandomGuess4.java diff --git a/StockBuySell.java b/JAVA/StockBuySell.java similarity index 100% rename from StockBuySell.java rename to JAVA/StockBuySell.java diff --git a/StringSort.java b/JAVA/StringSort.java similarity index 100% rename from StringSort.java rename to JAVA/StringSort.java diff --git a/Two Dimensional Array.java b/JAVA/Two Dimensional Array.java similarity index 100% rename from Two Dimensional Array.java rename to JAVA/Two Dimensional Array.java diff --git a/hotel-management-system.java b/JAVA/hotel-management-system.java similarity index 100% rename from hotel-management-system.java rename to JAVA/hotel-management-system.java diff --git a/leetcode 789.java b/JAVA/leetcode 789.java similarity index 100% rename from leetcode 789.java rename to JAVA/leetcode 789.java diff --git a/merge_sort.java b/JAVA/merge_sort.java similarity index 100% rename from merge_sort.java rename to JAVA/merge_sort.java diff --git a/optimizedprime.java b/JAVA/optimizedprime.java similarity index 100% rename from optimizedprime.java rename to JAVA/optimizedprime.java diff --git a/HelloWorld.js b/Javascript/HelloWorld.js similarity index 100% rename from HelloWorld.js rename to Javascript/HelloWorld.js diff --git a/alpha_sort.js b/Javascript/alpha_sort.js similarity index 100% rename from alpha_sort.js rename to Javascript/alpha_sort.js diff --git a/binary_search.js b/Javascript/binary_search.js similarity index 95% rename from binary_search.js rename to Javascript/binary_search.js index e3270d2..ad5806f 100644 --- a/binary_search.js +++ b/Javascript/binary_search.js @@ -1,32 +1,32 @@ -// iterative function to implement Binary Search -const binary_search = (arr, x) => { - let start = 0, - end = arr.length - 1; - - // iterate while start not meets end - while (start <= end) { - // find the mid index - let mid = Math.floor((start + end) / 2); - - // if element is present at mid, return true - if (arr[mid] === x) { - return true; - } else if (arr[mid] < x) { - start = mid + 1; - } else { - end = mid - 1; - } - } - - return false; -}; - -// driver code -const arr = [1, 3, 5, 7, 8, 9]; -const x = 5; - -if (binary_search(arr, x)) { - console.log('Element found!'); -} else { - console.log('Element not found!'); -} +// iterative function to implement Binary Search +const binary_search = (arr, x) => { + let start = 0, + end = arr.length - 1; + + // iterate while start not meets end + while (start <= end) { + // find the mid index + let mid = Math.floor((start + end) / 2); + + // if element is present at mid, return true + if (arr[mid] === x) { + return true; + } else if (arr[mid] < x) { + start = mid + 1; + } else { + end = mid - 1; + } + } + + return false; +}; + +// driver code +const arr = [1, 3, 5, 7, 8, 9]; +const x = 5; + +if (binary_search(arr, x)) { + console.log('Element found!'); +} else { + console.log('Element not found!'); +} diff --git a/bracketNotation.js b/Javascript/bracketNotation.js similarity index 100% rename from bracketNotation.js rename to Javascript/bracketNotation.js diff --git a/factorial.js b/Javascript/factorial.js similarity index 100% rename from factorial.js rename to Javascript/factorial.js diff --git a/fibonacci.js b/Javascript/fibonacci.js similarity index 100% rename from fibonacci.js rename to Javascript/fibonacci.js diff --git a/given_sum.js b/Javascript/given_sum.js similarity index 100% rename from given_sum.js rename to Javascript/given_sum.js diff --git a/golfArray.js b/Javascript/golfArray.js similarity index 100% rename from golfArray.js rename to Javascript/golfArray.js diff --git a/isArray.js b/Javascript/isArray.js similarity index 100% rename from isArray.js rename to Javascript/isArray.js diff --git a/leetcode 43.js b/Javascript/leetcode 43.js similarity index 100% rename from leetcode 43.js rename to Javascript/leetcode 43.js diff --git a/lengthOfAString.js b/Javascript/lengthOfAString.js similarity index 100% rename from lengthOfAString.js rename to Javascript/lengthOfAString.js diff --git a/mergesort.js b/Javascript/mergesort.js similarity index 100% rename from mergesort.js rename to Javascript/mergesort.js diff --git a/minimum-swapper-2.js b/Javascript/minimum-swapper-2.js similarity index 100% rename from minimum-swapper-2.js rename to Javascript/minimum-swapper-2.js diff --git a/node-rectangle.js b/Javascript/node-rectangle.js similarity index 100% rename from node-rectangle.js rename to Javascript/node-rectangle.js diff --git a/order_by_index.js b/Javascript/order_by_index.js similarity index 100% rename from order_by_index.js rename to Javascript/order_by_index.js diff --git a/prime_number.js b/Javascript/prime_number.js similarity index 100% rename from prime_number.js rename to Javascript/prime_number.js diff --git a/quick_sort.js b/Javascript/quick_sort.js similarity index 100% rename from quick_sort.js rename to Javascript/quick_sort.js diff --git a/reverseAString.js b/Javascript/reverseAString.js similarity index 100% rename from reverseAString.js rename to Javascript/reverseAString.js diff --git a/reverse_str.js b/Javascript/reverse_str.js similarity index 100% rename from reverse_str.js rename to Javascript/reverse_str.js diff --git a/romanize.js b/Javascript/romanize.js similarity index 100% rename from romanize.js rename to Javascript/romanize.js diff --git a/rotate-array-from-left.js b/Javascript/rotate-array-from-left.js similarity index 100% rename from rotate-array-from-left.js rename to Javascript/rotate-array-from-left.js diff --git a/selecting WithSwitchStmts.js b/Javascript/selecting WithSwitchStmts.js similarity index 100% rename from selecting WithSwitchStmts.js rename to Javascript/selecting WithSwitchStmts.js diff --git a/selection-sort.js b/Javascript/selection-sort.js similarity index 100% rename from selection-sort.js rename to Javascript/selection-sort.js diff --git a/List.ipynb b/Jupyter/List.ipynb similarity index 100% rename from List.ipynb rename to Jupyter/List.ipynb diff --git a/MNIST Classification using Stacked Autoencoder.ipynb b/Jupyter/MNIST Classification using Stacked Autoencoder.ipynb similarity index 100% rename from MNIST Classification using Stacked Autoencoder.ipynb rename to Jupyter/MNIST Classification using Stacked Autoencoder.ipynb diff --git a/matplotlib_graphs.ipynb b/Jupyter/matplotlib_graphs.ipynb similarity index 100% rename from matplotlib_graphs.ipynb rename to Jupyter/matplotlib_graphs.ipynb diff --git a/mirror_matrix.ipynb b/Jupyter/mirror_matrix.ipynb similarity index 100% rename from mirror_matrix.ipynb rename to Jupyter/mirror_matrix.ipynb diff --git a/nlp_with_python.ipynb b/Jupyter/nlp_with_python.ipynb similarity index 100% rename from nlp_with_python.ipynb rename to Jupyter/nlp_with_python.ipynb diff --git a/numpy_basics.ipynb b/Jupyter/numpy_basics.ipynb similarity index 100% rename from numpy_basics.ipynb rename to Jupyter/numpy_basics.ipynb diff --git a/pandas_basics.ipynb b/Jupyter/pandas_basics.ipynb similarity index 100% rename from pandas_basics.ipynb rename to Jupyter/pandas_basics.ipynb diff --git a/Leap_Year.m b/MATLAB/Leap_Year.m similarity index 100% rename from Leap_Year.m rename to MATLAB/Leap_Year.m diff --git a/TDMA.m b/MATLAB/TDMA.m similarity index 100% rename from TDMA.m rename to MATLAB/TDMA.m diff --git a/Auto.md b/Markdown/Auto.md similarity index 100% rename from Auto.md rename to Markdown/Auto.md diff --git a/Bubble.md b/Markdown/Bubble.md similarity index 100% rename from Bubble.md rename to Markdown/Bubble.md diff --git a/fenwick.md b/Markdown/fenwick.md similarity index 100% rename from fenwick.md rename to Markdown/fenwick.md diff --git a/lucky.md b/Markdown/lucky.md similarity index 100% rename from lucky.md rename to Markdown/lucky.md diff --git a/randomized_heap.md b/Markdown/randomized_heap.md similarity index 100% rename from randomized_heap.md rename to Markdown/randomized_heap.md diff --git a/zero_matrix.md b/Markdown/zero_matrix.md similarity index 100% rename from zero_matrix.md rename to Markdown/zero_matrix.md diff --git a/Automorphic Number b/No extenttion Files/Automorphic Number similarity index 100% rename from Automorphic Number rename to No extenttion Files/Automorphic Number diff --git a/Bubble sort b/No extenttion Files/Bubble sort similarity index 100% rename from Bubble sort rename to No extenttion Files/Bubble sort diff --git a/Combination-Sum b/No extenttion Files/Combination-Sum similarity index 100% rename from Combination-Sum rename to No extenttion Files/Combination-Sum diff --git a/Insertion sort b/No extenttion Files/Insertion sort similarity index 100% rename from Insertion sort rename to No extenttion Files/Insertion sort diff --git a/Island Perimeter b/No extenttion Files/Island Perimeter similarity index 100% rename from Island Perimeter rename to No extenttion Files/Island Perimeter diff --git a/JobSequencing b/No extenttion Files/JobSequencing similarity index 100% rename from JobSequencing rename to No extenttion Files/JobSequencing diff --git a/Longest palindrome substring b/No extenttion Files/Longest palindrome substring similarity index 100% rename from Longest palindrome substring rename to No extenttion Files/Longest palindrome substring diff --git a/Median of 2 sorted arrays b/No extenttion Files/Median of 2 sorted arrays similarity index 100% rename from Median of 2 sorted arrays rename to No extenttion Files/Median of 2 sorted arrays diff --git a/Palindrome Partition b/No extenttion Files/Palindrome Partition similarity index 100% rename from Palindrome Partition rename to No extenttion Files/Palindrome Partition diff --git a/Random b/No extenttion Files/Random similarity index 100% rename from Random rename to No extenttion Files/Random diff --git a/Sieve b/No extenttion Files/Sieve similarity index 100% rename from Sieve rename to No extenttion Files/Sieve diff --git a/changeArrayWithShift() b/No extenttion Files/changeArrayWithShift() similarity index 100% rename from changeArrayWithShift() rename to No extenttion Files/changeArrayWithShift() diff --git a/client-side_validation b/No extenttion Files/client-side_validation similarity index 100% rename from client-side_validation rename to No extenttion Files/client-side_validation diff --git a/clone b/No extenttion Files/clone similarity index 100% rename from clone rename to No extenttion Files/clone diff --git a/clone-graph b/No extenttion Files/clone-graph similarity index 100% rename from clone-graph rename to No extenttion Files/clone-graph diff --git a/cloning b/No extenttion Files/cloning similarity index 100% rename from cloning rename to No extenttion Files/cloning diff --git a/graph_ques b/No extenttion Files/graph_ques similarity index 100% rename from graph_ques rename to No extenttion Files/graph_ques diff --git a/minimum distance bw A and B (bfs) b/No extenttion Files/minimum distance bw A and B (bfs) similarity index 100% rename from minimum distance bw A and B (bfs) rename to No extenttion Files/minimum distance bw A and B (bfs) diff --git a/square root b/No extenttion Files/square root similarity index 100% rename from square root rename to No extenttion Files/square root diff --git a/temp b/No extenttion Files/temp similarity index 100% rename from temp rename to No extenttion Files/temp diff --git a/trie implimentation b/No extenttion Files/trie implimentation similarity index 100% rename from trie implimentation rename to No extenttion Files/trie implimentation diff --git a/Helloworld.php b/PHP/Helloworld.php similarity index 100% rename from Helloworld.php rename to PHP/Helloworld.php diff --git a/core.php b/PHP/core.php similarity index 100% rename from core.php rename to PHP/core.php diff --git a/AVL_tree_Deletion.py b/Python/AVL_tree_Deletion.py similarity index 95% rename from AVL_tree_Deletion.py rename to Python/AVL_tree_Deletion.py index be21abf..713891f 100644 --- a/AVL_tree_Deletion.py +++ b/Python/AVL_tree_Deletion.py @@ -1,203 +1,203 @@ -# Python code to delete a node in AVL tree -# Generic tree node class -class TreeNode(object): - def __init__(self, val): - self.val = val - self.left = None - self.right = None - self.height = 1 - -# AVL tree class which supports insertion, -# deletion operations -class AVL_Tree(object): - - def insert(self, root, key): - - # Step 1 - Perform normal BST - if not root: - return TreeNode(key) - elif key < root.val: - root.left = self.insert(root.left, key) - else: - root.right = self.insert(root.right, key) - - # Step 2 - Update the height of the - # ancestor node - root.height = 1 + max(self.getHeight(root.left), - self.getHeight(root.right)) - - # Step 3 - Get the balance factor - balance = self.getBalance(root) - - # Step 4 - If the node is unbalanced, - # then try out the 4 cases - # Case 1 - Left Left - if balance > 1 and key < root.left.val: - return self.rightRotate(root) - - # Case 2 - Right Right - if balance < -1 and key > root.right.val: - return self.leftRotate(root) - - # Case 3 - Left Right - if balance > 1 and key > root.left.val: - root.left = self.leftRotate(root.left) - return self.rightRotate(root) - - # Case 4 - Right Left - if balance < -1 and key < root.right.val: - root.right = self.rightRotate(root.right) - return self.leftRotate(root) - - return root - - # Recursive function to delete a node with - # given key from subtree with given root. - # It returns root of the modified subtree. - def delete(self, root, key): - - # Step 1 - Perform standard BST delete - if not root: - return root - - elif key < root.val: - root.left = self.delete(root.left, key) - - elif key > root.val: - root.right = self.delete(root.right, key) - - else: - if root.left is None: - temp = root.right - root = None - return temp - - elif root.right is None: - temp = root.left - root = None - return temp - - temp = self.getMinValueNode(root.right) - root.val = temp.val - root.right = self.delete(root.right, - temp.val) - - # If the tree has only one node, - # simply return it - if root is None: - return root - - # Step 2 - Update the height of the - # ancestor node - root.height = 1 + max(self.getHeight(root.left), - self.getHeight(root.right)) - - # Step 3 - Get the balance factor - balance = self.getBalance(root) - - # Step 4 - If the node is unbalanced, - # then try out the 4 cases - # Case 1 - Left Left - if balance > 1 and self.getBalance(root.left) >= 0: - return self.rightRotate(root) - - # Case 2 - Right Right - if balance < -1 and self.getBalance(root.right) <= 0: - return self.leftRotate(root) - - # Case 3 - Left Right - if balance > 1 and self.getBalance(root.left) < 0: - root.left = self.leftRotate(root.left) - return self.rightRotate(root) - - # Case 4 - Right Left - if balance < -1 and self.getBalance(root.right) > 0: - root.right = self.rightRotate(root.right) - return self.leftRotate(root) - - return root - - def leftRotate(self, z): - - y = z.right - T2 = y.left - - # Perform rotation - y.left = z - z.right = T2 - - # Update heights - z.height = 1 + max(self.getHeight(z.left), - self.getHeight(z.right)) - y.height = 1 + max(self.getHeight(y.left), - self.getHeight(y.right)) - - # Return the new root - return y - - def rightRotate(self, z): - - y = z.left - T3 = y.right - - # Perform rotation - y.right = z - z.left = T3 - - # Update heights - z.height = 1 + max(self.getHeight(z.left), - self.getHeight(z.right)) - y.height = 1 + max(self.getHeight(y.left), - self.getHeight(y.right)) - - # Return the new root - return y - - def getHeight(self, root): - if not root: - return 0 - - return root.height - - def getBalance(self, root): - if not root: - return 0 - - return self.getHeight(root.left) - self.getHeight(root.right) - - def getMinValueNode(self, root): - if root is None or root.left is None: - return root - - return self.getMinValueNode(root.left) - - def preOrder(self, root): - - if not root: - return - - print("{0} ".format(root.val), end="") - self.preOrder(root.left) - self.preOrder(root.right) - - -myTree = AVL_Tree() -root = None -nums = [9, 5, 10, 0, 6, 11, -1, 1, 2] - -for num in nums: - root = myTree.insert(root, num) - -# Preorder Traversal -print("Preorder Traversal after insertion -") -myTree.preOrder(root) -print() - -# Delete -key = 10 -root = myTree.delete(root, key) - -# Preorder Traversal -print("Preorder Traversal after deletion -") -myTree.preOrder(root) -print() +# Python code to delete a node in AVL tree +# Generic tree node class +class TreeNode(object): + def __init__(self, val): + self.val = val + self.left = None + self.right = None + self.height = 1 + +# AVL tree class which supports insertion, +# deletion operations +class AVL_Tree(object): + + def insert(self, root, key): + + # Step 1 - Perform normal BST + if not root: + return TreeNode(key) + elif key < root.val: + root.left = self.insert(root.left, key) + else: + root.right = self.insert(root.right, key) + + # Step 2 - Update the height of the + # ancestor node + root.height = 1 + max(self.getHeight(root.left), + self.getHeight(root.right)) + + # Step 3 - Get the balance factor + balance = self.getBalance(root) + + # Step 4 - If the node is unbalanced, + # then try out the 4 cases + # Case 1 - Left Left + if balance > 1 and key < root.left.val: + return self.rightRotate(root) + + # Case 2 - Right Right + if balance < -1 and key > root.right.val: + return self.leftRotate(root) + + # Case 3 - Left Right + if balance > 1 and key > root.left.val: + root.left = self.leftRotate(root.left) + return self.rightRotate(root) + + # Case 4 - Right Left + if balance < -1 and key < root.right.val: + root.right = self.rightRotate(root.right) + return self.leftRotate(root) + + return root + + # Recursive function to delete a node with + # given key from subtree with given root. + # It returns root of the modified subtree. + def delete(self, root, key): + + # Step 1 - Perform standard BST delete + if not root: + return root + + elif key < root.val: + root.left = self.delete(root.left, key) + + elif key > root.val: + root.right = self.delete(root.right, key) + + else: + if root.left is None: + temp = root.right + root = None + return temp + + elif root.right is None: + temp = root.left + root = None + return temp + + temp = self.getMinValueNode(root.right) + root.val = temp.val + root.right = self.delete(root.right, + temp.val) + + # If the tree has only one node, + # simply return it + if root is None: + return root + + # Step 2 - Update the height of the + # ancestor node + root.height = 1 + max(self.getHeight(root.left), + self.getHeight(root.right)) + + # Step 3 - Get the balance factor + balance = self.getBalance(root) + + # Step 4 - If the node is unbalanced, + # then try out the 4 cases + # Case 1 - Left Left + if balance > 1 and self.getBalance(root.left) >= 0: + return self.rightRotate(root) + + # Case 2 - Right Right + if balance < -1 and self.getBalance(root.right) <= 0: + return self.leftRotate(root) + + # Case 3 - Left Right + if balance > 1 and self.getBalance(root.left) < 0: + root.left = self.leftRotate(root.left) + return self.rightRotate(root) + + # Case 4 - Right Left + if balance < -1 and self.getBalance(root.right) > 0: + root.right = self.rightRotate(root.right) + return self.leftRotate(root) + + return root + + def leftRotate(self, z): + + y = z.right + T2 = y.left + + # Perform rotation + y.left = z + z.right = T2 + + # Update heights + z.height = 1 + max(self.getHeight(z.left), + self.getHeight(z.right)) + y.height = 1 + max(self.getHeight(y.left), + self.getHeight(y.right)) + + # Return the new root + return y + + def rightRotate(self, z): + + y = z.left + T3 = y.right + + # Perform rotation + y.right = z + z.left = T3 + + # Update heights + z.height = 1 + max(self.getHeight(z.left), + self.getHeight(z.right)) + y.height = 1 + max(self.getHeight(y.left), + self.getHeight(y.right)) + + # Return the new root + return y + + def getHeight(self, root): + if not root: + return 0 + + return root.height + + def getBalance(self, root): + if not root: + return 0 + + return self.getHeight(root.left) - self.getHeight(root.right) + + def getMinValueNode(self, root): + if root is None or root.left is None: + return root + + return self.getMinValueNode(root.left) + + def preOrder(self, root): + + if not root: + return + + print("{0} ".format(root.val), end="") + self.preOrder(root.left) + self.preOrder(root.right) + + +myTree = AVL_Tree() +root = None +nums = [9, 5, 10, 0, 6, 11, -1, 1, 2] + +for num in nums: + root = myTree.insert(root, num) + +# Preorder Traversal +print("Preorder Traversal after insertion -") +myTree.preOrder(root) +print() + +# Delete +key = 10 +root = myTree.delete(root, key) + +# Preorder Traversal +print("Preorder Traversal after deletion -") +myTree.preOrder(root) +print() diff --git a/AVL_tree_Insertion.py b/Python/AVL_tree_Insertion.py similarity index 96% rename from AVL_tree_Insertion.py rename to Python/AVL_tree_Insertion.py index fa0b4ef..79cc958 100644 --- a/AVL_tree_Insertion.py +++ b/Python/AVL_tree_Insertion.py @@ -1,116 +1,116 @@ -# Driver program to test above function -class TreeNode(object): - - def __init__(self, val): - self.val = val - self.left = None - self.right = None - self.height = 1 - -class AVL_Tree(object): - - def insert(self, root, key): - - if not root: - return TreeNode(key) - elif key < root.val: - root.left = self.insert(root.left, key) - else: - root.right = self.insert(root.right, key) - - root.height = 1 + max(self.getHeight(root.left), self.getHeight(root.right)) - - balance = self.getBalance(root) - - # Case 1 - Left Left - if balance > 1 and key < root.left.val: - return self.rightRotate(root) - - # Case 2 - Right Right - if balance < -1 and key > root.right.val: - return self.leftRotate(root) - - # Case 3 - Left Right - if balance > 1 and key > root.left.val: - root.left = self.leftRotate(root.left) - return self.rightRotate(root) - - # Case 4 - Right Left - if balance < -1 and key < root.right.val: - root.right = self.rightRotate(root.right) - return self.leftRotate(root) - - return root - - def leftRotate(self, z): - y = z.right - T2 = z.left - - # Perform rotation - y.left = z - z.right = T2 - - # Update heights - z.height = 1 + max(self.getHeight(z.left), self.getHeight(z.right)) - y.height = 1 + max(self.getHeight(y.left), self.getHeight(y.right)) - - return y - - def rightRotate(self, z): - y = z.left - T3 = y.right - - # Perform Rotation - y.right = z - z.left = T3 - - # Update heights - z.height = 1 + max(self.getHeight(z.left), self.getHeight(z.right)) - y.height = 1 + max(self.getHeight(y.left), self.getHeight(y.right)) - - return y - - def getHeight(self, root): - if not root: - return 0 - return root.height - - def getBalance(self, root): - if not root: - return 0 - - return self.getHeight(root.left) - self.getHeight(root.right) - - def preOrder(self, root): - if root: - - print(root.val,end=" ") - - self.preOrder(root.left) - - self.preOrder(root.right) - - return - -# Driver's Program -myTree = AVL_Tree() -root = None - -root = myTree.insert(root, 10) -root = myTree.insert(root, 20) -root = myTree.insert(root, 30) -root = myTree.insert(root, 40) -root = myTree.insert(root, 50) -root = myTree.insert(root, 25) - -"""The constructed AVL Tree would be - 30 - / \ - 20 40 - / \ \ - 10 25 50""" - -# Preorder Traversal -print("Preorder traversal of the constructed AVL tree is") - -myTree.preOrder(root) +# Driver program to test above function +class TreeNode(object): + + def __init__(self, val): + self.val = val + self.left = None + self.right = None + self.height = 1 + +class AVL_Tree(object): + + def insert(self, root, key): + + if not root: + return TreeNode(key) + elif key < root.val: + root.left = self.insert(root.left, key) + else: + root.right = self.insert(root.right, key) + + root.height = 1 + max(self.getHeight(root.left), self.getHeight(root.right)) + + balance = self.getBalance(root) + + # Case 1 - Left Left + if balance > 1 and key < root.left.val: + return self.rightRotate(root) + + # Case 2 - Right Right + if balance < -1 and key > root.right.val: + return self.leftRotate(root) + + # Case 3 - Left Right + if balance > 1 and key > root.left.val: + root.left = self.leftRotate(root.left) + return self.rightRotate(root) + + # Case 4 - Right Left + if balance < -1 and key < root.right.val: + root.right = self.rightRotate(root.right) + return self.leftRotate(root) + + return root + + def leftRotate(self, z): + y = z.right + T2 = z.left + + # Perform rotation + y.left = z + z.right = T2 + + # Update heights + z.height = 1 + max(self.getHeight(z.left), self.getHeight(z.right)) + y.height = 1 + max(self.getHeight(y.left), self.getHeight(y.right)) + + return y + + def rightRotate(self, z): + y = z.left + T3 = y.right + + # Perform Rotation + y.right = z + z.left = T3 + + # Update heights + z.height = 1 + max(self.getHeight(z.left), self.getHeight(z.right)) + y.height = 1 + max(self.getHeight(y.left), self.getHeight(y.right)) + + return y + + def getHeight(self, root): + if not root: + return 0 + return root.height + + def getBalance(self, root): + if not root: + return 0 + + return self.getHeight(root.left) - self.getHeight(root.right) + + def preOrder(self, root): + if root: + + print(root.val,end=" ") + + self.preOrder(root.left) + + self.preOrder(root.right) + + return + +# Driver's Program +myTree = AVL_Tree() +root = None + +root = myTree.insert(root, 10) +root = myTree.insert(root, 20) +root = myTree.insert(root, 30) +root = myTree.insert(root, 40) +root = myTree.insert(root, 50) +root = myTree.insert(root, 25) + +"""The constructed AVL Tree would be + 30 + / \ + 20 40 + / \ \ + 10 25 50""" + +# Preorder Traversal +print("Preorder traversal of the constructed AVL tree is") + +myTree.preOrder(root) diff --git a/BST.py b/Python/BST.py similarity index 96% rename from BST.py rename to Python/BST.py index e47efbb..6d493da 100644 --- a/BST.py +++ b/Python/BST.py @@ -1,161 +1,161 @@ -class Node: - def __init__(self, value): - self.value = value - self.left = None - self.right = None - - -class BinarySearchTree: - def __init__(self): - self.root = None - - def insert(self, value): - node = Node(value) - temp = self.root - if temp is None: - self.root = node - else: - while True: - if temp.value == value : - print("Redundant values are not allowed!") - break - if temp.value > value: - if temp.left is None: - temp.left = node - break - temp = temp.left - else: - if temp.right is None: - temp.right = node - break - temp = temp.right - - def deletion(self, value): - temp = self.root - if temp is None: - print("Tree is Empty!") - else: - while temp.value != value: - temp3 = temp - if temp.value > value: - if temp.left is None: - print("Value not found!") - break - temp = temp.left - else: - if temp.value < value: - if temp.right is None: - print("Value not found!") - break - temp = temp.right - else: - while True: - if temp.left: - temp2 = temp.left - while True: - if temp2.right: - temp3 = temp2 - temp2 = temp2.right - else: - temp.value = temp2.value - temp = temp2 - break - elif temp.right: - temp2 = temp.right - while True: - if temp2.left: - temp3 = temp2 - temp2 = temp2.left - - else: - temp.value = temp2.value - temp = temp2 - break - else: - if temp3.left : - if temp3.left.value == temp.value : - temp3.left = None - temp3.right = None - else : - temp3.right = None - - break - - def inorder(self): - root = self.root - print("Inorder :", end="") - - def inorderp(root): - if root: - inorderp(root.left) - print(root.value, end=" ") - inorderp(root.right) - inorderp(root) - print() - - def postorder(self): - root = self.root - print("Postorder :", end=" ") - - def postorderp(root): - if root: - postorderp(root.left) - postorderp(root.right) - print(root.value, end=" ") - postorderp(root) - print() - - def preorder(self): - root = self.root - print("Preorder :", end="") - - def preorderp(root): - if root: - print(root.value, end=" ") - preorderp(root.left) - preorderp(root.right) - preorderp(root) - print() - - def search(self, value): - temp = self.root - flag = 0 - if temp is None: - print("Tree is Empty!") - else: - while temp is not None: - if temp.value == value: - flag = 1 - break - elif temp.value < value: - temp = temp.right - else: - temp = temp.left - if flag == 1: - print("Value found in the tree") - return True - else: - print("Value not found in the tree") - return False - - -tree = BinarySearchTree() -print("Enter the operations you want to perform :\n1 ,for insertion\n2,for deletion\n3,for printing tree in postorder\n4, in inorder\n5,in preorder \n 6 to exit \n ") -while True : - input1 = int(input("Enter the number: ")) - if input1 == 1 : - tree.insert(int(input("Enter the number you want to insert : "))) - print() - elif input1 == 2 : - tree.deletion(int(input("Enter the you wanna delete :"))) - print() - elif input1 == 3: - tree.postorder() - elif input1 == 4: - tree.inorder() - elif input1 == 5: - tree.preorder() - elif input1 == 6 : - break - else : - print("Invalid Key !") +class Node: + def __init__(self, value): + self.value = value + self.left = None + self.right = None + + +class BinarySearchTree: + def __init__(self): + self.root = None + + def insert(self, value): + node = Node(value) + temp = self.root + if temp is None: + self.root = node + else: + while True: + if temp.value == value : + print("Redundant values are not allowed!") + break + if temp.value > value: + if temp.left is None: + temp.left = node + break + temp = temp.left + else: + if temp.right is None: + temp.right = node + break + temp = temp.right + + def deletion(self, value): + temp = self.root + if temp is None: + print("Tree is Empty!") + else: + while temp.value != value: + temp3 = temp + if temp.value > value: + if temp.left is None: + print("Value not found!") + break + temp = temp.left + else: + if temp.value < value: + if temp.right is None: + print("Value not found!") + break + temp = temp.right + else: + while True: + if temp.left: + temp2 = temp.left + while True: + if temp2.right: + temp3 = temp2 + temp2 = temp2.right + else: + temp.value = temp2.value + temp = temp2 + break + elif temp.right: + temp2 = temp.right + while True: + if temp2.left: + temp3 = temp2 + temp2 = temp2.left + + else: + temp.value = temp2.value + temp = temp2 + break + else: + if temp3.left : + if temp3.left.value == temp.value : + temp3.left = None + temp3.right = None + else : + temp3.right = None + + break + + def inorder(self): + root = self.root + print("Inorder :", end="") + + def inorderp(root): + if root: + inorderp(root.left) + print(root.value, end=" ") + inorderp(root.right) + inorderp(root) + print() + + def postorder(self): + root = self.root + print("Postorder :", end=" ") + + def postorderp(root): + if root: + postorderp(root.left) + postorderp(root.right) + print(root.value, end=" ") + postorderp(root) + print() + + def preorder(self): + root = self.root + print("Preorder :", end="") + + def preorderp(root): + if root: + print(root.value, end=" ") + preorderp(root.left) + preorderp(root.right) + preorderp(root) + print() + + def search(self, value): + temp = self.root + flag = 0 + if temp is None: + print("Tree is Empty!") + else: + while temp is not None: + if temp.value == value: + flag = 1 + break + elif temp.value < value: + temp = temp.right + else: + temp = temp.left + if flag == 1: + print("Value found in the tree") + return True + else: + print("Value not found in the tree") + return False + + +tree = BinarySearchTree() +print("Enter the operations you want to perform :\n1 ,for insertion\n2,for deletion\n3,for printing tree in postorder\n4, in inorder\n5,in preorder \n 6 to exit \n ") +while True : + input1 = int(input("Enter the number: ")) + if input1 == 1 : + tree.insert(int(input("Enter the number you want to insert : "))) + print() + elif input1 == 2 : + tree.deletion(int(input("Enter the you wanna delete :"))) + print() + elif input1 == 3: + tree.postorder() + elif input1 == 4: + tree.inorder() + elif input1 == 5: + tree.preorder() + elif input1 == 6 : + break + else : + print("Invalid Key !") diff --git a/Binarysearch.py b/Python/Binarysearch.py similarity index 100% rename from Binarysearch.py rename to Python/Binarysearch.py diff --git a/BitonicSort.py b/Python/BitonicSort.py similarity index 100% rename from BitonicSort.py rename to Python/BitonicSort.py diff --git a/Catalan_Number_python.py b/Python/Catalan_Number_python.py similarity index 100% rename from Catalan_Number_python.py rename to Python/Catalan_Number_python.py diff --git a/CountPrimesUsingSieve.py b/Python/CountPrimesUsingSieve.py similarity index 100% rename from CountPrimesUsingSieve.py rename to Python/CountPrimesUsingSieve.py diff --git a/CyclicSort.py b/Python/CyclicSort.py similarity index 100% rename from CyclicSort.py rename to Python/CyclicSort.py diff --git a/Fisher_Yates.py b/Python/Fisher_Yates.py similarity index 100% rename from Fisher_Yates.py rename to Python/Fisher_Yates.py diff --git a/GUI_AgeCalculator.py b/Python/GUI_AgeCalculator.py similarity index 100% rename from GUI_AgeCalculator.py rename to Python/GUI_AgeCalculator.py diff --git a/Guessing_Number.py b/Python/Guessing_Number.py similarity index 100% rename from Guessing_Number.py rename to Python/Guessing_Number.py diff --git a/Inorder_Successor_BinaryTree.py b/Python/Inorder_Successor_BinaryTree.py similarity index 100% rename from Inorder_Successor_BinaryTree.py rename to Python/Inorder_Successor_BinaryTree.py diff --git a/JPGtoPNG_Converter.py b/Python/JPGtoPNG_Converter.py similarity index 100% rename from JPGtoPNG_Converter.py rename to Python/JPGtoPNG_Converter.py diff --git a/KadaneAlgorithm.py b/Python/KadaneAlgorithm.py similarity index 100% rename from KadaneAlgorithm.py rename to Python/KadaneAlgorithm.py diff --git a/Larry's-Array.py b/Python/Larry's-Array.py similarity index 100% rename from Larry's-Array.py rename to Python/Larry's-Array.py diff --git a/Level_Order_Traversal(BFS).py b/Python/Level_Order_Traversal(BFS).py similarity index 95% rename from Level_Order_Traversal(BFS).py rename to Python/Level_Order_Traversal(BFS).py index 09f9293..4bec84c 100644 --- a/Level_Order_Traversal(BFS).py +++ b/Python/Level_Order_Traversal(BFS).py @@ -1,64 +1,64 @@ - -class Node: - - def __init__(self, key): - self.data = key - self.left = None - self.right = None - -# ____________Recursive Approach_________ -# def printLevelorder(root): -# h = height(root) -# for i in range(1, h+1): -# printCurrentLevel(root, i) - -# def printCurrentLevel(root, level): -# if root is None: -# return -# if level == 1: -# print(root.data, end=" ") -# else: -# printCurrentLevel(root.left, level-1) -# printCurrentLevel(root.right, level-1) - -# def height(node): -# if node: -# lheight = height(node.left) -# rheight = height(node.right) - -# if lheight > rheight: -# return lheight + 1 -# else: -# return rheight + 1 -# return 0 - -# ___________Queue Method____________ -def printLevelorder(root): - if root is None: - return - - queue = [] - - queue.append(root) - - while len(queue) > 0: - - node = queue.pop(0) - print(node.data, end = " ") - - if node.left: - queue.append(node.left) - - if node.right: - queue.append(node.right) - - -# Driver's program -root = Node(1) -root.left = Node(2) -root.right = Node(3) -root.left.left = Node(4) -root.left.right = Node(5) - -print("Level order traversal of binary tree is - ") + +class Node: + + def __init__(self, key): + self.data = key + self.left = None + self.right = None + +# ____________Recursive Approach_________ +# def printLevelorder(root): +# h = height(root) +# for i in range(1, h+1): +# printCurrentLevel(root, i) + +# def printCurrentLevel(root, level): +# if root is None: +# return +# if level == 1: +# print(root.data, end=" ") +# else: +# printCurrentLevel(root.left, level-1) +# printCurrentLevel(root.right, level-1) + +# def height(node): +# if node: +# lheight = height(node.left) +# rheight = height(node.right) + +# if lheight > rheight: +# return lheight + 1 +# else: +# return rheight + 1 +# return 0 + +# ___________Queue Method____________ +def printLevelorder(root): + if root is None: + return + + queue = [] + + queue.append(root) + + while len(queue) > 0: + + node = queue.pop(0) + print(node.data, end = " ") + + if node.left: + queue.append(node.left) + + if node.right: + queue.append(node.right) + + +# Driver's program +root = Node(1) +root.left = Node(2) +root.right = Node(3) +root.left.left = Node(4) +root.left.right = Node(5) + +print("Level order traversal of binary tree is - ") printLevelorder(root) \ No newline at end of file diff --git a/Linear_search.py b/Python/Linear_search.py similarity index 100% rename from Linear_search.py rename to Python/Linear_search.py diff --git a/MSP.py b/Python/MSP.py similarity index 100% rename from MSP.py rename to Python/MSP.py diff --git a/Max_Subarray.py b/Python/Max_Subarray.py similarity index 100% rename from Max_Subarray.py rename to Python/Max_Subarray.py diff --git a/MergeSortPythonCCSC.py b/Python/MergeSortPythonCCSC.py similarity index 100% rename from MergeSortPythonCCSC.py rename to Python/MergeSortPythonCCSC.py diff --git a/PathSum.py b/Python/PathSum.py similarity index 100% rename from PathSum.py rename to Python/PathSum.py diff --git a/Peak_array.py b/Python/Peak_array.py similarity index 100% rename from Peak_array.py rename to Python/Peak_array.py diff --git a/QueenAttack.py b/Python/QueenAttack.py similarity index 95% rename from QueenAttack.py rename to Python/QueenAttack.py index adee0e4..be6a5aa 100644 --- a/QueenAttack.py +++ b/Python/QueenAttack.py @@ -1,79 +1,79 @@ -def initialize(n): - for key in ['queen', 'row', 'col', 'nwtose', 'swtone']: - board[key] = {} - for i in range(n): - board['queen'][i] = -1 - board['row'][i] = 0 - board['col'][i] = 0 - for i in range(-(n - 1), n): - board['nwtose'][i] = 0 - for i in range(2 * n - 1): - board['swtone'][i] = 0 - - -def printing(t, n): - for i in range(n): - print("----" * n, end="") - print("-") - for j in range(n): - if (i, j) in t: - print("| {} ".format("Q"), end="") - else: - print("| ", end="") - - print("|") - print("----" * n, end="") - print("-") - - -def printboard(): - print(board) - li = list() - for row in sorted(board['queen'].keys()): - li.append((row, board['queen'][row])) - printing(li, len(li)) - - -def free(i, j): - return(board['row'][i] == 0 and board['col'][j] == 0 and - board['nwtose'][j - i] == 0 and board['swtone'][j + i] == 0) - - -def addqueen(i, j): - board['queen'][i] = j - board['row'][i] = 1 - board['col'][j] = 1 - board['nwtose'][j - i] = 1 - board['swtone'][j + i] = 1 - - -def undoqueen(i, j): - board['queen'][i] = -1 - board['row'][i] = 0 - board['col'][j] = 0 - board['nwtose'][j - i] = 0 - board['swtone'][j + i] = 0 - - -def placequeen(i): - n = len(board['queen'].keys()) - for j in range(n): - if free(i, j): - addqueen(i, j) - if i == n - 1: - return(True) - else: - extendsoln = placequeen(i + 1) - if extendsoln: - return(True) - else: - undoqueen(i, j) - else: - return(False) - - -board = {} -n = int(input("How many queens? ")) -initialize(n) -if placequeen(0): - printboard() +def initialize(n): + for key in ['queen', 'row', 'col', 'nwtose', 'swtone']: + board[key] = {} + for i in range(n): + board['queen'][i] = -1 + board['row'][i] = 0 + board['col'][i] = 0 + for i in range(-(n - 1), n): + board['nwtose'][i] = 0 + for i in range(2 * n - 1): + board['swtone'][i] = 0 + + +def printing(t, n): + for i in range(n): + print("----" * n, end="") + print("-") + for j in range(n): + if (i, j) in t: + print("| {} ".format("Q"), end="") + else: + print("| ", end="") + + print("|") + print("----" * n, end="") + print("-") + + +def printboard(): + print(board) + li = list() + for row in sorted(board['queen'].keys()): + li.append((row, board['queen'][row])) + printing(li, len(li)) + + +def free(i, j): + return(board['row'][i] == 0 and board['col'][j] == 0 and + board['nwtose'][j - i] == 0 and board['swtone'][j + i] == 0) + + +def addqueen(i, j): + board['queen'][i] = j + board['row'][i] = 1 + board['col'][j] = 1 + board['nwtose'][j - i] = 1 + board['swtone'][j + i] = 1 + + +def undoqueen(i, j): + board['queen'][i] = -1 + board['row'][i] = 0 + board['col'][j] = 0 + board['nwtose'][j - i] = 0 + board['swtone'][j + i] = 0 + + +def placequeen(i): + n = len(board['queen'].keys()) + for j in range(n): + if free(i, j): + addqueen(i, j) + if i == n - 1: + return(True) + else: + extendsoln = placequeen(i + 1) + if extendsoln: + return(True) + else: + undoqueen(i, j) + else: + return(False) + + +board = {} +n = int(input("How many queens? ")) +initialize(n) +if placequeen(0): + printboard() diff --git a/QuickSort.py b/Python/QuickSort.py similarity index 100% rename from QuickSort.py rename to Python/QuickSort.py diff --git a/SelectionSort.py b/Python/SelectionSort.py similarity index 100% rename from SelectionSort.py rename to Python/SelectionSort.py diff --git a/Siteblocker.py b/Python/Siteblocker.py similarity index 100% rename from Siteblocker.py rename to Python/Siteblocker.py diff --git a/Stack.py b/Python/Stack.py similarity index 100% rename from Stack.py rename to Python/Stack.py diff --git a/StonePaperScissors.py b/Python/StonePaperScissors.py similarity index 100% rename from StonePaperScissors.py rename to Python/StonePaperScissors.py diff --git a/TowerOfHanoi.py b/Python/TowerOfHanoi.py similarity index 96% rename from TowerOfHanoi.py rename to Python/TowerOfHanoi.py index 9c63d8e..a89c99e 100644 --- a/TowerOfHanoi.py +++ b/Python/TowerOfHanoi.py @@ -1,15 +1,15 @@ -# Python function for the problem of Tower of Hanoi - -def TowerOfHanoi(n , from_rod, to_rod, aux_rod): - if n == 1: - print "Move disk 1 from rod",from_rod,"to rod",to_rod - return - TowerOfHanoi(n-1, from_rod, aux_rod, to_rod) - print "Move disk",n,"from rod",from_rod,"to rod",to_rod - TowerOfHanoi(n-1, aux_rod, to_rod, from_rod) - -# driver code -n = 4 -TowerOfHanoi(n, 'a', 'c', 'b') - +# Python function for the problem of Tower of Hanoi + +def TowerOfHanoi(n , from_rod, to_rod, aux_rod): + if n == 1: + print "Move disk 1 from rod",from_rod,"to rod",to_rod + return + TowerOfHanoi(n-1, from_rod, aux_rod, to_rod) + print "Move disk",n,"from rod",from_rod,"to rod",to_rod + TowerOfHanoi(n-1, aux_rod, to_rod, from_rod) + +# driver code +n = 4 +TowerOfHanoi(n, 'a', 'c', 'b') + #contributed by AnushkaGarg26 \ No newline at end of file diff --git a/aes.py b/Python/aes.py similarity index 100% rename from aes.py rename to Python/aes.py diff --git a/aks prime test.py b/Python/aks prime test.py similarity index 100% rename from aks prime test.py rename to Python/aks prime test.py diff --git a/balanced_paranthesis.py b/Python/balanced_paranthesis.py similarity index 100% rename from balanced_paranthesis.py rename to Python/balanced_paranthesis.py diff --git a/bellmenford.py b/Python/bellmenford.py similarity index 100% rename from bellmenford.py rename to Python/bellmenford.py diff --git a/binary_search.py b/Python/binary_search.py similarity index 100% rename from binary_search.py rename to Python/binary_search.py diff --git a/bmi-calculator.py b/Python/bmi-calculator.py similarity index 100% rename from bmi-calculator.py rename to Python/bmi-calculator.py diff --git a/bmi.py b/Python/bmi.py similarity index 100% rename from bmi.py rename to Python/bmi.py diff --git a/bubble_sort.py b/Python/bubble_sort.py similarity index 100% rename from bubble_sort.py rename to Python/bubble_sort.py diff --git a/calculator.py b/Python/calculator.py similarity index 100% rename from calculator.py rename to Python/calculator.py diff --git a/clock.py b/Python/clock.py similarity index 100% rename from clock.py rename to Python/clock.py diff --git a/count_inversions.py b/Python/count_inversions.py similarity index 95% rename from count_inversions.py rename to Python/count_inversions.py index 38db0a2..1a4a487 100644 --- a/count_inversions.py +++ b/Python/count_inversions.py @@ -1,61 +1,61 @@ -def inversionsCount(arr, n): - - tmp_arr = [0]*n - return mergeSort(arr, tmp_arr, 0, n-1) - -def mergeSort(arr, temp_arr, left, right): - - inv_count = 0 - - if left < right: - - mid = (left + right)//2 - - inv_count += mergeSort(arr, temp_arr, left, mid) - - inv_count += mergeSort(arr, temp_arr, mid+1, right) - - inv_count += merge(arr, temp_arr, left, mid, right) - - return inv_count - -def merge(arr, temp_arr, left, mid, right): - i = left - j = mid+1 - k = left - inv_count = 0 - - while i <= mid and j <= right: - - if arr[i] <= arr[j]: - temp_arr[k] = arr[i] - k += 1 - i += 1 - else: - # Inversion will occur - temp_arr[k] = arr[j] - inv_count += (mid-i + 1) - k += 1 - j += 1 - - while i <= mid: - temp_arr[k] = arr[i] - k += 1 - i += 1 - - while j <= right: - temp_arr[k] = arr[j] - k += 1 - j += 1 - - for var in range(left, right + 1): - arr[var] = temp_arr[var] - print(arr) - return inv_count - - -# Driver's Code -arr = [1, 20, 6, 4, 5, 19] -n = len(arr) -result = inversionsCount(arr, n) +def inversionsCount(arr, n): + + tmp_arr = [0]*n + return mergeSort(arr, tmp_arr, 0, n-1) + +def mergeSort(arr, temp_arr, left, right): + + inv_count = 0 + + if left < right: + + mid = (left + right)//2 + + inv_count += mergeSort(arr, temp_arr, left, mid) + + inv_count += mergeSort(arr, temp_arr, mid+1, right) + + inv_count += merge(arr, temp_arr, left, mid, right) + + return inv_count + +def merge(arr, temp_arr, left, mid, right): + i = left + j = mid+1 + k = left + inv_count = 0 + + while i <= mid and j <= right: + + if arr[i] <= arr[j]: + temp_arr[k] = arr[i] + k += 1 + i += 1 + else: + # Inversion will occur + temp_arr[k] = arr[j] + inv_count += (mid-i + 1) + k += 1 + j += 1 + + while i <= mid: + temp_arr[k] = arr[i] + k += 1 + i += 1 + + while j <= right: + temp_arr[k] = arr[j] + k += 1 + j += 1 + + for var in range(left, right + 1): + arr[var] = temp_arr[var] + print(arr) + return inv_count + + +# Driver's Code +arr = [1, 20, 6, 4, 5, 19] +n = len(arr) +result = inversionsCount(arr, n) print("Number of inversions are", result) \ No newline at end of file diff --git a/cycleSort.py b/Python/cycleSort.py similarity index 100% rename from cycleSort.py rename to Python/cycleSort.py diff --git a/cycle_detection_linked_list.py b/Python/cycle_detection_linked_list.py similarity index 100% rename from cycle_detection_linked_list.py rename to Python/cycle_detection_linked_list.py diff --git a/diameter_Btree.py b/Python/diameter_Btree.py similarity index 95% rename from diameter_Btree.py rename to Python/diameter_Btree.py index 0ac6c48..85d3663 100644 --- a/diameter_Btree.py +++ b/Python/diameter_Btree.py @@ -1,31 +1,31 @@ -class Node: - def __init__(self, val=0, left=None, right=None): - self.val = val - self.left = left - self.right = right - -def diameter(root) -> int: - d = [0] - def dfs(root): - if not root: - return -1 - - left = dfs(root.left) - right = dfs(root.right) - d[0] = max(d[0], left+right+2) - - return 1 + max(left, right) - - dfs(root) - return d[0] - - - -root = Node(1) -root.left = Node(2) -root.right = Node(3) -root.left.left = Node(4) -root.left.right = Node(5) -root.right.left = Node(6) -# Function Call +class Node: + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + +def diameter(root) -> int: + d = [0] + def dfs(root): + if not root: + return -1 + + left = dfs(root.left) + right = dfs(root.right) + d[0] = max(d[0], left+right+2) + + return 1 + max(left, right) + + dfs(root) + return d[0] + + + +root = Node(1) +root.left = Node(2) +root.right = Node(3) +root.left.left = Node(4) +root.left.right = Node(5) +root.right.left = Node(6) +# Function Call print(diameter(root)) \ No newline at end of file diff --git a/dijkstra.py b/Python/dijkstra.py similarity index 100% rename from dijkstra.py rename to Python/dijkstra.py diff --git a/fraction.py b/Python/fraction.py similarity index 100% rename from fraction.py rename to Python/fraction.py diff --git a/hybrid_sort.py b/Python/hybrid_sort.py similarity index 100% rename from hybrid_sort.py rename to Python/hybrid_sort.py diff --git a/insertion-sort.py b/Python/insertion-sort.py similarity index 100% rename from insertion-sort.py rename to Python/insertion-sort.py diff --git a/knapsack.py b/Python/knapsack.py similarity index 100% rename from knapsack.py rename to Python/knapsack.py diff --git a/kruskal.py b/Python/kruskal.py similarity index 100% rename from kruskal.py rename to Python/kruskal.py diff --git a/livecliterminal.py b/Python/livecliterminal.py similarity index 96% rename from livecliterminal.py rename to Python/livecliterminal.py index 28220fa..d6a1db4 100644 --- a/livecliterminal.py +++ b/Python/livecliterminal.py @@ -1,17 +1,17 @@ -#use_yum-install-httpd for downlaod apache server -#yum start httpd for running the apache server -#! /usr/bin/python3 -import cgi -import subprocess -import json -print("content-type: text/html") -print() - -user_input = cgi.FIeldStorage() -command = user_input.getvalue("x") -output= subprocess.getstatusoutput("{0}".format(command)) -StatusCode = output[0] -result = output[1] -db = {"Result" : result, "statusCode" : StatusCode} -finalResult = json.dumps(db) -print(finalResult) +#use_yum-install-httpd for downlaod apache server +#yum start httpd for running the apache server +#! /usr/bin/python3 +import cgi +import subprocess +import json +print("content-type: text/html") +print() + +user_input = cgi.FIeldStorage() +command = user_input.getvalue("x") +output= subprocess.getstatusoutput("{0}".format(command)) +StatusCode = output[0] +result = output[1] +db = {"Result" : result, "statusCode" : StatusCode} +finalResult = json.dumps(db) +print(finalResult) diff --git a/mandelbrot_Set.py b/Python/mandelbrot_Set.py similarity index 100% rename from mandelbrot_Set.py rename to Python/mandelbrot_Set.py diff --git a/matching_paren.py b/Python/matching_paren.py similarity index 100% rename from matching_paren.py rename to Python/matching_paren.py diff --git a/matrixMultiply.py b/Python/matrixMultiply.py similarity index 100% rename from matrixMultiply.py rename to Python/matrixMultiply.py diff --git a/merge_sort.py b/Python/merge_sort.py similarity index 100% rename from merge_sort.py rename to Python/merge_sort.py diff --git a/min_in_sorted_&_rotated_array.py b/Python/min_in_sorted_&_rotated_array.py similarity index 96% rename from min_in_sorted_&_rotated_array.py rename to Python/min_in_sorted_&_rotated_array.py index ebfd411..b5df0da 100644 --- a/min_in_sorted_&_rotated_array.py +++ b/Python/min_in_sorted_&_rotated_array.py @@ -1,63 +1,63 @@ -def findMin(arr, low, high): - # This condition is needed to handle the case when array is not - # rotated at all - if high < low: - return arr[0] - - # If there is only one element left - if high == low: - return arr[low] - - # Find mid - mid = int((low + high)/2) - - # Check if element (mid+1) is minimum element. Consider - # the cases like [3, 4, 5, 1, 2] - if mid < high and arr[mid+1] < arr[mid]: - return arr[mid+1] - - # Check if mid itself is minimum element - if mid > low and arr[mid] < arr[mid - 1]: - return arr[mid] - - # Decide whether we need to go to left half or right half - if arr[high] > arr[mid]: - return findMin(arr, low, mid-1) - return findMin(arr, mid+1, high) - -# Driver program to test above functions -arr1 = [5, 6, 1, 2, 3, 4] -n1 = len(arr1) -print("The minimum element is " + str(findMin(arr1, 0, n1-1))) - -arr2 = [1, 2, 3, 4] -n2 = len(arr2) -print("The minimum element is " + str(findMin(arr2, 0, n2-1))) - -arr3 = [1] -n3 = len(arr3) -print("The minimum element is " + str(findMin(arr3, 0, n3-1))) - -arr4 = [1, 2] -n4 = len(arr4) -print("The minimum element is " + str(findMin(arr4, 0, n4-1))) - -arr5 = [2, 1] -n5 = len(arr5) -print("The minimum element is " + str(findMin(arr5, 0, n5-1))) - -arr6 = [5, 6, 7, 1, 2, 3, 4] -n6 = len(arr6) -print("The minimum element is " + str(findMin(arr6, 0, n6-1))) - -arr7 = [1, 2, 3, 4, 5, 6, 7] -n7 = len(arr7) -print("The minimum element is " + str(findMin(arr7, 0, n7-1))) - -arr8 = [2, 3, 4, 5, 6, 7, 8, 1] -n8 = len(arr8) -print("The minimum element is " + str(findMin(arr8, 0, n8-1))) - -arr9 = [3, 4, 5, 1, 2] -n9 = len(arr9) +def findMin(arr, low, high): + # This condition is needed to handle the case when array is not + # rotated at all + if high < low: + return arr[0] + + # If there is only one element left + if high == low: + return arr[low] + + # Find mid + mid = int((low + high)/2) + + # Check if element (mid+1) is minimum element. Consider + # the cases like [3, 4, 5, 1, 2] + if mid < high and arr[mid+1] < arr[mid]: + return arr[mid+1] + + # Check if mid itself is minimum element + if mid > low and arr[mid] < arr[mid - 1]: + return arr[mid] + + # Decide whether we need to go to left half or right half + if arr[high] > arr[mid]: + return findMin(arr, low, mid-1) + return findMin(arr, mid+1, high) + +# Driver program to test above functions +arr1 = [5, 6, 1, 2, 3, 4] +n1 = len(arr1) +print("The minimum element is " + str(findMin(arr1, 0, n1-1))) + +arr2 = [1, 2, 3, 4] +n2 = len(arr2) +print("The minimum element is " + str(findMin(arr2, 0, n2-1))) + +arr3 = [1] +n3 = len(arr3) +print("The minimum element is " + str(findMin(arr3, 0, n3-1))) + +arr4 = [1, 2] +n4 = len(arr4) +print("The minimum element is " + str(findMin(arr4, 0, n4-1))) + +arr5 = [2, 1] +n5 = len(arr5) +print("The minimum element is " + str(findMin(arr5, 0, n5-1))) + +arr6 = [5, 6, 7, 1, 2, 3, 4] +n6 = len(arr6) +print("The minimum element is " + str(findMin(arr6, 0, n6-1))) + +arr7 = [1, 2, 3, 4, 5, 6, 7] +n7 = len(arr7) +print("The minimum element is " + str(findMin(arr7, 0, n7-1))) + +arr8 = [2, 3, 4, 5, 6, 7, 8, 1] +n8 = len(arr8) +print("The minimum element is " + str(findMin(arr8, 0, n8-1))) + +arr9 = [3, 4, 5, 1, 2] +n9 = len(arr9) print("The minimum element is " + str(findMin(arr9, 0, n9-1))) \ No newline at end of file diff --git a/missing-number.py b/Python/missing-number.py similarity index 93% rename from missing-number.py rename to Python/missing-number.py index 9126e6d..88ce6d0 100644 --- a/missing-number.py +++ b/Python/missing-number.py @@ -1,18 +1,18 @@ -n = int(input()) -arr = list(map(int,input().split())) - -sum = sum(arr) -exp = (n)*(n+1)/2 -print(int(exp-sum)) - - - -"""temp = 0 -arr = sorted(arr) -for i in range(len(arr)): - temp += 1 - if arr[i] != temp: - res = temp - break - -print(res)""" +n = int(input()) +arr = list(map(int,input().split())) + +sum = sum(arr) +exp = (n)*(n+1)/2 +print(int(exp-sum)) + + + +"""temp = 0 +arr = sorted(arr) +for i in range(len(arr)): + temp += 1 + if arr[i] != temp: + res = temp + break + +print(res)""" diff --git a/numberguesser.py b/Python/numberguesser.py similarity index 96% rename from numberguesser.py rename to Python/numberguesser.py index 2ab450f..3aa3f7a 100644 --- a/numberguesser.py +++ b/Python/numberguesser.py @@ -1,37 +1,37 @@ -#guessthenumber - -import random -print("Welcome to Guess the Number v1.2!") - -#Release notes 1.0: guess a number between 1 and 100 -#Release notes 1.1: Difficulty Level added, three levels of difficulty, -#1-5, 1-10, 1-100 -#Release notes 1.2: If invaild difficulty is an input, program will return -#"Sorry, please enter a vaild choice of difficulty." - - -input1 = input("Choose a difficulty: Easy, Medium, Hard.") - -if input1 == ("Easy"): - input2 = int(input("Enter a number between 1 and 5!")) - random_number = random.randint(1, 5) - if input2 != random_number: - print("Sorry, you're wrong.") - else: - print("Wow, you nailed it!") - -elif input1 == ("Medium"): - input3 = int(input("Enter a number between 1 and 10!")) - random_number2 = random.randint(1, 10) - if input3 != random_number2: - print("Sorry, you're wrong.") - else: - print("Wow, you nailed it!") - -elif input1 == ("Hard"): - input4 = int(input("Enter a number between 1 and 100!")) - random_number3 = random.randint(1, 100) - if input4 != random_number3: - print("Sorry, you're wrong.") -else: - print("Sorry, please enter a valid choice of difficulty.") +#guessthenumber + +import random +print("Welcome to Guess the Number v1.2!") + +#Release notes 1.0: guess a number between 1 and 100 +#Release notes 1.1: Difficulty Level added, three levels of difficulty, +#1-5, 1-10, 1-100 +#Release notes 1.2: If invaild difficulty is an input, program will return +#"Sorry, please enter a vaild choice of difficulty." + + +input1 = input("Choose a difficulty: Easy, Medium, Hard.") + +if input1 == ("Easy"): + input2 = int(input("Enter a number between 1 and 5!")) + random_number = random.randint(1, 5) + if input2 != random_number: + print("Sorry, you're wrong.") + else: + print("Wow, you nailed it!") + +elif input1 == ("Medium"): + input3 = int(input("Enter a number between 1 and 10!")) + random_number2 = random.randint(1, 10) + if input3 != random_number2: + print("Sorry, you're wrong.") + else: + print("Wow, you nailed it!") + +elif input1 == ("Hard"): + input4 = int(input("Enter a number between 1 and 100!")) + random_number3 = random.randint(1, 100) + if input4 != random_number3: + print("Sorry, you're wrong.") +else: + print("Sorry, please enter a valid choice of difficulty.") diff --git a/numpy_basic.py b/Python/numpy_basic.py similarity index 96% rename from numpy_basic.py rename to Python/numpy_basic.py index 6dab558..6ad3926 100644 --- a/numpy_basic.py +++ b/Python/numpy_basic.py @@ -1,41 +1,41 @@ -# ============= WHAT IS NUMPY ? ============= - -# NumPy is the fundamental package for scientific computing in Python. It is a Python library that provides -# a multidimensional array object, various derived objects (such as masked arrays and matrices), and an assortment -# of routines for fast operations on arrays, -# including mathematical, logical, shape manipulation, sorting, selecting, I/O, discrete Fourier transforms, -# basic linear algebra, basic statistical operations, -# random simulation and much more. - - - - -# ============= REQUIREMENT ============= -# pip install numpy - -# ============= IMPORT MODULE/PACKAGE ============= -import numpy as np - -# ============= MAKE ARRAY USING NUMPY ============= -array1 = np.array([1, 2, 3 ,4, 5]) -print("Result is :" , array1) - -# RESULT : - # Result is : [1 2 3 4 5] - -# ============= MAKE ARRAY WITH 0 VALUE ============= -array2 = np.zeros(5) # MAKE ARRAY 0 VALUE AS MUCH 5 -print("Result is :", array2) - -# RESULT : - # Result is : [0. 0. 0. 0. 0.] - -# ============= MAKE ARRAY WITH 1 VALUE ============= -array3 = np.ones(5) # MAKE ARRAY 1 VALUE AS MUCH 5 -print("Result is :", array3) - -# RESULT : - # Result is : [1. 1. 1. 1. 1.] - - +# ============= WHAT IS NUMPY ? ============= + +# NumPy is the fundamental package for scientific computing in Python. It is a Python library that provides +# a multidimensional array object, various derived objects (such as masked arrays and matrices), and an assortment +# of routines for fast operations on arrays, +# including mathematical, logical, shape manipulation, sorting, selecting, I/O, discrete Fourier transforms, +# basic linear algebra, basic statistical operations, +# random simulation and much more. + + + + +# ============= REQUIREMENT ============= +# pip install numpy + +# ============= IMPORT MODULE/PACKAGE ============= +import numpy as np + +# ============= MAKE ARRAY USING NUMPY ============= +array1 = np.array([1, 2, 3 ,4, 5]) +print("Result is :" , array1) + +# RESULT : + # Result is : [1 2 3 4 5] + +# ============= MAKE ARRAY WITH 0 VALUE ============= +array2 = np.zeros(5) # MAKE ARRAY 0 VALUE AS MUCH 5 +print("Result is :", array2) + +# RESULT : + # Result is : [0. 0. 0. 0. 0.] + +# ============= MAKE ARRAY WITH 1 VALUE ============= +array3 = np.ones(5) # MAKE ARRAY 1 VALUE AS MUCH 5 +print("Result is :", array3) + +# RESULT : + # Result is : [1. 1. 1. 1. 1.] + + # ==================== THANKS FOR YOUR ATTENTION, I HOPE YOU LIKE THIS ==================== \ No newline at end of file diff --git a/palindrome.py b/Python/palindrome.py similarity index 100% rename from palindrome.py rename to Python/palindrome.py diff --git a/permutermIndex.py b/Python/permutermIndex.py similarity index 100% rename from permutermIndex.py rename to Python/permutermIndex.py diff --git a/pong.py b/Python/pong.py similarity index 100% rename from pong.py rename to Python/pong.py diff --git a/prim.py b/Python/prim.py similarity index 100% rename from prim.py rename to Python/prim.py diff --git a/primefactor.py b/Python/primefactor.py similarity index 100% rename from primefactor.py rename to Python/primefactor.py diff --git a/quickselect_algo.py b/Python/quickselect_algo.py similarity index 100% rename from quickselect_algo.py rename to Python/quickselect_algo.py diff --git a/random_num_generator.py b/Python/random_num_generator.py similarity index 100% rename from random_num_generator.py rename to Python/random_num_generator.py diff --git a/readability.py b/Python/readability.py similarity index 100% rename from readability.py rename to Python/readability.py diff --git a/scicalculator.py b/Python/scicalculator.py similarity index 100% rename from scicalculator.py rename to Python/scicalculator.py diff --git a/scorenotifier.py b/Python/scorenotifier.py similarity index 97% rename from scorenotifier.py rename to Python/scorenotifier.py index 67d767d..193a51e 100644 --- a/scorenotifier.py +++ b/Python/scorenotifier.py @@ -1,82 +1,82 @@ -import requests -from bs4 import BeautifulSoup -from win10toast import ToastNotifier -import re -from time import sleep -import tkinter as tk -from tkinter import ttk -from tkinter import * -import tkinter.font as font -from PIL import ImageTk,Image - - -def art(): - print(""" -||| ||| \\\ /// ||||||||| ||||||||| ||||||||| ||||||||| |||||||| ||||||||| -||| ||| \\\ /// ||| ||| ||| ||| ||| ||| ||| ||| -||| ||| \\\ /// ||||| ||||||||| ||| ||| ||| |||||/// ||||| -||| ||| \\\ /// ||| ||| ||| ||| ||| ||| \\\ ||| -|||||||| ||| \\\/// ||||||||| ||||||||| ||||||||| ||||||||| ||| \\\ ||||||||| -""") - -def get_current_matches(): - page = requests.get('http://static.cricinfo.com/rss/livescores.xml') - soup = BeautifulSoup(page.text,'lxml') - matches = soup.find_all('description') - live_matches = [s.get_text() for s in matches if '*' in s.get_text()] - return live_matches - -def fetch_score(matchNum): - page = requests.get('http://static.cricinfo.com/rss/livescores.xml') - soup = BeautifulSoup(page.text,'lxml') - matches = soup.find_all('description') - live_matches = [s.get_text() for s in matches if '*' in s.get_text()] - return live_matches[matchNum] - - -def popupmsg(score,name): - popup = tk.Tk() - popup.geometry("1200x800") - myFont=font.Font(family='Helvetica', size=20, weight="bold") - popup.wm_title("LIVE CRICKET SCORE") - canvas = Canvas(popup,width=750,height=500) - canvas.pack() - img = ImageTk.PhotoImage(Image.open("ipl.jpg")) - canvas.create_image(50,50,anchor=NW, image=img) - label = ttk.Label(popup, text=score) - label.pack(side="top", fill="x", pady=20 , padx=80) - label.config(font=("Courier", 36, "bold")) - popup.configure(bg='gold') - B1 = Button(popup, text="Okay", command = popup.destroy, bg='red', fg='black') - B1['font']=myFont - B1.pack() - copyri8 = Label(popup,text='Ⓒ:G3', - bg='plum1',fg='red3',font=('arial',10,'bold')) - copyri8.pack(side=BOTTOM) - popup.mainloop() - - -if __name__ == "__main__": - name = input("Please Enter your Name:") - print("Hello",name,",Welcome to Live Cricket Score Notifier") - art() - matches = get_current_matches() - print('Current matches in play') - print('='*25) - for i,match in enumerate(matches): - print('[{}] '.format(i) + - re.search('\D+',match.split('v')[0]).group() + 'vs.' + - re.search('\D+',match.split('v')[1]).group() - ) - - print() - matchNum = int(input('Please select Match Number for Live Scores [0,1,2...] => ')) - print("Getting Scores.....") - print("Please check the popup window/icon in your Taskbar") - print("Popup will appear again and again after every 10 seconds") - - while True: - current_score = fetch_score(matchNum) - popupmsg(current_score, name) - sleep(10) +import requests +from bs4 import BeautifulSoup +from win10toast import ToastNotifier +import re +from time import sleep +import tkinter as tk +from tkinter import ttk +from tkinter import * +import tkinter.font as font +from PIL import ImageTk,Image + + +def art(): + print(""" +||| ||| \\\ /// ||||||||| ||||||||| ||||||||| ||||||||| |||||||| ||||||||| +||| ||| \\\ /// ||| ||| ||| ||| ||| ||| ||| ||| +||| ||| \\\ /// ||||| ||||||||| ||| ||| ||| |||||/// ||||| +||| ||| \\\ /// ||| ||| ||| ||| ||| ||| \\\ ||| +|||||||| ||| \\\/// ||||||||| ||||||||| ||||||||| ||||||||| ||| \\\ ||||||||| +""") + +def get_current_matches(): + page = requests.get('http://static.cricinfo.com/rss/livescores.xml') + soup = BeautifulSoup(page.text,'lxml') + matches = soup.find_all('description') + live_matches = [s.get_text() for s in matches if '*' in s.get_text()] + return live_matches + +def fetch_score(matchNum): + page = requests.get('http://static.cricinfo.com/rss/livescores.xml') + soup = BeautifulSoup(page.text,'lxml') + matches = soup.find_all('description') + live_matches = [s.get_text() for s in matches if '*' in s.get_text()] + return live_matches[matchNum] + + +def popupmsg(score,name): + popup = tk.Tk() + popup.geometry("1200x800") + myFont=font.Font(family='Helvetica', size=20, weight="bold") + popup.wm_title("LIVE CRICKET SCORE") + canvas = Canvas(popup,width=750,height=500) + canvas.pack() + img = ImageTk.PhotoImage(Image.open("ipl.jpg")) + canvas.create_image(50,50,anchor=NW, image=img) + label = ttk.Label(popup, text=score) + label.pack(side="top", fill="x", pady=20 , padx=80) + label.config(font=("Courier", 36, "bold")) + popup.configure(bg='gold') + B1 = Button(popup, text="Okay", command = popup.destroy, bg='red', fg='black') + B1['font']=myFont + B1.pack() + copyri8 = Label(popup,text='Ⓒ:G3', + bg='plum1',fg='red3',font=('arial',10,'bold')) + copyri8.pack(side=BOTTOM) + popup.mainloop() + + +if __name__ == "__main__": + name = input("Please Enter your Name:") + print("Hello",name,",Welcome to Live Cricket Score Notifier") + art() + matches = get_current_matches() + print('Current matches in play') + print('='*25) + for i,match in enumerate(matches): + print('[{}] '.format(i) + + re.search('\D+',match.split('v')[0]).group() + 'vs.' + + re.search('\D+',match.split('v')[1]).group() + ) + + print() + matchNum = int(input('Please select Match Number for Live Scores [0,1,2...] => ')) + print("Getting Scores.....") + print("Please check the popup window/icon in your Taskbar") + print("Popup will appear again and again after every 10 seconds") + + while True: + current_score = fetch_score(matchNum) + popupmsg(current_score, name) + sleep(10) \ No newline at end of file diff --git a/snake-game.py b/Python/snake-game.py similarity index 100% rename from snake-game.py rename to Python/snake-game.py diff --git a/snakeGame.py b/Python/snakeGame.py similarity index 100% rename from snakeGame.py rename to Python/snakeGame.py diff --git a/speech_to_text.py b/Python/speech_to_text.py similarity index 100% rename from speech_to_text.py rename to Python/speech_to_text.py diff --git a/sudoku.py b/Python/sudoku.py similarity index 100% rename from sudoku.py rename to Python/sudoku.py diff --git a/telegrambot.py b/Python/telegrambot.py similarity index 100% rename from telegrambot.py rename to Python/telegrambot.py diff --git a/tictactoe.py b/Python/tictactoe.py similarity index 100% rename from tictactoe.py rename to Python/tictactoe.py diff --git a/to_roman_numerals.py b/Python/to_roman_numerals.py similarity index 100% rename from to_roman_numerals.py rename to Python/to_roman_numerals.py diff --git a/url_shortner.py b/Python/url_shortner.py similarity index 100% rename from url_shortner.py rename to Python/url_shortner.py diff --git a/variableprogram.py b/Python/variableprogram.py similarity index 100% rename from variableprogram.py rename to Python/variableprogram.py diff --git a/linear-regression(grade prediction).R b/R/linear-regression(grade prediction).R similarity index 100% rename from linear-regression(grade prediction).R rename to R/linear-regression(grade prediction).R diff --git a/bubble.rs b/Rust/bubble.rs similarity index 96% rename from bubble.rs rename to Rust/bubble.rs index 7efcc76..70e9211 100644 --- a/bubble.rs +++ b/Rust/bubble.rs @@ -1,36 +1,36 @@ -// A Bubble Sort Algorithm in RustLang, this sorts both Numbers as well as Strings. -//@author : Srinjana - -fn bubble_sort(values: &mut[T]) { - let mut n = values.len(); - let mut swapped = true; - - while swapped { - swapped = false; - - for i in 1..n { - if values[i - 1] > values[i] { - values.swap(i - 1, i); - swapped = true; - } - } - - n = n - 1; - } -} - -fn main() { - // Sorting numbers. - let mut numbers = [8, 7, 1, 2, 9, 3, 4, 5, 0, 6]; - println!("Before: {:?}", numbers); - - bubble_sort(&mut numbers); - println!("After: {:?}", numbers); - - // Sorting strings. - let mut strings = ["elephant", "badger", "airplne", "cat", "doctor"]; - println!("Before: {:?}", strings); - - bubble_sort(&mut strings); - println!("After: {:?}", strings); +// A Bubble Sort Algorithm in RustLang, this sorts both Numbers as well as Strings. +//@author : Srinjana + +fn bubble_sort(values: &mut[T]) { + let mut n = values.len(); + let mut swapped = true; + + while swapped { + swapped = false; + + for i in 1..n { + if values[i - 1] > values[i] { + values.swap(i - 1, i); + swapped = true; + } + } + + n = n - 1; + } +} + +fn main() { + // Sorting numbers. + let mut numbers = [8, 7, 1, 2, 9, 3, 4, 5, 0, 6]; + println!("Before: {:?}", numbers); + + bubble_sort(&mut numbers); + println!("After: {:?}", numbers); + + // Sorting strings. + let mut strings = ["elephant", "badger", "airplne", "cat", "doctor"]; + println!("Before: {:?}", strings); + + bubble_sort(&mut strings); + println!("After: {:?}", strings); } \ No newline at end of file diff --git a/burrows_wheeler_transform.rs b/Rust/burrows_wheeler_transform.rs similarity index 100% rename from burrows_wheeler_transform.rs rename to Rust/burrows_wheeler_transform.rs diff --git a/_config.yml b/Yaml/_config.yml similarity index 100% rename from _config.yml rename to Yaml/_config.yml diff --git a/binarySearch.cpp b/binarySearch.cpp deleted file mode 100644 index 463a3d7..0000000 --- a/binarySearch.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include -using namespace std; - -int binarySearch(int arr[], int low, int high, int x) -{ - if (high >= low) { - int mid = (low + high) / 2; - if (arr[mid] == x) - return mid; - if (arr[mid] > x) - return binarySearch(arr, low, mid - 1, x); - return binarySearch(arr, mid + 1, high, x); - } - - return -1; -} - -int main() -{ - int arr[100],n,x; - cout<<"Enter no of elements in the array"<>n; - cout<<"Enter the elements of the array :"<>arr[i]; - } - cout<<"Enter the Number that you want to search : "<>x; - int res = binarySearch(arr, 0, n, x); - (res == -1) ? cout << "Number not present": cout << "Number present at index " << res; - return 0; -} diff --git a/hello.sh b/shell scripts/hello.sh similarity index 100% rename from hello.sh rename to shell scripts/hello.sh diff --git a/ping_host.sh b/shell scripts/ping_host.sh similarity index 100% rename from ping_host.sh rename to shell scripts/ping_host.sh