├── C-codes ├── Num Converters │ ├── Bin2oct │ │ └── bin2oct.c │ ├── Dec2bin │ │ └── dec2bi.c │ ├── Dex2hex │ │ └── dex2hex.c │ └── Hex2bin │ │ └── hex2bin.c ├── Readme.md ├── SchedulingAlgo │ ├── RoundRobin.c │ └── ShortestJobFirst.c ├── cyclically_rotate_an_array_by_one.c ├── gussthenum │ └── command.c ├── important program │ ├── armstrongNum.c │ ├── palindrome.c │ └── reverse number.c ├── merge2sortedArrays.c ├── mysql │ └── mysql.c ├── simple programs │ ├── Halfpyramid.c │ ├── factorial.c │ └── fibonacci.c ├── simpleinterest.c ├── sjf.c └── socket │ ├── client.c │ └── server.c ├── Contribute.md ├── Images ├── Coded_logo.png └── hacktoberfest.jpg ├── Java-codes ├── Area │ ├── Rectangle.java │ ├── Sphere.java │ ├── Square.java │ ├── circle.java │ └── triangle.java ├── Bottom_view_of_binary_tree.java ├── LongestPalindromicSubstring.java ├── MedianofTwoSortedArrays.java ├── PalindromeNumber.java ├── Readme.md ├── RegularExpressionMatching.java ├── ReverseInteger.java ├── Sorting │ ├── bubblesort.java │ ├── heapsort.java │ ├── quicksort.java │ └── selectionsort.java ├── Stack_implementation_in.java ├── StringtoInteger(atoi).java ├── ZigzagConversion.java ├── dijkastra.java ├── huffman_Coding.java ├── impotant Programs │ ├── BFS.java │ ├── Binary_search_tree_in_java.java │ ├── Concatenate.java │ ├── FactorialofNum.java │ ├── Fibonacci.java │ ├── Top_view_of_binary_tree.java │ ├── calculator.java │ ├── checkPalindrome.java │ ├── checkevenodd.java │ ├── kadane’sAlgo.java │ ├── prime-number.java │ ├── rat_in_maze.java │ └── swapping.java ├── kadanes_algorithm.java ├── matrixadd.java ├── reverse_the_array.java └── timer.java ├── README.md ├── React └── portfolio │ └── package.json ├── VisualBasic ├── Readme.md └── Simpleprograms │ ├── Areaofparallelogram.vb │ ├── Mathematicalcalculations.vb │ └── typeconverison.vb ├── Web ├── Google │ └── index1.html ├── Readme.md ├── THEME │ ├── index.html │ ├── index.js │ └── style.css ├── calculator │ ├── index.html │ ├── script.js │ └── style.css ├── loading.css ├── loading.html ├── loginpage │ ├── 4.jpg │ ├── loginpage.css │ └── loginpage.html ├── skc group │ ├── index.html │ └── style.css └── style1.css ├── c++ └── important programs │ ├── Hosoya traingle │ ├── Krukshal c++ │ ├── MyC++programs │ ├── Reverseanumber.cpp │ ├── armstrong.cpp │ ├── factorialofnumber.cpp │ └── palindrome or not.cpp │ ├── Painting_fence_algorithm.cpp │ ├── bubble sort │ ├── dijkastra.cpp │ ├── evenodd.cpp │ ├── fcfs.cpp │ ├── quicksort.cpp │ ├── reverse.cpp │ ├── sudoko │ ├── unbounded_kanpsack.cpp │ └── usefulprograms │ ├── GCD.cpp │ ├── LCM.cpp │ ├── greatestnumberinarray.cpp │ ├── matrixaddition.cpp │ └── towerofhanoi.cpp └── python ├── CardGame.py ├── bubble_sort.py ├── circular_queue.py ├── lcs.py └── merge_sort.py /C-codes/Num Converters/Bin2oct/bin2oct.c: -------------------------------------------------------------------------------- 1 | // Convert a binary number to octal number 2 | #include 3 | 4 | int main() 5 | { 6 | int binaryNumber = 0; 7 | int octalNumber = 0; 8 | int i = 1; 9 | int rem = 0; 10 | 11 | printf("Enter binary number: "); 12 | scanf("%d", &binaryNumber); 13 | 14 | while (binaryNumber != 0) { 15 | rem = binaryNumber % 10; 16 | octalNumber = octalNumber + rem * i; 17 | 18 | i = i * 2; 19 | binaryNumber = binaryNumber / 10; 20 | } 21 | 22 | printf("Octal Number: %o", octalNumber); 23 | return 0; 24 | } -------------------------------------------------------------------------------- /C-codes/Num Converters/Dec2bin/dec2bi.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | void insert_binary(char *str,char d){ 7 | int len = strlen(str); 8 | static pos = 0; 9 | if(pos == 4){ 10 | memmove(&str[1],str,len+1); 11 | str[0] = ' '; 12 | pos = 0; 13 | } 14 | 15 | memmove(&str[1],str,len+1); 16 | str[0] = d; 17 | pos++; 18 | } 19 | int main(int argc,char *agrv[]){ 20 | int i; 21 | char binary[1024]; 22 | int n,r; 23 | 24 | if(argc<2){ 25 | fprintf(stderr,"usages:%s number\n",agrv[0]); 26 | exit(0); 27 | } 28 | memset(binary,0,sizeof(binary)); 29 | i = atoi(agrv[1]); 30 | do{ 31 | r = i%2; 32 | n = i/2; 33 | /*insert degiit reminder to the leftmost*/ 34 | insert_binary(binary,r?'1':'0'); 35 | i = n; 36 | }while(i); 37 | printf("binayr : %s\n",binary); 38 | 39 | return 0; 40 | } -------------------------------------------------------------------------------- /C-codes/Num Converters/Dex2hex/dex2hex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc,char *argv[]){ 6 | char h[17]="0123456789ABCDEF"; 7 | int num; 8 | char hex[1024]; 9 | int quo; 10 | int rem; 11 | int i; 12 | 13 | if (argc !=2){ 14 | fprintf(stderr,"Usage: %s decimal_number\n",argv[0]); 15 | exit(1); 16 | } 17 | num = atoi(argv[1]); 18 | hex[0] = '\0'; 19 | 20 | while(num != 0){ 21 | quo = num / 16; 22 | rem = num % 16; 23 | memmove(&hex[1],hex,strlen(hex)+1); 24 | hex[0] = h[rem]; 25 | num = quo; 26 | } 27 | printf("%d= 0x%s\n\n",atoi(argv[1]),hex); 28 | return 0; 29 | } -------------------------------------------------------------------------------- /C-codes/Num Converters/Hex2bin/hex2bin.c: -------------------------------------------------------------------------------- 1 | // Convert a hexadecimal number to binary number 2 | #include 3 | 4 | int main() 5 | { 6 | char HexNum[32] = { 0 }; 7 | int i = 0; 8 | 9 | printf("Enter the Hexadecimal number: "); 10 | scanf("%s", HexNum); 11 | 12 | printf("Binary Number: "); 13 | 14 | while (HexNum[i]) { 15 | switch (HexNum[i]) { 16 | case '0': 17 | printf("0000"); 18 | break; 19 | 20 | case '1': 21 | printf("0001"); 22 | break; 23 | 24 | case '2': 25 | printf("0010"); 26 | break; 27 | 28 | case '3': 29 | printf("0011"); 30 | break; 31 | 32 | case '4': 33 | printf("0100"); 34 | break; 35 | 36 | case '5': 37 | printf("0101"); 38 | break; 39 | 40 | case '6': 41 | printf("0110"); 42 | break; 43 | 44 | case '7': 45 | printf("0111"); 46 | break; 47 | 48 | case '8': 49 | printf("1000"); 50 | break; 51 | 52 | case '9': 53 | printf("1001"); 54 | break; 55 | 56 | case 'a': 57 | case 'A': 58 | printf("1010"); 59 | break; 60 | 61 | case 'b': 62 | case 'B': 63 | printf("1011"); 64 | break; 65 | 66 | case 'c': 67 | case 'C': 68 | printf("1100"); 69 | break; 70 | 71 | case 'd': 72 | case 'D': 73 | printf("1101"); 74 | break; 75 | 76 | case 'e': 77 | case 'E': 78 | printf("1110"); 79 | break; 80 | 81 | case 'f': 82 | case 'F': 83 | printf("1111"); 84 | break; 85 | 86 | default: 87 | printf("\nInvalid hexa digit: %c", HexNum[i]); 88 | return 0; 89 | } 90 | i++; 91 | } 92 | return 0; 93 | } -------------------------------------------------------------------------------- /C-codes/Readme.md: -------------------------------------------------------------------------------- 1 | Here are c codes written for windows and linux systems. 2 | -------------------------------------------------------------------------------- /C-codes/SchedulingAlgo/RoundRobin.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int i, limit, total = 0, x, counter = 0, time_quantum; 5 | int WT = 0, tat = 0, AT[10], BT[10], temp[10]; 6 | float average_WT, average_tat; 7 | printf("\nEnter Total Number of Processes: "); 8 | scanf("%d", &limit); 9 | x = limit; 10 | for(i = 0; i < limit; i++) 11 | { 12 | printf("Enter Details of Process[%d]\n", i + 1); 13 | printf("Arrival Time:"); 14 | scanf("%d", &AT[i]); 15 | printf("Burst Time:"); 16 | scanf("%d", &BT[i]); 17 | temp[i] = BT[i]; 18 | } 19 | 20 | printf("\nEnter Time Quantum:\t"); 21 | scanf("%d", &time_quantum); 22 | printf("\nProcess\tBT\tTAT\tWT"); 23 | for(total = 0, i = 0; x != 0;) 24 | { 25 | if(temp[i] <= time_quantum && temp[i] > 0) 26 | { 27 | total = total + temp[i]; 28 | temp[i] = 0; 29 | counter = 1; 30 | } 31 | else if(temp[i] > 0) 32 | { 33 | temp[i] = temp[i] - time_quantum; 34 | total = total + time_quantum; 35 | } 36 | if(temp[i] == 0 && counter == 1) 37 | { 38 | x--; 39 | printf("\nP[%d]\t%d\t%d\t%d", i + 1, BT[i], total - AT[i], total - AT[i] - BT[i]); 40 | WT = WT + total - AT[i] - BT[i]; 41 | tat = tat + total - AT[i]; 42 | counter = 0; 43 | } 44 | if(i == limit - 1) 45 | { 46 | i = 0; 47 | } 48 | else if(AT[i + 1] <= total) 49 | { 50 | i++; 51 | } 52 | else 53 | { 54 | i = 0; 55 | } 56 | } 57 | 58 | average_WT = WT * 1.0 / limit; 59 | average_tat = tat * 1.0 / limit; 60 | printf("\nAverage Waiting Time:\t%f", average_WT); 61 | printf("\nAvg Turnaround Time:\t%f", average_tat); 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /C-codes/SchedulingAlgo/ShortestJobFirst.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int bt[20],p[20],wt[20],tat[20],i,j,n,total=0,pos,temp; 5 | float avg_wt,avg_tat; 6 | printf("Enter number of process:"); 7 | scanf("%d",&n); 8 | 9 | printf("\nEnter Burst Time:\n"); 10 | for(i=0;i 2 | 3 | 4 | 5 | void rotate(int arr[], int n) 6 | 7 | { 8 | 9 | int x = arr[n-1], i; 10 | 11 | for (i = n-1; i > 0; i--) 12 | 13 | arr[i] = arr[i-1]; 14 | 15 | arr[0] = x; 16 | 17 | } 18 | 19 | 20 | 21 | int main() 22 | 23 | { 24 | 25 | int arr[] = {1, 2, 3, 4, 5}, i; 26 | 27 | int n = sizeof(arr)/sizeof(arr[0]); 28 | 29 | 30 | 31 | printf("Given array is\n"); 32 | 33 | for (i = 0; i < n; i++) 34 | 35 | printf("%d ", arr[i]); 36 | 37 | 38 | 39 | rotate(arr, n); 40 | 41 | 42 | 43 | printf("\nRotated array is\n"); 44 | 45 | for (i = 0; i < n; i++) 46 | 47 | printf("%d ", arr[i]); 48 | 49 | 50 | 51 | return 0; 52 | 53 | } 54 | -------------------------------------------------------------------------------- /C-codes/gussthenum/command.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | randnum(int maxval) 6 | { 7 | /* pick a random number from 1 to maxval */ 8 | 9 | int randval; 10 | 11 | getrandom(&randval, sizeof(int), GRND_NONBLOCK); 12 | 13 | /* could be negative, so ensure it's positive */ 14 | 15 | if (randval < 0) { 16 | return (-1 * randval % maxval + 1); 17 | } 18 | else { 19 | return (randval % maxval + 1); 20 | } 21 | } 22 | 23 | int 24 | main(void) 25 | { 26 | int number; 27 | int guess; 28 | 29 | number = randnum(100); 30 | 31 | puts("Guess a number between 1 and 100"); 32 | 33 | do { 34 | scanf("%d", &guess); 35 | 36 | if (guess < number) { 37 | puts("Too low"); 38 | } 39 | else if (guess > number) { 40 | puts("Too high"); 41 | } 42 | } while (guess != number); 43 | 44 | puts("That's right!"); 45 | 46 | return 0; 47 | } -------------------------------------------------------------------------------- /C-codes/important program/armstrongNum.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int num, originalNum, remainder, result = 0; 4 | printf("Enter a three-digit integer: "); 5 | scanf("%d", &num); 6 | originalNum = num; 7 | 8 | while (originalNum != 0) { 9 | // remainder contains the last digit 10 | remainder = originalNum % 10; 11 | 12 | result += remainder * remainder * remainder; 13 | 14 | // removing last digit from the orignal number 15 | originalNum /= 10; 16 | } 17 | 18 | if (result == num) 19 | printf("%d is an Armstrong number.", num); 20 | else 21 | printf("%d is not an Armstrong number.", num); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /C-codes/important program/palindrome.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int n, reversed = 0, remainder, original; 4 | printf("Enter an integer: "); 5 | scanf("%d", &n); 6 | original = n; 7 | 8 | // reversed integer is stored in reversed variable 9 | while (n != 0) { 10 | remainder = n % 10; 11 | reversed = reversed * 10 + remainder; 12 | n /= 10; 13 | } 14 | 15 | // palindrome if orignal and reversed are equal 16 | if (original == reversed) 17 | printf("%d is a palindrome.", original); 18 | else 19 | printf("%d is not a palindrome.", original); 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /C-codes/important program/reverse number.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | 5 | int n, reverse = 0, remainder; 6 | 7 | printf("Enter an integer: "); 8 | scanf("%d", &n); 9 | 10 | while (n != 0) { 11 | remainder = n % 10; 12 | reverse = reverse * 10 + remainder; 13 | n /= 10; 14 | } 15 | 16 | printf("Reversed number = %d", reverse); 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /C-codes/merge2sortedArrays.c: -------------------------------------------------------------------------------- 1 | // C program to merge two sorted arrays with O(1) extra 2 | // space. 3 | #include 4 | 5 | // Merge ar1[] and ar2[] with O(1) extra space 6 | 7 | void merge(int ar1[], int ar2[], int m, int n) 8 | { 9 | 10 | // Iterate through all elements 11 | 12 | // of ar2[] starting from the last element 13 | 14 | for (int i = n - 1; i >= 0; i--) { 15 | 16 | // Find the smallest element greater than ar2[i]. 17 | 18 | // Move all elements one position ahead till the 19 | 20 | // smallest greater element is not found */ 21 | 22 | int j, last = ar1[m - 1]; 23 | 24 | for (j = m - 2; j >= 0 && ar1[j] > ar2[i]; j--) 25 | 26 | ar1[j + 1] = ar1[j]; 27 | 28 | 29 | // If there was a greater element 30 | 31 | if (last > ar2[i]) { 32 | 33 | ar1[j + 1] = ar2[i]; 34 | 35 | ar2[i] = last; 36 | 37 | } 38 | 39 | } 40 | } 41 | 42 | // Driver program 43 | 44 | int main() 45 | { 46 | 47 | int ar1[] = { 1, 5, 9, 10, 15, 20 }; 48 | 49 | int ar2[] = { 2, 3, 8, 13 }; 50 | 51 | int m = sizeof(ar1) / sizeof(ar1[0]); 52 | 53 | int n = sizeof(ar2) / sizeof(ar2[0]); 54 | 55 | merge(ar1, ar2, m, n); 56 | 57 | 58 | printf("After Merging \nFirst Array: "); 59 | 60 | for (int i = 0; i < m; i++) 61 | 62 | printf("%d ", ar1[i]); 63 | 64 | printf("\nSecond Array: "); 65 | 66 | for (int i = 0; i < n; i++) 67 | 68 | printf("%d ", ar2[i]); 69 | 70 | return 0; 71 | } 72 | 73 | // This code is contributed by Ramanujam 74 | -------------------------------------------------------------------------------- /C-codes/mysql/mysql.c: -------------------------------------------------------------------------------- 1 | /* Simple C program that connects to MySQL Database server*/ 2 | #include 3 | #include 4 | 5 | main() { 6 | MYSQL *conn; 7 | MYSQL_RES *res; 8 | MYSQL_ROW row; 9 | 10 | char *server = "localhost"; 11 | char *user = "root"; 12 | char *password = "PASSWORD"; /* set me first */ 13 | char *database = "mysql"; 14 | 15 | conn = mysql_init(NULL); 16 | 17 | /* Connect to database */ 18 | if (!mysql_real_connect(conn, server, 19 | user, password, database, 0, NULL, 0)) { 20 | fprintf(stderr, "%s\n", mysql_error(conn)); 21 | exit(1); 22 | } 23 | 24 | /* send SQL query */ 25 | if (mysql_query(conn, "show tables")) { 26 | fprintf(stderr, "%s\n", mysql_error(conn)); 27 | exit(1); 28 | } 29 | 30 | res = mysql_use_result(conn); 31 | 32 | /* output table name */ 33 | printf("MySQL Tables in mysql database:\n"); 34 | while ((row = mysql_fetch_row(res)) != NULL) 35 | printf("%s \n", row[0]); 36 | 37 | /* close connection */ 38 | mysql_free_result(res); 39 | mysql_close(conn); 40 | } -------------------------------------------------------------------------------- /C-codes/simple programs/Halfpyramid.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int i, j, rows; 4 | printf("Enter the number of rows: "); 5 | scanf("%d", &rows); 6 | for (i = 1; i <= rows; ++i) { 7 | for (j = 1; j <= i; ++j) { 8 | printf("* "); 9 | } 10 | printf("\n"); 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /C-codes/simple programs/factorial.c: -------------------------------------------------------------------------------- 1 | #include 2 | long int multiplyNumbers(int n); 3 | int main() { 4 | int n; 5 | printf("Enter a positive integer: "); 6 | scanf("%d",&n); 7 | printf("Factorial of %d = %ld", n, multiplyNumbers(n)); 8 | return 0; 9 | } 10 | 11 | long int multiplyNumbers(int n) { 12 | if (n>=1) 13 | return n*multiplyNumbers(n-1); 14 | else 15 | return 1; 16 | } 17 | -------------------------------------------------------------------------------- /C-codes/simple programs/fibonacci.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | 4 | int i, n; 5 | 6 | // initialize first and second terms 7 | int t1 = 0, t2 = 1; 8 | 9 | // initialize the next term (3rd term) 10 | int nextTerm = t1 + t2; 11 | 12 | // get no. of terms from user 13 | printf("Enter the number of terms: "); 14 | scanf("%d", &n); 15 | 16 | // print the first two terms t1 and t2 17 | printf("Fibonacci Series: %d, %d, ", t1, t2); 18 | 19 | // print 3rd to nth terms 20 | for (i = 3; i <= n; ++i) { 21 | printf("%d, ", nextTerm); 22 | t1 = t2; 23 | t2 = nextTerm; 24 | nextTerm = t1 + t2; 25 | } 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /C-codes/simpleinterest.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | float principle, time, rate, SI; 6 | 7 | /* Input principle, rate and time */ 8 | printf("Enter principle (amount): "); 9 | scanf("%f", &principle); 10 | 11 | printf("Enter time: "); 12 | scanf("%f", &time); 13 | 14 | printf("Enter rate: "); 15 | scanf("%f", &rate); 16 | 17 | /* Calculate simple interest */ 18 | SI = (principle * time * rate) / 100; 19 | 20 | /* Print the resultant value of SI */ 21 | printf("Simple Interest = %f", SI); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /C-codes/sjf.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int A[100][4]; 5 | int i, j, n, total = 0, index, temp; 6 | float avg_wt, avg_tat; 7 | printf("Enter number of process: "); 8 | scanf("%d", &n); 9 | printf("Enter Burst Time:\n"); 10 | for (i = 0; i < n; i++) { 11 | printf("P%d: ", i + 1); 12 | scanf("%d", &A[i][1]); 13 | A[i][0] = i + 1; 14 | } 15 | for (i = 0; i < n; i++) { 16 | index = i; 17 | for (j = i + 1; j < n; j++) 18 | if (A[j][1] < A[index][1]) 19 | index = j; 20 | temp = A[i][1]; 21 | A[i][1] = A[index][1]; 22 | A[index][1] = temp; 23 | 24 | temp = A[i][0]; 25 | A[i][0] = A[index][0]; 26 | A[index][0] = temp; 27 | } 28 | A[0][2] = 0; 29 | for (i = 1; i < n; i++) { 30 | A[i][2] = 0; 31 | for (j = 0; j < i; j++) 32 | A[i][2] += A[j][1]; 33 | total += A[i][2]; 34 | } 35 | avg_wt = (float)total / n; 36 | total = 0; 37 | printf("P BT WT TAT\n"); 38 | for (i = 0; i < n; i++) { 39 | A[i][3] = A[i][1] + A[i][2]; 40 | total += A[i][3]; 41 | printf("P%d %d %d %d\n", A[i][0], 42 | A[i][1], A[i][2], A[i][3]); 43 | } 44 | avg_tat = (float)total / n; 45 | printf("Average Waiting Time= %f", avg_wt); 46 | printf("\nAverage Turnaround Time= %f", avg_tat); 47 | } 48 | -------------------------------------------------------------------------------- /C-codes/socket/client.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #define NEXT "Hello World of sockets" 11 | 12 | int main(int argc, char *argv[]){ 13 | int sock; 14 | struct sockaddr_in server; 15 | struct hostent *hp; 16 | char buffer[1024]; 17 | 18 | sock = socket(AF_INET, SOCK_STREAM,0); 19 | if(sock < 0){ 20 | perror("socket creation failed\n"); 21 | exit(1); 22 | } 23 | server.sin_family = AF_INET; 24 | hp = gethostbyname (argv[1]); 25 | if(hp == 0){ 26 | perror("hostname not found\n"); 27 | close(sock); 28 | exit(1); 29 | } 30 | memcpy(&server.sin_addr, hp->h_addr, hp->h_length); 31 | server.sin_port = htons(5000); 32 | 33 | if(connect(sock, (struct sockaddr *)&server, sizeof(server)) < 0){ 34 | perror("connect failed\n"); 35 | exit(1); 36 | } 37 | if(send(sock, NEXT, sizeof(NEXT), 0) < 0){ 38 | perror("send failed\n"); 39 | close(sock); 40 | exit(1); 41 | } 42 | printf("sent %s\n",NEXT); 43 | close(sock); 44 | return 0; 45 | 46 | } 47 | -------------------------------------------------------------------------------- /C-codes/socket/server.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int agrc,char *argv[]){ 9 | 10 | /*variables*/ 11 | int sock; 12 | struct sockaddr_in server; 13 | int mysock; 14 | char buffer[1024]; 15 | int rval; 16 | /*Create shocket*/ 17 | /*tcp--ip*/ 18 | sock = socket(AF_INET, SOCK_STREAM,0); 19 | if(sock == 0){ 20 | printf("socket creation failed\n"); 21 | exit(1); 22 | } 23 | server.sin_family = AF_INET; 24 | server.sin_addr.s_addr = INADDR_ANY; 25 | server.sin_port = htons(5000); 26 | 27 | /*call bind*/ 28 | if(bind(sock, (struct sockaddr *)&server, sizeof(server))<0){ 29 | perror("bind failed\n"); 30 | exit(1); 31 | } 32 | 33 | /*listen*/ 34 | listen(sock, 5); 35 | // 36 | //printf("listening\n"); 37 | // } 38 | 39 | /*accept*/ 40 | /*Only only connectection doesnt need to optimized or creating 41 | another process for handeling is not required*/ 42 | do{ 43 | mysock = accept(sock, (struct sockaddr *) 0, 0); 44 | if(mysock == -1 ){ 45 | perror("accept failed\n"); 46 | } 47 | else{ 48 | memset(buffer, 0, sizeof(buffer)); 49 | 50 | if((rval=recv(mysock,buffer,sizeof(buffer),0))<0) 51 | perror("Reading steam message error"); 52 | else if(rval == 0) 53 | printf("Client disconnected\n"); 54 | 55 | else 56 | printf("Message received: %s\n",buffer); 57 | printf("Got the message(rval = %d) \n",rval); 58 | close(mysock); 59 | 60 | } 61 | } while(1); 62 | 63 | 64 | return 0; 65 | } -------------------------------------------------------------------------------- /Contribute.md: -------------------------------------------------------------------------------- 1 | 2 | 3 |

HacktoberFest 2022 :fire:

4 | 5 |

6 | 7 | 8 |

9 | 10 | 11 | >-The power of open source is power of people,the people rule.(Philippe) 12 | #### [hacktoberfest 2022](https://hacktoberfest.com/) 13 | 14 | 15 | ### Let's Contribute :+1: 16 | - **Step 1** - Fork this repository. 17 | - **Step 2** - Clone the repository to your local machine. 18 | - **Step 3** - Resolve the bugs, mentions provided in the Issues section of the repository. *Also add a description of what changes you have done*. 19 | - **Step 4** - Add the changes to your repository. 20 | - **Step 5** - Create a PULL Request. And that's all. 21 | - **NOTE** - Please start the filename with the platform name on which the problem was solved. 22 | ### What you can contribute in this repo? :punch: 23 | - You can add your own competitive programming solutions or coding related solution. 24 | - There are various topics like Recursion , Bits Manipulation, Graphs etc. ***You can contribute in them*** 25 | - You can contribute some **Learning Resources** in the ***Readme.md*** File. 26 | - You can modify previous solutions if you feel like your solution has better ***Time or Space complexity.*** 27 | 28 | 29 | ##### Let's Contribute :smiley: 30 | -------------------------------------------------------------------------------- /Images/Coded_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codednepal/hacktober2022/8f64ced0fb555d6e1456228c0b73dd55068d67c7/Images/Coded_logo.png -------------------------------------------------------------------------------- /Images/hacktoberfest.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codednepal/hacktober2022/8f64ced0fb555d6e1456228c0b73dd55068d67c7/Images/hacktoberfest.jpg -------------------------------------------------------------------------------- /Java-codes/Area/Rectangle.java: -------------------------------------------------------------------------------- 1 | // a program to calculate area of Rectangle in Java 2 | import java.util.Scanner; 3 | class AreaOfRectangle 4 | { 5 | public static void main(String[] args) { 6 | Scanner s= new Scanner(System.in); 7 | System.out.println("Enter the length of the Triangle:"); 8 | Double l= s.nextDouble(); 9 | 10 | System.out.println("Enter the breadth of the Triangle:"); 11 | Double b= s.nextDouble(); 12 | 13 | //Area = ( length * breadth ) 14 | double area=(l*b); 15 | System.out.println("Area of Rectangle is: " + area); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Java-codes/Area/Sphere.java: -------------------------------------------------------------------------------- 1 | // Java program to calculate area of a Sphere in java 2 | 3 | import java.util.Scanner; 4 | public class AreaOfSphere { 5 | 6 | public static void main(String[] args) { 7 | System.out.println("Enter radius of circle: "); 8 | Scanner sn = new Scanner(System.in); 9 | Double radius = sn.nextDouble(); 10 | 11 | //area of sphere = 4*pi*r*r 12 | Double area = 4*Math.PI * radius * radius; 13 | System.out.println("Area of sphere = "+area); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Java-codes/Area/Square.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | public class AreaOfSquare { 4 | 5 | public static void main(String[] args) { 6 | System.out.println("Enter side: "); 7 | Scanner sn = new Scanner(System.in); 8 | Double side = sn.nextDouble(); 9 | //area of square= side*side 10 | Double area = side*side; 11 | System.out.println("Area of square = "+area); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Java-codes/Area/circle.java: -------------------------------------------------------------------------------- 1 | // Java program to calculate area of a circle in java 2 | import java.util.Scanner; 3 | public class AreaOfCircle { 4 | public static void main(String[] args) { 5 | System.out.println("Enter radius of circle: "); 6 | Scanner sn = new Scanner(System.in); 7 | Double radius = sn.nextDouble(); 8 | //area of circle = pi*r*r 9 | Double area = Math.PI * radius * radius; 10 | System.out.println("Area of circle = "+area); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Java-codes/Area/triangle.java: -------------------------------------------------------------------------------- 1 | 2 | // a program to calculate area of triangle in Java 3 | import java.util.Scanner; 4 | class AreaOfTriangle 5 | { 6 | public static void main(String[] args) { 7 | Scanner s= new Scanner(System.in); 8 | System.out.println("Enter the breadth of the Triangle:"); 9 | Double b= s.nextDouble(); 10 | 11 | System.out.println("Enter the height of the Triangle:"); 12 | Double h= s.nextDouble(); 13 | 14 | //Area = ( breadth * height )/2 15 | double area=(b*h)/2; 16 | System.out.println("Area of Triangle is: " + area); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Java-codes/Bottom_view_of_binary_tree.java: -------------------------------------------------------------------------------- 1 | // Java Program to print Bottom View of Binary Tree 2 | import java.util.*; 3 | import java.util.Map.Entry; 4 | 5 | // Tree node class 6 | class Node 7 | { 8 | int data; //data of the node 9 | int hd; //horizontal distance of the node 10 | Node left, right; //left and right references 11 | 12 | // Constructor of tree node 13 | public Node(int key) 14 | { 15 | data = key; 16 | hd = Integer.MAX_VALUE; 17 | left = right = null; 18 | } 19 | } 20 | 21 | //Tree class 22 | class Tree 23 | { 24 | Node root; //root node of tree 25 | 26 | // Default constructor 27 | public Tree() {} 28 | 29 | // Parameterized tree constructor 30 | public Tree(Node node) 31 | { 32 | root = node; 33 | } 34 | 35 | // Method that prints the bottom view. 36 | public void bottomView() 37 | { 38 | if (root == null) 39 | return; 40 | 41 | // Initialize a variable 'hd' with 0 for the root element. 42 | int hd = 0; 43 | 44 | // TreeMap which stores key value pair sorted on key value 45 | Map map = new TreeMap<>(); 46 | 47 | // Queue to store tree nodes in level order traversal 48 | Queue queue = new LinkedList(); 49 | 50 | // Assign initialized horizontal distance value to root 51 | // node and add it to the queue. 52 | root.hd = hd; 53 | queue.add(root); 54 | 55 | // Loop until the queue is empty (standard level order loop) 56 | while (!queue.isEmpty()) 57 | { 58 | Node temp = queue.remove(); 59 | 60 | // Extract the horizontal distance value from the 61 | // dequeued tree node. 62 | hd = temp.hd; 63 | 64 | // Put the dequeued tree node to TreeMap having key 65 | // as horizontal distance. Every time we find a node 66 | // having same horizontal distance we need to replace 67 | // the data in the map. 68 | map.put(hd, temp.data); 69 | 70 | // If the dequeued node has a left child add it to the 71 | // queue with a horizontal distance hd-1. 72 | if (temp.left != null) 73 | { 74 | temp.left.hd = hd-1; 75 | queue.add(temp.left); 76 | } 77 | // If the dequeued node has a right child add it to the 78 | // queue with a horizontal distance hd+1. 79 | if (temp.right != null) 80 | { 81 | temp.right.hd = hd+1; 82 | queue.add(temp.right); 83 | } 84 | } 85 | 86 | // Extract the entries of map into a set to traverse 87 | // an iterator over that. 88 | Set> set = map.entrySet(); 89 | 90 | // Make an iterator 91 | Iterator> iterator = set.iterator(); 92 | 93 | // Traverse the map elements using the iterator. 94 | while (iterator.hasNext()) 95 | { 96 | Map.Entry me = iterator.next(); 97 | System.out.print(me.getValue()+" "); 98 | } 99 | } 100 | } 101 | 102 | // Main driver class 103 | public class BottomView 104 | { 105 | public static void main(String[] args) 106 | { 107 | Node root = new Node(20); 108 | root.left = new Node(8); 109 | root.right = new Node(22); 110 | root.left.left = new Node(5); 111 | root.left.right = new Node(3); 112 | root.right.left = new Node(4); 113 | root.right.right = new Node(25); 114 | root.left.right.left = new Node(10); 115 | root.left.right.right = new Node(14); 116 | Tree tree = new Tree(root); 117 | System.out.println("Bottom view of the given binary tree:"); 118 | tree.bottomView(); 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /Java-codes/LongestPalindromicSubstring.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String longestPalindrome(String s) { 3 | if (s == null || s.length() < 1) return ""; 4 | int start = 0, end = 0; 5 | for (int i = 0; i < s.length(); i++) { 6 | int len1 = expandAroundCenter(s, i, i); 7 | int len2 = expandAroundCenter(s, i, i + 1); 8 | int len = Math.max(len1, len2); 9 | if (len > end - start) { 10 | start = i - (len - 1) / 2; 11 | end = i + len / 2; 12 | } 13 | } 14 | return s.substring(start, end + 1); 15 | } 16 | 17 | private int expandAroundCenter(String s, int left, int right) { 18 | int L = left, R = right; 19 | while (L >= 0 && R < s.length() && s.charAt(L) == s.charAt(R)) { 20 | L--; 21 | R++; 22 | } 23 | return R - L - 1; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Java-codes/MedianofTwoSortedArrays.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public double findMedianSortedArrays(int[] nums1, int[] nums2) { 3 | int index1 = 0; 4 | int index2 = 0; 5 | int med1 = 0; 6 | int med2 = 0; 7 | for (int i=0; i<=(nums1.length+nums2.length)/2; i++) { 8 | med1 = med2; 9 | 10 | if (index1 == nums1.length) 11 | { 12 | med2 = nums2[index2]; 13 | index2++; 14 | } 15 | else if (index2 == nums2.length) { 16 | med2 = nums1[index1]; 17 | index1++; 18 | } 19 | else if (nums1[index1] < nums2[index2] ) { 20 | med2 = nums1[index1]; 21 | index1++; 22 | } 23 | else { 24 | med2 = nums2[index2]; 25 | index2++; 26 | } 27 | } 28 | 29 | if ((nums1.length+nums2.length)%2 == 0){ 30 | return (float)(med1+med2)/2; 31 | } 32 | return med2; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Java-codes/PalindromeNumber.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean isPalindrome(int x) { 3 | int i = x; 4 | int num = 0; 5 | while(i>=1) { 6 | int rem = i%10; 7 | num = num*10+rem; 8 | i=i/10; 9 | } 10 | return num==x; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Java-codes/Readme.md: -------------------------------------------------------------------------------- 1 | upload Your Java codes here 2 | -------------------------------------------------------------------------------- /Java-codes/RegularExpressionMatching.java: -------------------------------------------------------------------------------- 1 | enum Result { 2 | TRUE, FALSE 3 | } 4 | 5 | class Solution { 6 | Result[][] memo; 7 | 8 | public boolean isMatch(String text, String pattern) { 9 | memo = new Result[text.length() + 1][pattern.length() + 1]; 10 | return dp(0, 0, text, pattern); 11 | } 12 | 13 | public boolean dp(int i, int j, String text, String pattern) { 14 | if (memo[i][j] != null) { 15 | return memo[i][j] == Result.TRUE; 16 | } 17 | boolean ans; 18 | if (j == pattern.length()){ 19 | ans = i == text.length(); 20 | } else{ 21 | boolean first_match = (i < text.length() && 22 | (pattern.charAt(j) == text.charAt(i) || 23 | pattern.charAt(j) == '.')); 24 | 25 | if (j + 1 < pattern.length() && pattern.charAt(j+1) == '*'){ 26 | ans = (dp(i, j+2, text, pattern) || 27 | first_match && dp(i+1, j, text, pattern)); 28 | } else { 29 | ans = first_match && dp(i+1, j+1, text, pattern); 30 | } 31 | } 32 | memo[i][j] = ans ? Result.TRUE : Result.FALSE; 33 | return ans; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Java-codes/ReverseInteger.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int reverse(int x) { 3 | int rev = 0; 4 | while (x != 0) { 5 | int pop = x % 10; 6 | x /= 10; 7 | if (rev > Integer.MAX_VALUE/10 || (rev == Integer.MAX_VALUE / 10 && pop > 7)) return 0; 8 | if (rev < Integer.MIN_VALUE/10 || (rev == Integer.MIN_VALUE / 10 && pop < -8)) return 0; 9 | rev = rev * 10 + pop; 10 | } 11 | return rev; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Java-codes/Sorting/bubblesort.java: -------------------------------------------------------------------------------- 1 | public class BubbleSortExample { 2 | static void bubbleSort(int[] arr) { 3 | int n = arr.length; 4 | int temp = 0; 5 | for(int i=0; i < n; i++){ 6 | for(int j=1; j < (n-i); j++){ 7 | if(arr[j-1] > arr[j]){ 8 | //swap elements 9 | temp = arr[j-1]; 10 | arr[j-1] = arr[j]; 11 | arr[j] = temp; 12 | } 13 | 14 | } 15 | } 16 | 17 | } 18 | public static void main(String[] args) { 19 | int arr[] ={3,60,35,2,45,320,5}; 20 | 21 | System.out.println("Array Before Bubble Sort"); 22 | for(int i=0; i < arr.length; i++){ 23 | System.out.print(arr[i] + " "); 24 | } 25 | System.out.println(); 26 | 27 | bubbleSort(arr);//sorting array elements using bubble sort 28 | 29 | System.out.println("Array After Bubble Sort"); 30 | for(int i=0; i < arr.length; i++){ 31 | System.out.print(arr[i] + " "); 32 | } 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Java-codes/Sorting/heapsort.java: -------------------------------------------------------------------------------- 1 | 2 | // Java program for implementation of Heap Sort 3 | public class HeapSort 4 | { 5 | public void sort(int arr[]) 6 | { 7 | int n = arr.length; 8 | 9 | // Build heap (rearrange array) 10 | for (int i = n / 2 - 1; i >= 0; i--) 11 | heapify(arr, n, i); 12 | 13 | // One by one extract an element from heap 14 | for (int i=n-1; i>=0; i--) 15 | { 16 | // Move current root to end 17 | int temp = arr[0]; 18 | arr[0] = arr[i]; 19 | arr[i] = temp; 20 | 21 | // call max heapify on the reduced heap 22 | heapify(arr, i, 0); 23 | } 24 | } 25 | 26 | // To heapify a subtree rooted with node i which is 27 | // an index in arr[]. n is size of heap 28 | void heapify(int arr[], int n, int i) 29 | { 30 | int largest = i; // Initialize largest as root 31 | int l = 2*i + 1; // left = 2*i + 1 32 | int r = 2*i + 2; // right = 2*i + 2 33 | 34 | // If left child is larger than root 35 | if (l < n && arr[l] > arr[largest]) 36 | largest = l; 37 | 38 | // If right child is larger than largest so far 39 | if (r < n && arr[r] > arr[largest]) 40 | largest = r; 41 | 42 | // If largest is not root 43 | if (largest != i) 44 | { 45 | int swap = arr[i]; 46 | arr[i] = arr[largest]; 47 | arr[largest] = swap; 48 | 49 | // Recursively heapify the affected sub-tree 50 | heapify(arr, n, largest); 51 | } 52 | } 53 | 54 | /* A utility function to print array of size n */ 55 | static void printArray(int arr[]) 56 | { 57 | int n = arr.length; 58 | for (int i=0; i MAX) return MAX; //likewise. 24 | 25 | i++; 26 | } 27 | return (int)ans*sign; //convert ans to integer and return. 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Java-codes/ZigzagConversion.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String convert(String s, int numRows) { 3 | 4 | if (numRows == 1) return s; 5 | 6 | StringBuilder ret = new StringBuilder(); 7 | int n = s.length(); 8 | int cycleLen = 2 * numRows - 2; 9 | 10 | for (int i = 0; i < numRows; i++) { 11 | for (int j = 0; j + i < n; j += cycleLen) { 12 | ret.append(s.charAt(j + i)); 13 | if (i != 0 && i != numRows - 1 && j + cycleLen - i < n) 14 | ret.append(s.charAt(j + cycleLen - i)); 15 | } 16 | } 17 | return ret.toString(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Java-codes/dijkastra.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.lang.*; 3 | import java.io.*; 4 | 5 | class ShortestPath { 6 | // A utility function to find the vertex with minimum distance value, 7 | // from the set of vertices not yet included in shortest path tree 8 | static final int V = 9; 9 | int minDistance(int dist[], Boolean sptSet[]) 10 | { 11 | // Initialize min value 12 | int min = Integer.MAX_VALUE, min_index = -1; 13 | 14 | for (int v = 0; v < V; v++) 15 | if (sptSet[v] == false && dist[v] <= min) { 16 | min = dist[v]; 17 | min_index = v; 18 | } 19 | 20 | return min_index; 21 | } 22 | 23 | // A utility function to print the constructed distance array 24 | void printSolution(int dist[], int n) 25 | { 26 | System.out.println("Vertex Distance from Source"); 27 | for (int i = 0; i < V; i++) 28 | System.out.println(i + " tt " + dist[i]); 29 | } 30 | 31 | // Function that implements Dijkstra's single source shortest path 32 | // algorithm for a graph represented using adjacency matrix 33 | // representation 34 | void dijkstra(int graph[][], int src) 35 | { 36 | int dist[] = new int[V]; // The output array. dist[i] will hold 37 | // the shortest distance from src to i 38 | 39 | // sptSet[i] will true if vertex i is included in shortest 40 | // path tree or shortest distance from src to i is finalized 41 | Boolean sptSet[] = new Boolean[V]; 42 | 43 | // Initialize all distances as INFINITE and stpSet[] as false 44 | for (int i = 0; i < V; i++) { 45 | dist[i] = Integer.MAX_VALUE; 46 | sptSet[i] = false; 47 | } 48 | 49 | // Distance of source vertex from itself is always 0 50 | dist[src] = 0; 51 | 52 | // Find shortest path for all vertices 53 | for (int count = 0; count < V - 1; count++) { 54 | // Pick the minimum distance vertex from the set of vertices 55 | // not yet processed. u is always equal to src in first 56 | // iteration. 57 | int u = minDistance(dist, sptSet); 58 | 59 | // Mark the picked vertex as processed 60 | sptSet[u] = true; 61 | 62 | // Update dist value of the adjacent vertices of the 63 | // picked vertex. 64 | for (int v = 0; v < V; v++) 65 | 66 | // Update dist[v] only if is not in sptSet, there is an 67 | // edge from u to v, and total weight of path from src to 68 | // v through u is smaller than current value of dist[v] 69 | if (!sptSet[v] && graph[u][v] != 0 && 70 | dist[u] != Integer.MAX_VALUE && dist[u] + graph[u][v] < dist[v]) 71 | dist[v] = dist[u] + graph[u][v]; 72 | } 73 | 74 | // print the constructed distance array 75 | printSolution(dist, V); 76 | } 77 | 78 | // Driver method 79 | public static void main(String[] args) 80 | { 81 | /* Let us create the example graph discussed above */ 82 | int graph[][] = new int[][] { { 0, 4, 0, 0, 0, 0, 0, 8, 0 }, 83 | { 4, 0, 8, 0, 0, 0, 0, 11, 0 }, 84 | { 0, 8, 0, 7, 0, 4, 0, 0, 2 }, 85 | { 0, 0, 7, 0, 9, 14, 0, 0, 0 }, 86 | { 0, 0, 0, 9, 0, 10, 0, 0, 0 }, 87 | { 0, 0, 4, 14, 10, 0, 2, 0, 0 }, 88 | { 0, 0, 0, 0, 0, 2, 0, 1, 6 }, 89 | { 8, 11, 0, 0, 0, 0, 1, 0, 7 }, 90 | { 0, 0, 2, 0, 0, 0, 6, 7, 0 } }; 91 | ShortestPath t = new ShortestPath(); 92 | t.dijkstra(graph, 0); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /Java-codes/huffman_Coding.java: -------------------------------------------------------------------------------- 1 | import java.util.PriorityQueue; 2 | import java.util.Scanner; 3 | import java.util.Comparator; 4 | 5 | class Huffman { 6 | public static void printCode(HuffmanNode root, String s) 7 | { 8 | if (root.left 9 | == null 10 | && root.right 11 | == null 12 | && Character.isLetter(root.c)) { 13 | System.out.println(root.c + ":" + s); 14 | 15 | return; 16 | } 17 | printCode(root.left, s + "0"); 18 | printCode(root.right, s + "1"); 19 | } 20 | public static void main(String[] args) 21 | { 22 | Scanner s = new Scanner(System.in); 23 | int n = 6; 24 | char[] charArray = { 'a', 'b', 'c', 'd', 'e', 'f' }; 25 | int[] charfreq = { 5, 9, 12, 13, 16, 45 }; 26 | PriorityQueue q 27 | = new PriorityQueue(n, new MyComparator()); 28 | 29 | for (int i = 0; i < n; i++) { 30 | HuffmanNode hn = new HuffmanNode(); 31 | hn.c = charArray[i]; 32 | hn.data = charfreq[i]; 33 | hn.left = null; 34 | hn.right = null; 35 | q.add(hn); 36 | } 37 | HuffmanNode root = null; 38 | while (q.size() > 1) { 39 | HuffmanNode x = q.peek(); 40 | q.poll(); 41 | HuffmanNode y = q.peek(); 42 | q.poll(); 43 | HuffmanNode f = new HuffmanNode(); 44 | f.data = x.data + y.data; 45 | f.c = '-'; 46 | f.left = x; 47 | f.right = y; 48 | root = f; 49 | q.add(f); 50 | } 51 | printCode(root, ""); 52 | } 53 | } 54 | class HuffmanNode { 55 | int data; 56 | char c; 57 | HuffmanNode left; 58 | HuffmanNode right; 59 | } 60 | class MyComparator implements Comparator { 61 | public int compare(HuffmanNode x, HuffmanNode y) 62 | { 63 | 64 | return x.data - y.data; 65 | } 66 | } 67 | 68 | // This code is contributed by Nishant Choudhary 69 | -------------------------------------------------------------------------------- /Java-codes/impotant Programs/BFS.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | class Graph { 3 | 4 | private int V; 5 | private LinkedList adj[]; 6 | Graph(int v) { 7 | V = v; 8 | adj = new LinkedList[v]; 9 | for (int i = 0; i < v; ++i) 10 | adj[i] = new LinkedList(); 11 | } 12 | void addEdge(int v, int w) { 13 | adj[v].add(w); 14 | } 15 | void BFS(int s) { 16 | 17 | boolean visited[] = new boolean[V]; 18 | 19 | LinkedList queue = new LinkedList(); 20 | 21 | visited[s] = true; 22 | queue.add(s); 23 | 24 | while (queue.size() != 0) { 25 | s = queue.poll(); 26 | System.out.print(s + " "); 27 | 28 | Iterator i = adj[s].listIterator(); 29 | while (i.hasNext()) { 30 | int n = i.next(); 31 | if (!visited[n]) { 32 | visited[n] = true; 33 | queue.add(n); 34 | } 35 | } 36 | } 37 | } 38 | 39 | public static void main(String args[]) { 40 | Graph g = new Graph(4); 41 | 42 | g.addEdge(0, 1); 43 | g.addEdge(0, 2); 44 | g.addEdge(1, 2); 45 | g.addEdge(2, 0); 46 | g.addEdge(2, 3); 47 | g.addEdge(3, 3); 48 | 49 | System.out.println("Following is Breadth First Traversal " + "(starting from vertex 2)"); 50 | 51 | g.BFS(2); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Java-codes/impotant Programs/Binary_search_tree_in_java.java: -------------------------------------------------------------------------------- 1 | class BST_class { 2 | //node class that defines BST node 3 | class Node { 4 | int key; 5 | Node left, right; 6 | 7 | public Node(int data){ 8 | key = data; 9 | left = right = null; 10 | } 11 | } 12 | // BST root node 13 | Node root; 14 | 15 | // Constructor for BST =>initial empty tree 16 | BST_class(){ 17 | root = null; 18 | } 19 | //delete a node from BST 20 | void deleteKey(int key) { 21 | root = delete_Recursive(root, key); 22 | } 23 | 24 | //recursive delete function 25 | Node delete_Recursive(Node root, int key) { 26 | //tree is empty 27 | if (root == null) return root; 28 | 29 | //traverse the tree 30 | if (key < root.key) //traverse left subtree 31 | root.left = delete_Recursive(root.left, key); 32 | else if (key > root.key) //traverse right subtree 33 | root.right = delete_Recursive(root.right, key); 34 | else { 35 | // node contains only one child 36 | if (root.left == null) 37 | return root.right; 38 | else if (root.right == null) 39 | return root.left; 40 | 41 | // node has two children; 42 | //get inorder successor (min value in the right subtree) 43 | root.key = minValue(root.right); 44 | 45 | // Delete the inorder successor 46 | root.right = delete_Recursive(root.right, root.key); 47 | } 48 | return root; 49 | } 50 | 51 | int minValue(Node root) { 52 | //initially minval = root 53 | int minval = root.key; 54 | //find minval 55 | while (root.left != null) { 56 | minval = root.left.key; 57 | root = root.left; 58 | } 59 | return minval; 60 | } 61 | 62 | // insert a node in BST 63 | void insert(int key) { 64 | root = insert_Recursive(root, key); 65 | } 66 | 67 | //recursive insert function 68 | Node insert_Recursive(Node root, int key) { 69 | //tree is empty 70 | if (root == null) { 71 | root = new Node(key); 72 | return root; 73 | } 74 | //traverse the tree 75 | if (key < root.key) //insert in the left subtree 76 | root.left = insert_Recursive(root.left, key); 77 | else if (key > root.key) //insert in the right subtree 78 | root.right = insert_Recursive(root.right, key); 79 | // return pointer 80 | return root; 81 | } 82 | 83 | // method for inorder traversal of BST 84 | void inorder() { 85 | inorder_Recursive(root); 86 | } 87 | 88 | // recursively traverse the BST 89 | void inorder_Recursive(Node root) { 90 | if (root != null) { 91 | inorder_Recursive(root.left); 92 | System.out.print(root.key + " "); 93 | inorder_Recursive(root.right); 94 | } 95 | } 96 | 97 | boolean search(int key) { 98 | root = search_Recursive(root, key); 99 | if (root!= null) 100 | return true; 101 | else 102 | return false; 103 | } 104 | 105 | //recursive insert function 106 | Node search_Recursive(Node root, int key) { 107 | // Base Cases: root is null or key is present at root 108 | if (root==null || root.key==key) 109 | return root; 110 | // val is greater than root's key 111 | if (root.key > key) 112 | return search_Recursive(root.left, key); 113 | // val is less than root's key 114 | return search_Recursive(root.right, key); 115 | } 116 | } 117 | class Main{ 118 | public static void main(String[] args) { 119 | //create a BST object 120 | BST_class bst = new BST_class(); 121 | /* BST tree example 122 | 45 123 | / \ 124 | 10 90 125 | / \ / 126 | 7 12 50 */ 127 | //insert data into BST 128 | bst.insert(45); 129 | bst.insert(10); 130 | bst.insert(7); 131 | bst.insert(12); 132 | bst.insert(90); 133 | bst.insert(50); 134 | //print the BST 135 | System.out.println("The BST Created with input data(Left-root-right):"); 136 | bst.inorder(); 137 | 138 | //delete leaf node 139 | System.out.println("\nThe BST after Delete 12(leaf node):"); 140 | bst.deleteKey(12); 141 | bst.inorder(); 142 | //delete the node with one child 143 | System.out.println("\nThe BST after Delete 90 (node with 1 child):"); 144 | bst.deleteKey(90); 145 | bst.inorder(); 146 | 147 | //delete node with two children 148 | System.out.println("\nThe BST after Delete 45 (Node with two children):"); 149 | bst.deleteKey(45); 150 | bst.inorder(); 151 | //search a key in the BST 152 | boolean ret_val = bst.search (50); 153 | System.out.println("\nKey 50 found in BST:" + ret_val ); 154 | ret_val = bst.search (12); 155 | System.out.println("\nKey 12 found in BST:" + ret_val ); 156 | } 157 | } -------------------------------------------------------------------------------- /Java-codes/impotant Programs/Concatenate.java: -------------------------------------------------------------------------------- 1 | class Concatenate 2 | { 3 | public static void main(String args[]){ 4 | 5 | String s1="Sachin "; 6 | String s2="Tendulkar"; 7 | 8 | String s3=s1.concat(s2); 9 | 10 | System.out.println(s3);//Sachin Tendulkar 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Java-codes/impotant Programs/FactorialofNum.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | public class Factorial 3 | { 4 | public static void main(String[] args) 5 | { 6 | Scanner in=new Scanner(System.in); 7 | System.out.println("Enter any number "); 8 | int num,i,f=1; 9 | num=in.nextInt(); 10 | for ( i=1;i<=num;i++) 11 | { 12 | f=f*i; 13 | } 14 | if(num==0) 15 | System.out.println("factorial of given number is : 0 "); 16 | else 17 | System.out.println("factorial of given number is :"+f); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Java-codes/impotant Programs/Fibonacci.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class Fibonacci 3 | { 4 | public static void main(String[] args) 5 | { 6 | Scanner in = new Scanner(System.in); 7 | int a,b=1,c=0,num; 8 | System.out.println("Enter how many number you want to print fibonacci series"); 9 | num= in.nextInt(); 10 | for(int i=1;i<=num;i++) 11 | { 12 | System.out.println(c+" "); 13 | a=b; 14 | b=c; 15 | c=a+b; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Java-codes/impotant Programs/Top_view_of_binary_tree.java: -------------------------------------------------------------------------------- 1 | // Java program to print top 2 | // view of binary tree 3 | import java.util.LinkedList; 4 | import java.util.Map; 5 | import java.util.Map.Entry; 6 | import java.util.Queue; 7 | import java.util.TreeMap; 8 | 9 | // class to create a node 10 | class Node { 11 | int data; 12 | Node left, right; 13 | 14 | public Node(int data) 15 | { 16 | this.data = data; 17 | left = right = null; 18 | } 19 | } 20 | 21 | // class of binary tree 22 | class BinaryTree { 23 | Node root; 24 | 25 | public BinaryTree() { root = null; } 26 | 27 | // function should print the topView of 28 | // the binary tree 29 | private void TopView(Node root) 30 | { 31 | class QueueObj { 32 | Node node; 33 | int hd; 34 | 35 | QueueObj(Node node, int hd) 36 | { 37 | this.node = node; 38 | this.hd = hd; 39 | } 40 | } 41 | Queue q = new LinkedList(); 42 | Map topViewMap 43 | = new TreeMap(); 44 | 45 | if (root == null) { 46 | return; 47 | } 48 | else { 49 | q.add(new QueueObj(root, 0)); 50 | } 51 | 52 | System.out.println( 53 | "The top view of the tree is : "); 54 | 55 | // count function returns 1 if the container 56 | // contains an element whose key is equivalent 57 | // to hd, or returns zero otherwise. 58 | while (!q.isEmpty()) { 59 | QueueObj tmpNode = q.poll(); 60 | if (!topViewMap.containsKey(tmpNode.hd)) { 61 | topViewMap.put(tmpNode.hd, tmpNode.node); 62 | } 63 | 64 | if (tmpNode.node.left != null) { 65 | q.add(new QueueObj(tmpNode.node.left, 66 | tmpNode.hd - 1)); 67 | } 68 | if (tmpNode.node.right != null) { 69 | q.add(new QueueObj(tmpNode.node.right, 70 | tmpNode.hd + 1)); 71 | } 72 | } 73 | for (Map.Entry entry : 74 | topViewMap.entrySet()) { 75 | System.out.print(entry.getValue().data + " "); 76 | } 77 | } 78 | 79 | // Driver Program to test above functions 80 | public static void main(String[] args) 81 | { 82 | /* Create following Binary Tree 83 | 1 84 | / \ 85 | 2 3 86 | \ 87 | 4 88 | \ 89 | 5 90 | \ 91 | 6 92 | */ 93 | BinaryTree tree = new BinaryTree(); 94 | tree.root = new Node(1); 95 | tree.root.left = new Node(2); 96 | tree.root.right = new Node(3); 97 | tree.root.left.right = new Node(4); 98 | tree.root.left.right.right = new Node(5); 99 | tree.root.left.right.right.right = new Node(6); 100 | System.out.println( 101 | "Following are nodes in top view of Binary Tree"); 102 | tree.TopView(tree.root); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /Java-codes/impotant Programs/calculator.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class Main { 3 | public static void main(String[] args) { 4 | char operator; 5 | Double number1, number2, result; 6 | Scanner input = new Scanner(System.in); 7 | System.out.println("Choose an operator: +, -, *, or /"); 8 | operator = input.next().charAt(0); 9 | System.out.println("Enter first number"); 10 | number1 = input.nextDouble(); 11 | System.out.println("Enter second number"); 12 | number2 = input.nextDouble(); 13 | switch (operator) { 14 | case '+': 15 | result = number1 + number2; 16 | System.out.println(number1 + " + " + number2 + " = " + result); 17 | break; 18 | case '-': 19 | result = number1 - number2; 20 | System.out.println(number1 + " - " + number2 + " = " + result); 21 | break; 22 | case '*': 23 | result = number1 * number2; 24 | System.out.println(number1 + " * " + number2 + " = " + result); 25 | break; 26 | case '/': 27 | result = number1 / number2; 28 | System.out.println(number1 + " / " + number2 + " = " + result); 29 | break; 30 | default: 31 | System.out.println("Invalid operator!"); 32 | break; 33 | } 34 | input.close(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Java-codes/impotant Programs/checkPalindrome.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | public class CheckPalindrome 3 | { 4 | public static void main(String[] args) 5 | { 6 | Scanner in = new Scanner(System.in); 7 | int num,b,cpy,rev=0; 8 | System.out.println("Enter any number "); 9 | num=in.nextInt(); 10 | cpy=num; 11 | while(num!=0) 12 | { 13 | b=num%10; 14 | rev=rev*10+b; 15 | num=num/10; 16 | } 17 | if(cpy==rev) 18 | System.out.println("number is palindrome"); 19 | else 20 | System.out.println("number is not palindrome"); 21 | } 22 | } 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Java-codes/impotant Programs/checkevenodd.java: -------------------------------------------------------------------------------- 1 | //program to check number is even or odd 2 | import java.util.Scanner; 3 | class Check 4 | { 5 | public static void main(String[] args) 6 | { 7 | Scanner in= new Scanner(System.in); 8 | System.out.println("Enter any number"); 9 | int num =in.nextInt(); 10 | if(num%2==0) 11 | System.out.println("number is even"); 12 | else 13 | System.out.println("numberis odd"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Java-codes/impotant Programs/kadane’sAlgo.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.lang.*; 3 | import java.io.*; 4 | class Main { 5 | public static int maximumSubarraySum(int[] arr) { 6 | int n = arr.length; 7 | int maxSum = Integer.MIN_VALUE; 8 | 9 | for (int i = 0; i <= n - 1; i++) { 10 | int currSum = 0; 11 | for (int j = i; j <= n - 1; j++) { 12 | currSum += arr[j]; 13 | if (currSum > maxSum) { 14 | maxSum = currSum; 15 | } 16 | } 17 | } 18 | 19 | return maxSum; 20 | } 21 | public static void main(String args[]) { 22 | // Your code goes here 23 | int a[] = {1, 3, 8, -2, 6, -8, 5}; 24 | System.out.println(maximumSubarraySum(a)); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Java-codes/impotant Programs/prime-number.java: -------------------------------------------------------------------------------- 1 | public class PrimeExample{ 2 | public static void main(String args[]){ 3 | int i,m=0,flag=0; 4 | int n=3; 5 | m=n/2; 6 | if(n==0||n==1){ 7 | System.out.println(n+" is not prime number"); 8 | }else{ 9 | for(i=2;i<=m;i++){ 10 | if(n%i==0){ 11 | System.out.println(n+" is not prime number"); 12 | flag=1; 13 | break; 14 | } 15 | } 16 | if(flag==0) { System.out.println(n+" is prime number"); } 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Java-codes/impotant Programs/rat_in_maze.java: -------------------------------------------------------------------------------- 1 | /* Java program to solve Rat in 2 | a Maze problem using backtracking */ 3 | 4 | public class RatMaze { 5 | 6 | // Size of the maze 7 | static int N; 8 | 9 | /* A utility function to print 10 | solution matrix sol[N][N] */ 11 | void printSolution(int sol[][]) 12 | { 13 | for (int i = 0; i < N; i++) { 14 | for (int j = 0; j < N; j++) 15 | System.out.print( 16 | " " + sol[i][j] + " "); 17 | System.out.println(); 18 | } 19 | } 20 | 21 | /* A utility function to check 22 | if x, y is valid index for N*N maze */ 23 | boolean isSafe( 24 | int maze[][], int x, int y) 25 | { 26 | // if (x, y outside maze) return false 27 | return (x >= 0 && x < N && y >= 0 28 | && y < N && maze[x][y] == 1); 29 | } 30 | 31 | /* This function solves the Maze problem using 32 | Backtracking. It mainly uses solveMazeUtil() 33 | to solve the problem. It returns false if no 34 | path is possible, otherwise return true and 35 | prints the path in the form of 1s. Please note 36 | that there may be more than one solutions, this 37 | function prints one of the feasible solutions.*/ 38 | boolean solveMaze(int maze[][]) 39 | { 40 | int sol[][] = new int[N][N]; 41 | 42 | if (solveMazeUtil(maze, 0, 0, sol) == false) { 43 | System.out.print("Solution doesn't exist"); 44 | return false; 45 | } 46 | 47 | printSolution(sol); 48 | return true; 49 | } 50 | 51 | /* A recursive utility function to solve Maze 52 | problem */ 53 | boolean solveMazeUtil(int maze[][], int x, int y, 54 | int sol[][]) 55 | { 56 | // if (x, y is goal) return true 57 | if (x == N - 1 && y == N - 1 58 | && maze[x][y] == 1) { 59 | sol[x][y] = 1; 60 | return true; 61 | } 62 | 63 | // Check if maze[x][y] is valid 64 | if (isSafe(maze, x, y) == true) { 65 | // Check if the current block is already part of solution path. 66 | if (sol[x][y] == 1) 67 | return false; 68 | 69 | // mark x, y as part of solution path 70 | sol[x][y] = 1; 71 | 72 | /* Move forward in x direction */ 73 | if (solveMazeUtil(maze, x + 1, y, sol)) 74 | return true; 75 | 76 | /* If moving in x direction doesn't give 77 | solution then Move down in y direction */ 78 | if (solveMazeUtil(maze, x, y + 1, sol)) 79 | return true; 80 | 81 | /* If none of the above movements works then 82 | BACKTRACK: unmark x, y as part of solution 83 | path */ 84 | sol[x][y] = 0; 85 | return false; 86 | } 87 | 88 | return false; 89 | } 90 | 91 | public static void main(String args[]) 92 | { 93 | RatMaze rat = new RatMaze(); 94 | int maze[][] = { { 1, 0, 0, 0 }, 95 | { 1, 1, 0, 1 }, 96 | { 0, 1, 0, 0 }, 97 | { 1, 1, 1, 1 } }; 98 | 99 | N = maze.length; 100 | rat.solveMaze(maze); 101 | } 102 | } 103 | // This code is contributed by Abhishek Shankhadhar 104 | -------------------------------------------------------------------------------- /Java-codes/impotant Programs/swapping.java: -------------------------------------------------------------------------------- 1 | public class Swapping { 2 | 3 | public static void main(String[] args) { 4 | 5 | float first = 13.0f, second = 23.4f; 6 | 7 | System.out.println("--Before swap--"); 8 | System.out.println("First number = " + first); 9 | System.out.println("Second number = " + second); 10 | 11 | // Value of first is assigned to temporary 12 | float temporary = first; 13 | 14 | // Value of second is assigned to first 15 | first = second; 16 | 17 | // Value of temporary (which contains the initial value of first) is assigned to second 18 | second = temporary; 19 | 20 | System.out.println("--After swap--"); 21 | System.out.println("First number = " + first); 22 | System.out.println("Second number = " + second); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Java-codes/kadanes_algorithm.java: -------------------------------------------------------------------------------- 1 | package me.company; 2 | import java.util.*; 3 | public class kadanes_algorithm 4 | { 5 | public static void main(String args[]) 6 | { 7 | Scanner sc=new Scanner(System.in); 8 | System.out.println("Enter the no. of elements in array"); 9 | int n=sc.nextInt(); 10 | int a[]=new int[n]; 11 | System.out.println("Enter the elements of the array : "); 12 | for(int i=0; i=0) 21 | curr_sum+=a[i]; 22 | else 23 | curr_sum=a[i]; 24 | 25 | if(curr_sum>total_sum) 26 | total_sum=curr_sum; 27 | } 28 | System.out.println("Maximum sum subarray is : "+total_sum); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Java-codes/matrixadd.java: -------------------------------------------------------------------------------- 1 | public class MatrixAdd{ 2 | public static void main(String args[]){ 3 | //creating two matrices 4 | int x[][]={{1,3,4},{2,4,3},{3,4,5}}; 5 | int y[][]={{1,3,4},{2,4,3},{1,2,4}}; 6 | 7 | //creating another matrix to store the sum of two matrices 8 | int z[][]=new int[2][2]; //2 rows and 2 columns 9 | 10 | //adding and printing addition of 2 matrices 11 | for(int i=0;i<2;i++){ 12 | for(int j=0;j<2;j++){ 13 | z[i][j]=x[i][j]+y[i][j]; //use - for subtraction 14 | System.out.print(z[i][j]+" "); 15 | } 16 | System.out.println();//new line 17 | } 18 | }} 19 | -------------------------------------------------------------------------------- /Java-codes/reverse_the_array.java: -------------------------------------------------------------------------------- 1 | // Iterative java program to reverse an 2 | 3 | // array 4 | 5 | public class GFG { 6 | 7 | /* Function to reverse arr[] from 8 | 9 | start to end*/ 10 | 11 | static void rvereseArray(int arr[], 12 | 13 | int start, int end) 14 | 15 | { 16 | 17 | int temp; 18 | 19 | 20 | 21 | while (start < end) 22 | 23 | { 24 | 25 | temp = arr[start]; 26 | 27 | arr[start] = arr[end]; 28 | 29 | arr[end] = temp; 30 | 31 | start++; 32 | 33 | end--; 34 | 35 | } 36 | 37 | } 38 | 39 | 40 | 41 | /* Utility that prints out an 42 | 43 | array on a line */ 44 | 45 | static void printArray(int arr[], 46 | 47 | int size) 48 | 49 | { 50 | 51 | for (int i = 0; i < size; i++) 52 | 53 | System.out.print(arr[i] + " "); 54 | 55 | 56 | 57 | System.out.println(); 58 | 59 | } 60 | 61 | // Driver code 62 | 63 | public static void main(String args[]) { 64 | 65 | 66 | 67 | int arr[] = {1, 2, 3, 4, 5, 6}; 68 | 69 | printArray(arr, 6); 70 | 71 | rvereseArray(arr, 0, 5); 72 | 73 | System.out.print("Reversed array is \n"); 74 | 75 | printArray(arr, 6); 76 | 77 | 78 | 79 | } 80 | 81 | } 82 | 83 | // This code is contributed by Mahesmati Maharana 84 | -------------------------------------------------------------------------------- /Java-codes/timer.java: -------------------------------------------------------------------------------- 1 | import java.util.Calendar; 2 | import java.util.Timer; 3 | import java.util.TimerTask; 4 | public class ScheduleTimer 5 | { 6 | public static void main(String args[]) 7 | { 8 | //instance of the Timer class 9 | Timer timer = new Timer(); 10 | TimerTask task = new TimerTask() 11 | { 12 | //represent the time after which the task will begin to execute 13 | int i = 5; 14 | @Override 15 | public void run() 16 | { 17 | if(i>0) 18 | { 19 | System.out.println(i); 20 | i--; 21 | } 22 | else 23 | { 24 | System.out.println("Wish You Very Happy Birthday!!"); 25 | //cancel the task once it is completed 26 | timer.cancel(); 27 | } 28 | } 29 | }; 30 | //creating an instance of the Calendar class 31 | Calendar date = Calendar.getInstance(); 32 | //setting the date and time on which timer will begin 33 | date.set(2022, Calendar.MARCH, 30,23, 59, 54); 34 | //enables the counter to count at a rate of 1 second 35 | timer.scheduleAtFixedRate(task, date.getTime(), 1000); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | CodedNepal-logo 4 | 5 |

6 |

Hacktober Fest 2022

7 | 8 |

Give a Star to This repo:fire::star:

9 | 10 | 11 |

12 | 13 | GitHub Issues 14 | 15 |     16 | 17 | GitHub Stars 18 | 19 |     20 | 21 | GitHub Forks 22 | 23 |
24 | 25 |

Open source for everybody.

26 |

27 | 28 | ## Table of Contents 29 | 30 | - [C-Programming](/C-codes) 31 | - [C++-Programming](/c++) 32 | - [Java-Programming](/Java-codes) 33 | - [React](/React) 34 | - [Python Programming](/python) 35 | - [Web-Projects](/Web) 36 | 37 | 38 | ## Contributing 39 | 40 | Contributions are always welcome! 41 | 42 | See `contributing.md` for ways to get started. 43 | 44 | Add any Simple or Complex Program in any language you Like in this Repository by clicking "Add File -> Create new File". 45 | 46 | 47 | If you liked working on this project, please share this project as much as you can and star this project to help as many people in opensource as you can. 48 | 49 | ## Note: 50 | 51 | 1. Don't Create Pull Request to update "readme.md" File. 52 | 2. Upload or Create File in Specified Language Folder. 53 | 3. If Specified Language Folder not Found then Create Folder and then Upload or Create File. 54 | -------------------------------------------------------------------------------- /React/portfolio/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "info", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.16.5", 7 | "@testing-library/react": "^13.4.0", 8 | "@testing-library/user-event": "^13.5.0", 9 | "autoprefixer": "^10.4.8", 10 | "postcss": "^8.4.16", 11 | "react": "^18.2.0", 12 | "react-dom": "^18.2.0", 13 | "react-icons": "^4.4.0", 14 | "react-router-dom": "^6.3.0", 15 | "react-scripts": "5.0.1", 16 | "tailwindcss": "^3.1.8", 17 | "web-vitals": "^2.1.4" 18 | }, 19 | "scripts": { 20 | "start": "react-scripts start", 21 | "build": "react-scripts build", 22 | "test": "react-scripts test", 23 | "eject": "react-scripts eject" 24 | }, 25 | "eslintConfig": { 26 | "extends": [ 27 | "react-app", 28 | "react-app/jest" 29 | ] 30 | }, 31 | "browserslist": { 32 | "production": [ 33 | ">0.2%", 34 | "not dead", 35 | "not op_mini all" 36 | ], 37 | "development": [ 38 | "last 1 chrome version", 39 | "last 1 firefox version", 40 | "last 1 safari version" 41 | ] 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /VisualBasic/Readme.md: -------------------------------------------------------------------------------- 1 | Add your Vb code here. 2 | -------------------------------------------------------------------------------- /VisualBasic/Simpleprograms/Areaofparallelogram.vb: -------------------------------------------------------------------------------- 1 | Module Program 2 | Public Sub main() 3 | Dim base As Integer 4 | Dim height As Integer 5 | Console.WriteLine("enter base") 6 | base = Console.ReadLine() 7 | Console.WriteLine("enter height") 8 | height = Console.ReadLine() 9 | Dim area As Integer 10 | area = base * height 11 | Console.WriteLine("Area of Parallelogram {0}", area) 12 | Console.ReadKey() 13 | End Sub 14 | End Module 15 | -------------------------------------------------------------------------------- /VisualBasic/Simpleprograms/Mathematicalcalculations.vb: -------------------------------------------------------------------------------- 1 | Module Program 2 | Public Sub main() 3 | Dim a, b As Integer 4 | Dim add, diff, product, divide As Integer 5 | Console.WriteLine("enter first number") 6 | a = Console.ReadLine() 7 | Console.WriteLine("enter second number") 8 | b = Console.ReadLine() 9 | 10 | add = a + b 11 | diff = a - b 12 | product = a * b 13 | divide = a / b 14 | Console.WriteLine("Addition is {0}", add) 15 | Console.WriteLine("subraction is {0}", diff) 16 | Console.WriteLine("Product is {0}", product) 17 | Console.WriteLine("Division is {0}", divide) 18 | End Sub 19 | End Module 20 | -------------------------------------------------------------------------------- /VisualBasic/Simpleprograms/typeconverison.vb: -------------------------------------------------------------------------------- 1 | Option Strict On 2 | 3 | Module Program 4 | Public Sub main() 5 | Dim n As Integer 6 | Dim da As Date 7 | Dim bl As Boolean = True 8 | n = 12345 9 | da = Today 10 | Console.WriteLine(bl) 11 | Console.WriteLine(CSByte(bl)) 12 | Console.WriteLine(CStr(bl)) 13 | Console.WriteLine(CChar(CStr(da))) 14 | Console.ReadKey() 15 | End Sub 16 | End Module 17 | -------------------------------------------------------------------------------- /Web/Google/index1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Google Fieldset 8 | 9 | 10 | 11 | 12 | 13 |
14 | 21 |

Sign in

22 |

Continue to Gmail

23 |
24 |
25 |
26 | 27 |

Email or phone

28 | 29 |
30 |
31 |
32 |
33 | 34 |

Password

35 | 36 |
37 |
38 | 39 |
40 | 41 |
42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /Web/Readme.md: -------------------------------------------------------------------------------- 1 | WebProjects here. 2 | -------------------------------------------------------------------------------- /Web/THEME/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Shikshya 10 | 11 | 12 | 13 | 14 | 15 | 24 | 25 |

Change the theme

26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /Web/THEME/index.js: -------------------------------------------------------------------------------- 1 | function changeTheme() { 2 | if (document.getElementById('button').innerHTML === 'Dark Theme') { 3 | document.body.style.background = '#555'; 4 | document.body.style.color = 'white'; 5 | document.getElementById('button').innerHTML = 'Light Theme'; 6 | } 7 | else { 8 | document.body.style.background = 'white'; 9 | document.body.style.color = '#555'; 10 | document.getElementById('button').innerHTML = 'Dark Theme'; 11 | } 12 | } -------------------------------------------------------------------------------- /Web/THEME/style.css: -------------------------------------------------------------------------------- 1 | @import url('https://fonts.googleapis.com/css?family=Quicksand&display=swap'); 2 | @import url('https://fonts.googleapis.com/css2?family=Advent+Pro&display=swap'); 3 | 4 | html, 5 | button { 6 | font-family: Quicksand, sans-serif; 7 | } 8 | 9 | body { 10 | background: white; 11 | color: #555; 12 | text-align: center; 13 | } 14 | 15 | .logo { 16 | margin-top: 30%; 17 | font-size: 30px; 18 | font-weight: normal; 19 | } 20 | 21 | .brackets { 22 | font-family: Advent Pro, sans-serif; 23 | } 24 | 25 | .left { 26 | color: tomato; 27 | } 28 | 29 | .right { 30 | color: dodgerblue; 31 | } 32 | 33 | .sample { 34 | padding: 20px; 35 | font-size: 18px; 36 | background: inherit; 37 | color: inherit; 38 | } 39 | 40 | #button { 41 | margin-top: 10px; 42 | background: dodgerblue; 43 | color: white; 44 | width: 80%; 45 | height: 60px; 46 | font-size: 20px; 47 | outline: none; 48 | border: 5px solid deepskyblue; 49 | border-radius: 5px; 50 | } 51 | 52 | #button:active { 53 | transform: scale(0.95); 54 | } -------------------------------------------------------------------------------- /Web/calculator/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Calculator 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /Web/calculator/script.js: -------------------------------------------------------------------------------- 1 | // This function clear all the values 2 | function clearScreen() { 3 | document.getElementById("result").value = ""; 4 | } 5 | 6 | 7 | // This function display values 8 | function display(value) { 9 | document.getElementById("result").value += value; 10 | } 11 | 12 | // This function evaluates the expression and return result 13 | function calculate() { 14 | var p = document.getElementById("result").value; 15 | var q = eval(p); 16 | document.getElementById("result").value = q; 17 | } -------------------------------------------------------------------------------- /Web/calculator/style.css: -------------------------------------------------------------------------------- 1 | @import url('https://fonts.googleapis.com/css2?family=Orbitron&display=swap'); 2 | 3 | .calculator { 4 | padding: 10px; 5 | border-radius: 1em; 6 | height: 380px; 7 | width: 400px; 8 | margin: auto; 9 | background-color: #252529; 10 | box-shadow: rgba(0, 0, 0, 0.19) 0px 10px 20px, rgba(0, 0, 0, 0.23) 0px 6px 6px; 11 | } 12 | .display-box { 13 | font-family: 'Orbitron', sans-serif; 14 | background-color: #dcdbe1; 15 | border: solid black 0.5px; 16 | color: black; 17 | border-radius: 5px; 18 | width: 100%; 19 | height: 65%; 20 | } 21 | #btn { 22 | background-color: #c500fb; 23 | } 24 | input[type=button] { 25 | font-family: 'Orbitron', sans-serif; 26 | background-color: #278f67; 27 | color: white; 28 | border: solid black 0.5px; 29 | width: 100%; 30 | border-radius: 5px; 31 | height: 70%; 32 | outline: none; 33 | } 34 | /* ends */ -------------------------------------------------------------------------------- /Web/loading.css: -------------------------------------------------------------------------------- 1 | body{ 2 | 3 | background: rgb(103, 103, 94); 4 | font-family: Georgia, 'Times New Roman', Times, serif; 5 | 6 | } 7 | .container{ 8 | width:100%; 9 | display:flex; 10 | align-items: center; 11 | justify-content: center; 12 | min-height: 100vh; 13 | flex-direction: column; 14 | } 15 | .text{ 16 | color: aliceblue; 17 | font-size: 25px; 18 | margin-bottom: 25px; 19 | 20 | } 21 | .loading{ 22 | width:100%; 23 | height:auto; 24 | display:flex; 25 | 26 | } 27 | 28 | .loading .line-box{ 29 | padding:2px; 30 | width:40%; 31 | height:20px; 32 | border:2px solid #00bbff; 33 | border-radius: 20px; 34 | margin-left: 600px; 35 | } 36 | .loading .line-box .line{ 37 | height:20px; 38 | border-radius: 20px; 39 | background: rgb(188, 83, 83); 40 | animation: loading 4s forwards cubic-bezier(0,0,0,0); 41 | 42 | } 43 | @keyframes loading{ 44 | 0%{ 45 | width:0%; 46 | 47 | } 48 | 100%{ 49 | width:100%; 50 | 51 | } 52 | } -------------------------------------------------------------------------------- /Web/loading.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Document 6 | 7 | 8 | 9 | 10 |
11 |
12 |

Loading...

13 |
14 |
15 |
16 |
17 | 18 |
19 |
20 |
21 |
22 | 23 | 24 | -------------------------------------------------------------------------------- /Web/loginpage/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codednepal/hacktober2022/8f64ced0fb555d6e1456228c0b73dd55068d67c7/Web/loginpage/4.jpg -------------------------------------------------------------------------------- /Web/loginpage/loginpage.css: -------------------------------------------------------------------------------- 1 | 2 | body{ 3 | width: 100%; 4 | background-image: url("4.jpg"); 5 | background-size: cover; 6 | height: 100vh; 7 | } 8 | 9 | .navbar{ 10 | width:1800px; 11 | height:75px; 12 | margin: auto; 13 | } 14 | 15 | .logo{ 16 | color:rgb(175, 224, 83); 17 | font-style:30px; 18 | padding-top:10px; 19 | float:left; 20 | font-size:40px; 21 | 22 | } 23 | 24 | .search{ 25 | width: 150px; 26 | float:right; 27 | margin-right: 500px; 28 | 29 | } 30 | 31 | .srch{ 32 | font-family: 'Times New Roman'; 33 | width:300px; 34 | height:45px; 35 | background: transparent; 36 | border:1px solid rgb(178, 94, 94);; 37 | margin-top:35px; 38 | color:rgb(255, 236, 240); 39 | padding:10px; 40 | font-size:15px; 41 | float:left; 42 | 43 | } 44 | .btn{ 45 | width:75px; 46 | height:50px; 47 | background:olivedrab; 48 | 49 | } 50 | 51 | .form{ 52 | width:250px; 53 | height:350px; 54 | background: linear-gradient(to top,rgba(0,0,0,0.5)50%,rgba(0,0,0,0.5)50%); 55 | position: absolute; 56 | top: 275px; 57 | left:100px; 58 | border-radius:11px; 59 | padding:25px; 60 | } 61 | .form h1{ 62 | width:220px; 63 | font-family: sans-serif; 64 | text-align: center; 65 | color:rgb(18, 70, 160); 66 | font-size: 22px; 67 | background-color: rgb(153, 164, 174); 68 | border-radius: 10px; 69 | margin: 2px; 70 | padding: 8px; 71 | 72 | } 73 | .form input{ 74 | width: 240px; 75 | height:34px; 76 | background: transparent; 77 | border-bottom: 1px,solid; 78 | border-top:none; 79 | border-right:none; 80 | border-left:none; 81 | color:rgb(237, 225, 225); 82 | font-size:16px; 83 | letter-spacing:1.5px; 84 | margin-top:30px; 85 | font-family: sans-serif; 86 | 87 | } 88 | .form input:focus{ 89 | outline:none; 90 | } 91 | ::placeholder{ 92 | color:rgb(240, 236, 230); 93 | font-family:Arial; 94 | } 95 | .form .link{ 96 | font-family: Arial, Helvetica, sans-serif; 97 | font-size: 16px; 98 | padding-top:18px; 99 | text-align: center; 100 | color:brown; 101 | 102 | } 103 | .liw{ 104 | font-family: Arial, Helvetica, sans-serif; 105 | font-size: 16px; 106 | padding-top:18px; 107 | text-align: center; 108 | color:brown; 109 | 110 | } 111 | 112 | .content{ 113 | width:1100px; 114 | height:auto; 115 | margin: auto; 116 | color:blanchedalmond; 117 | position:relative; 118 | background:scroll; 119 | 120 | } 121 | .content{ 122 | width:700px; 123 | height:auto; 124 | margin:auto; 125 | color:rgb(171, 255, 2); 126 | position:relative; 127 | 128 | } 129 | .content .par{ 130 | font-size:30px; 131 | padding-left: 18px; 132 | padding-bottom: 17px; 133 | font-family: 'Times New Roman', Times, serif; 134 | letter-spacing: 1.5px; 135 | 136 | } 137 | .content h1{ 138 | font-size: 55px; 139 | padding-left:55px; 140 | margin-top: 35%; 141 | letter-spacing: 1.8px; 142 | } 143 | .content .cn{ 144 | font-size:20px; 145 | width:150px; 146 | height:40px; 147 | background:rgb(171, 255, 2); 148 | 149 | } 150 | .content .cn a{ 151 | text-decoration: none; 152 | } 153 | 154 | .container{ 155 | float:right; 156 | margin-right: 100px; 157 | margin-top: 190px; 158 | 159 | } 160 | .container .btn{ 161 | font-size: 25px; 162 | background: rgba(95, 95, 95, 0.986); 163 | } 164 | .container .btn a{ 165 | text-decoration: none; 166 | color:aliceblue; 167 | } 168 | 169 | 170 | -------------------------------------------------------------------------------- /Web/loginpage/loginpage.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | LOGINFORM 7 | 8 | 9 | 10 | 11 |
12 | 17 |
18 | 23 | 24 |
25 |

Join with us and
Read books

26 |

We do have all kinds of books available .
Just enjoy the books free of cost.

27 | 28 | 29 |
30 | 31 |
32 |

LOGIN

33 |
34 | 35 |
36 |
37 | 38 |
39 | 40 | 42 |

Login with Gmail

43 | 44 |
45 |
46 | 47 | 48 |
49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /Web/skc group/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | SKC 11 | 12 | 13 | 17 |
18 |

SKC group is an team working together to build a platform of resources ,blogs, articles etc from people to 19 | people.

20 |

Writeups worth diving deep

21 | 22 |
23 |
24 |

Collection of blogs,ebooks and writeups to inspire you

25 |
26 |
27 |

Featured industries in this downloads

28 |
29 |
    30 |
  1. Agency & Studio
  2. 31 |
  3. Ecommerce & Retail
  4. 32 |
  5. Nonprofit
  6. 33 |
  7. Software & Tech
  8. 34 |
  9. Culture & Lifestyle
  10. 35 |
36 |
37 |

Feel free to download your genre of blogs

38 | 39 |
40 |
41 |

42 | Publish your passions, your way, 43 |
44 | Create a unique and beautiful blog and articles 45 |

46 |
47 |
48 |

Your email

49 |
50 | 51 |
52 |
53 |
54 | 55 |
56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /Web/skc group/style.css: -------------------------------------------------------------------------------- 1 | .logo { 2 | height: 250px; 3 | margin-left: 50px; 4 | 5 | } 6 | 7 | .btn { 8 | height: 50px; 9 | width: 180px; 10 | padding: 50px; 11 | margin: 10px; 12 | padding: 10px; 13 | font: style bold 1000%; 14 | color: rgb(121, 6, 235); 15 | } 16 | 17 | .text { 18 | font-family: sans-serif; 19 | text-align: left; 20 | color: rgb(133, 114, 178); 21 | } 22 | 23 | .abc { 24 | color: black; 25 | } 26 | 27 | .form { 28 | width: 220px; 29 | height: 130px; 30 | background-color: lightslategrey; 31 | border-radius: 10px; 32 | padding: 50px; 33 | margin-bottom: 20px; 34 | 35 | 36 | } 37 | 38 | .form h1 { 39 | width: 220px; 40 | font-family: sans-serif; 41 | text-align: center; 42 | color: rgb(239, 242, 247); 43 | font-size: 22px; 44 | margin: 2px; 45 | padding: 8px; 46 | 47 | } 48 | 49 | .form input { 50 | width: 240px; 51 | height: 34px; 52 | background: transparent; 53 | border-bottom: 1px, solid; 54 | border-top: none; 55 | border-right: none; 56 | border-left: none; 57 | color: rgb(8, 8, 8); 58 | font-size: 20px; 59 | margin-top: 25px; 60 | font-family: sans-serif; 61 | } 62 | 63 | 64 | 65 | ::placeholder { 66 | color: rgb(11, 9, 5); 67 | font-family: Arial; 68 | } -------------------------------------------------------------------------------- /Web/style1.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: 'Google Sans', 'Noto Sans Myanmar UI', arial, sans-serif; 3 | } 4 | 5 | img { 6 | max-width: 100px; 7 | max-height: 50px; 8 | } 9 | 10 | .maindiv { 11 | position: absolute; 12 | top: 50%; 13 | left: 50%; 14 | transform: translate(-50%, -50%); 15 | width: 350px; 16 | min-height: 400px; 17 | padding: 3rem; 18 | border-radius: 0.5rem; 19 | border: 1px solid #e1e1e1; 20 | text-align: center; 21 | } 22 | 23 | .maindiv .srm { 24 | display: inline-block; 25 | height: 90px; 26 | position: relative; 27 | } 28 | 29 | h1 { 30 | font-size: 24px; 31 | font-weight: 200px; 32 | } 33 | 34 | h3 { 35 | color: #202124; 36 | font-size: 16px; 37 | font-weight: 400; 38 | } 39 | 40 | input { 41 | outline: none; 42 | } 43 | 44 | .Before-FS { 45 | width: 344px; 46 | border: 1px solid #c2c2c2; 47 | border-radius: 3px; 48 | height: 28px; 49 | font-size: 16px; 50 | margin: 1px 1px 0 1px; 51 | padding: 13px 15px; 52 | transition: 0.1s; 53 | } 54 | 55 | .Before-FS:focus { 56 | border: 2px solid #1a73e8; 57 | border-top: 1px solid transparent; 58 | } 59 | 60 | .Fs-H { 61 | opacity: 0; 62 | transition: 0.2s; 63 | } 64 | 65 | .bhattu>h1 { 66 | font: 1em normal; 67 | margin: -5px 2.5px -8px; 68 | position: relative; 69 | top: -60px 70 | } 71 | 72 | .bhattu>h1>span { 73 | float: left; 74 | color: #1a73e8; 75 | font-family: 'Google Sans', 'Noto Sans Myanmar UI', 'arial', 'sans-serif'; 76 | font-size: 13px; 77 | } 78 | 79 | .bhattu>h1::before { 80 | border-top: 2px solid #1a73e8; 81 | content: ' '; 82 | float: left; 83 | margin: 0.5em 2px 0 -1px; 84 | width: 0.75em 85 | } 86 | 87 | .bhattu>h1::after { 88 | 89 | border-top: 2px solid #1a73e8; 90 | content: ' '; 91 | display: block; 92 | height: 1.5em; 93 | left: 2px; 94 | margin: 0 1px 0 0; 95 | overflow: hidden; 96 | position: relative; 97 | top: 0.5em; 98 | } 99 | 100 | .placeholder { 101 | position: absolute; 102 | left: 20px; 103 | top: 19px; 104 | color: #80868b; 105 | font-size: 16px; 106 | font-weight: 400; 107 | pointer-events: none; 108 | transition: 0.4s 109 | } 110 | 111 | input:focus~label.placeholder, 112 | input:valid~label.placeholder { 113 | top: 3px; 114 | font-size: 10px; 115 | opacity: 0; 116 | } 117 | 118 | input:focus+.Fs-H, 119 | input:valid+.Fs-H { 120 | opacity: 1; 121 | 122 | } 123 | 124 | button { 125 | cursor: pointer; 126 | border: 1px solid transparent; 127 | padding: 6px 12px; 128 | font-size: 14px; 129 | line-height: 1.42; 130 | color: white; 131 | border-radius: 4px; 132 | background-color: #1a73e8; 133 | outline: none; 134 | min-width: 88px; 135 | 136 | } -------------------------------------------------------------------------------- /c++/important programs/Hosoya traingle: -------------------------------------------------------------------------------- 1 | // CPP Program to print Hosoya's 2 | // triangle of height n. 3 | #include 4 | using namespace std; 5 | 6 | int Hosoya(int n, int m) 7 | { 8 | // Base case 9 | if ((n == 0 && m == 0) || 10 | (n == 1 && m == 0) || 11 | (n == 1 && m == 1) || 12 | (n == 2 && m == 1)) 13 | return 1; 14 | 15 | // Recursive step 16 | if (n > m) 17 | return Hosoya(n - 1, m) 18 | + Hosoya(n - 2, m); 19 | 20 | else if (m == n) 21 | return Hosoya(n - 1, m - 1) 22 | + Hosoya(n - 2, m - 2); 23 | 24 | else 25 | return 0; 26 | } 27 | 28 | // Print the Hosoya triangle of height n. 29 | void printHosoya(int n) 30 | { 31 | for (int i = 0; i < n; i++) { 32 | for (int j = 0; j <= i; j++) 33 | cout << Hosoya(i, j) << " "; 34 | 35 | cout << endl; 36 | } 37 | } 38 | 39 | // Driven Program 40 | int main() 41 | { 42 | int n = 5; 43 | printHosoya(n); 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /c++/important programs/Krukshal c++: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int i, j, k, a, b, u, v, n, ne = 1; 4 | int min, mincost = 0, cost[9][9], parent[9]; 5 | int find(int); 6 | int uni(int, int); 7 | void main() { 8 | printf("\nEnter the no. of vertices - "); 9 | scanf("%d", &n); 10 | printf("\nEnter the cost adjacency matrix - \n"); 11 | for (i = 1; i <= n; i++) { 12 | for (j = 1; j <= n; j++) { 13 | scanf("%d", &cost[i][j]); 14 | if (cost[i][j] == 0) 15 | cost[i][j] = 999; 16 | } 17 | } 18 | printf("The edges of Minimum Cost Spanning Tree are - \n"); 19 | while (ne < n) { 20 | for (i = 1, min = 999; i <= n; i++) { 21 | for (j = 1; j <= n; j++) { 22 | if (cost[i][j] < min) { 23 | min = cost[i][j]; 24 | a = u = i; 25 | b = v = j; 26 | } 27 | } 28 | } 29 | u = find(u); 30 | v = find(v); 31 | if (uni(u, v)) { 32 | printf("%d Edge (%d,%d) =%d\n", ne++, a, b, min); 33 | mincost += min; 34 | } 35 | cost[a][b] = cost[b][a] = 999; 36 | } 37 | printf("\n\tMinimum Cost - %d\n", mincost); 38 | } 39 | int find(int i) { 40 | while (parent[i]) 41 | i = parent[i]; 42 | return i; 43 | } 44 | int uni(int i, int j) { 45 | if (i != j) { 46 | parent[j] = i; 47 | return 1; 48 | } 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /c++/important programs/MyC++programs/Reverseanumber.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | 6 | int n, reversed_number = 0, remainder; 7 | 8 | cout << "Enter an integer: "; 9 | cin >> n; 10 | 11 | while(n != 0) { 12 | remainder = n % 10; 13 | reversed_number = reversed_number * 10 + remainder; 14 | n /= 10; 15 | } 16 | 17 | cout << "Reversed Number = " << reversed_number; 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /c++/important programs/MyC++programs/armstrong.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int num, originalNum, remainder, result = 0; 6 | cout << "Enter a three-digit integer: "; 7 | cin >> num; 8 | originalNum = num; 9 | 10 | while (originalNum != 0) { 11 | // remainder contains the last digit 12 | remainder = originalNum % 10; 13 | 14 | result += remainder * remainder * remainder; 15 | 16 | // removing last digit from the orignal number 17 | originalNum /= 10; 18 | } 19 | 20 | if (result == num) 21 | cout << num << " is an Armstrong number."; 22 | else 23 | cout << num << " is not an Armstrong number."; 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /c++/important programs/MyC++programs/factorialofnumber.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int n; 6 | long factorial = 1.0; 7 | 8 | cout << "Enter a positive integer: "; 9 | cin >> n; 10 | 11 | if (n < 0) 12 | cout << "Error! Factorial of a negative number doesn't exist."; 13 | else { 14 | for(int i = 1; i <= n; ++i) { 15 | factorial *= i; 16 | } 17 | cout << "Factorial of " << n << " = " << factorial; 18 | } 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /c++/important programs/MyC++programs/palindrome or not.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n, num, digit, rev = 0; 7 | 8 | cout << "Enter a positive number: "; 9 | cin >> num; 10 | 11 | n = num; 12 | 13 | do 14 | { 15 | digit = num % 10; 16 | rev = (rev * 10) + digit; 17 | num = num / 10; 18 | } while (num != 0); 19 | 20 | cout << " The reverse of the number is: " << rev << endl; 21 | 22 | if (n == rev) 23 | cout << " The number is a palindrome."; 24 | else 25 | cout << " The number is not a palindrome."; 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /c++/important programs/Painting_fence_algorithm.cpp: -------------------------------------------------------------------------------- 1 | //Painting fence algorithm 2 | #include 3 | using namespace std; 4 | //no of ways 5 | long count_Ways(int n, int k) 6 | { 7 | long dp[n + 1]; 8 | memset(dp, 0, sizeof(dp)); 9 | long long mod = 1000000007; 10 | 11 | dp[1] = k; 12 | dp[2] = k * k; 13 | 14 | for (int i = 3; i <= n; i++) { 15 | dp[i] = ((k - 1) * (dp[i - 1] + dp[i - 2])) % mod; 16 | } 17 | 18 | return dp[n]; 19 | } 20 | 21 | 22 | int main() 23 | { 24 | 25 | int n; 26 | cin>>n; 27 | int k; 28 | cin>>k; 29 | //n is the number of fences and k is the number of colors 30 | cout << count_Ways(n, k) << endl; 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /c++/important programs/bubble sort: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int n, i, arr[30], j, temp,flag; 6 | cout<<"Enter the Size (max. 30): "; 7 | cin>>n; 8 | cout<<"Enter "<>arr[i]; 11 | cout<<"\nSorting the Array using Bubble Sort \n"; 12 | for(i=0; i<(n-1); i++) 13 | { 14 | flag=0; 15 | 16 | for(j=0; j<(n-i-1); j++) 17 | { 18 | if(arr[j]>arr[j+1]) 19 | { 20 | temp = arr[j]; 21 | arr[j] = arr[j+1]; 22 | arr[j+1] = temp; 23 | flag=1; 24 | 25 | } 26 | } 27 | if(flag==0) 28 | { 29 | break; 30 | 31 | } 32 | } 33 | cout<<"\nThe Sorted Array is: \n"; 34 | for(i=0; i 2 | #include 3 | using namespace std; 4 | #define INFINITY 9999 5 | #define max 5 6 | void dijkstra(int G[max][max],int n,int startnode); 7 | int main() { 8 | int G[max][max]={{0,1,0,3,10},{1,0,5,0,0},{0,5,0,2,1},{3,0,2,0,6},{10,0,1,6,0}}; 9 | int n=5; 10 | int u=0; 11 | dijkstra(G,n,u); 12 | return 0; 13 | } 14 | void dijkstra(int G[max][max],int n,int startnode) { 15 | int cost[max][max],distance[max],pred[max]; 16 | int visited[max],count,mindistance,nextnode,i,j; 17 | for(i=0;i 2 | using namespace std; 3 | 4 | int main() { 5 | int n; 6 | 7 | cout << "Enter an integer: "; 8 | cin >> n; 9 | 10 | if ( n % 2 == 0) 11 | cout << n << " is even."; 12 | else 13 | cout << n << " is odd."; 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /c++/important programs/fcfs.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | using namespace std; 4 | 5 | // Function to find the waiting time for all 6 | // processes 7 | void findWaitingTime(int processes[], int n, 8 | int bt[], int wt[]) 9 | { 10 | // waiting time for first process is 0 11 | wt[0] = 0; 12 | 13 | // calculating waiting time 14 | for (int i = 1; i < n ; i++ ) 15 | wt[i] = bt[i-1] + wt[i-1] ; 16 | } 17 | 18 | // Function to calculate turn around time 19 | void findTurnAroundTime( int processes[], int n, 20 | int bt[], int wt[], int tat[]) 21 | { 22 | // calculating turnaround time by adding 23 | // bt[i] + wt[i] 24 | for (int i = 0; i < n ; i++) 25 | tat[i] = bt[i] + wt[i]; 26 | } 27 | 28 | //Function to calculate average time 29 | void findavgTime( int processes[], int n, int bt[]) 30 | { 31 | int wt[n], tat[n], total_wt = 0, total_tat = 0; 32 | 33 | //Function to find waiting time of all processes 34 | findWaitingTime(processes, n, bt, wt); 35 | 36 | //Function to find turn around time for all processes 37 | findTurnAroundTime(processes, n, bt, wt, tat); 38 | 39 | //Display processes along with all details 40 | cout << "Processes "<< " Burst time " 41 | << " Waiting time " << " Turn around time\n"; 42 | 43 | // Calculate total waiting time and total turn 44 | // around time 45 | for (int i=0; i>n; 71 | 72 | int arr[n]; 73 | for(i = 0; i < n; i++) 74 | { 75 | cout<<"Enter element "<>arr[i]; 77 | } 78 | 79 | QuickSort(arr, 0, n-1); 80 | 81 | // Printing the sorted data. 82 | cout<<"\nSorted Data "; 83 | for (i = 0; i < n; i++) 84 | cout<<"->"< 2 | using namespace std; 3 | 4 | int main() { 5 | 6 | int n, reversed_number = 0, remainder; 7 | 8 | cout << "Enter an integer: "; 9 | cin >> n; 10 | 11 | while(n != 0) { 12 | remainder = n % 10; 13 | reversed_number = reversed_number * 10 + remainder; 14 | n /= 10; 15 | } 16 | 17 | cout << "Reversed Number = " << reversed_number; 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /c++/important programs/sudoko: -------------------------------------------------------------------------------- 1 | #include 2 | #define N 9 3 | using namespace std; 4 | 5 | int grid[N][N] = { 6 | {6,5,0,8,7,3,0,9,0}, 7 | {0,0,3,2,5,0,0,0,8}, 8 | {9,8,0,1,0,4,3,5,7}, 9 | {1,0,5,0,0,0,0,0,0}, 10 | {4,0,0,0,0,0,0,0,2}, 11 | {0,0,0,0,0,0,5,0,3}, 12 | {5,7,8,3,0,1,0,2,6}, 13 | {2,0,0,0,4,8,9,0,0}, 14 | {0,9,0,6,2,5,0,8,1} 15 | }; 16 | 17 | 18 | 19 | 20 | bool isPresentInCol(int col, int num) { //check whether num is present in col or not 21 | 22 | for (int row = 0; row < N; row++) 23 | if (grid[row][col] == num) 24 | return true; 25 | 26 | return false; 27 | } 28 | 29 | 30 | 31 | bool isPresentInRow(int row, int num) { //check whether num is present in row or not 32 | 33 | for (int col = 0; col < N; col++) 34 | if (grid[row][col] == num) 35 | return true; 36 | return false; 37 | } 38 | 39 | 40 | 41 | bool isPresentInBox(int boxStartRow, int boxStartCol, int num) { //check whether num is present in 3x3 box or not 42 | 43 | for (int row = 0; row < 3; row++) 44 | for (int col = 0; col < 3; col++) 45 | if (grid[row+boxStartRow][col+boxStartCol] == num) 46 | return true; 47 | return false; 48 | } 49 | 50 | 51 | 52 | void sudokuGrid() { //print the sudoku grid after solve 53 | 54 | vector> vec; 55 | for (int row = 0; row < N; row++) { 56 | //cout<<"[ "; 57 | 58 | for (int col = 0; col < N; col++) { 59 | vector temp_vec; 60 | temp_vec.insert(col, grid[row][col]); 61 | 62 | //cout << grid[row][col] <<" "; 63 | } 64 | vec.insert(row, temp_vec); 65 | //cout<<"]"< 110*/ 7 | 8 | #include 9 | using namespace std; 10 | 11 | 12 | int unboundedKnapsack(int W, int n, 13 | int val[], int wt[]) 14 | { 15 | 16 | int dp[W+1]; 17 | memset(dp, 0, sizeof dp); 18 | 19 | 20 | for (int i=0; i<=W; i++) 21 | for (int j=0; j>n; 32 | int val[n]; 33 | int wt[n]; 34 | for(int i=0;i>val[i]; 37 | } 38 | for(int i=0;i>wt[i]; 41 | } 42 | 43 | int W; 44 | cin>>W; 45 | cout << unboundedKnapsack(W, n, val, wt); 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /c++/important programs/usefulprograms/GCD.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int n1, n2, hcf; 6 | cout << "Enter two numbers: "; 7 | cin >> n1 >> n2; 8 | 9 | // swapping variables n1 and n2 if n2 is greater than n1. 10 | if ( n2 > n1) { 11 | int temp = n2; 12 | n2 = n1; 13 | n1 = temp; 14 | } 15 | 16 | for (int i = 1; i <= n2; ++i) { 17 | if (n1 % i == 0 && n2 % i ==0) { 18 | hcf = i; 19 | } 20 | } 21 | 22 | cout << "HCF = " << hcf; 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /c++/important programs/usefulprograms/LCM.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int n1, n2, max_num, flag = 1; 6 | cout << " Enter two numbers: \n"; 7 | cin >> n1 >> n2; 8 | 9 | // use ternary operator to get the large number 10 | max_num = (n1 > n2) ? n1 : n2; 11 | 12 | while (flag) 13 | { 14 | // if statement checks max_num is completely divisible by n1 and n2. 15 | if(max_num % n1 == 0 && max_num % n2 == 0) 16 | { 17 | cout << " The LCM of " < 2 | using namespace std; 3 | 4 | int main() { 5 | 6 | int i, n; 7 | float arr[100]; 8 | 9 | cout << "Enter total number of elements(1 to 100): "; 10 | cin >> n; 11 | cout << endl; 12 | 13 | // Store number entered by the user 14 | for(i = 0; i < n; ++i) { 15 | cout << "Enter Number " << i + 1 << " : "; 16 | cin >> arr[i]; 17 | } 18 | 19 | // Loop to store largest number to arr[0] 20 | for(i = 1;i < n; ++i) { 21 | 22 | // Change < to > if you want to find the smallest element 23 | if(arr[0] < arr[i]) 24 | arr[0] = arr[i]; 25 | } 26 | 27 | cout << endl << "Largest element = " << arr[0]; 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /c++/important programs/usefulprograms/matrixaddition.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int r, c, a[100][100], b[100][100], sum[100][100], i, j; 7 | 8 | cout << "Enter number of rows (between 1 and 100): "; 9 | cin >> r; 10 | 11 | cout << "Enter number of columns (between 1 and 100): "; 12 | cin >> c; 13 | 14 | cout << endl << "Enter elements of 1st matrix: " << endl; 15 | 16 | // Storing elements of first matrix entered by user. 17 | for(i = 0; i < r; ++i) 18 | for(j = 0; j < c; ++j) 19 | { 20 | cout << "Enter element a" << i + 1 << j + 1 << " : "; 21 | cin >> a[i][j]; 22 | } 23 | 24 | // Storing elements of second matrix entered by user. 25 | cout << endl << "Enter elements of 2nd matrix: " << endl; 26 | for(i = 0; i < r; ++i) 27 | for(j = 0; j < c; ++j) 28 | { 29 | cout << "Enter element b" << i + 1 << j + 1 << " : "; 30 | cin >> b[i][j]; 31 | } 32 | 33 | // Adding Two matrices 34 | for(i = 0; i < r; ++i) 35 | for(j = 0; j < c; ++j) 36 | sum[i][j] = a[i][j] + b[i][j]; 37 | 38 | // Displaying the resultant sum matrix. 39 | cout << endl << "Sum of two matrix is: " << endl; 40 | for(i = 0; i < r; ++i) 41 | for(j = 0; j < c; ++j) 42 | { 43 | cout << sum[i][j] << " "; 44 | if(j == c - 1) 45 | cout << endl; 46 | } 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /c++/important programs/usefulprograms/towerofhanoi.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | //tower of HANOI function implementation 5 | void TOH(int n,char Sour, char Aux,char Des) 6 | { 7 | if(n==1) 8 | { 9 | cout<<"Move Disk "<>n; 25 | //calling the TOH 26 | TOH(n,'A','B','C'); 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /python/CardGame.py: -------------------------------------------------------------------------------- 1 | @@ -0,0 +1,145 @@ 2 | # import the required libraries.... 3 | # for this project we need only "random" library only 4 | import random 5 | 6 | # create the set of cards... 7 | # here, if you want to make a single list, it will also work fine(but you might need to change some funtions) 8 | # no. of element in suits = 4 9 | # no. of element in ranks = 13 10 | # total cards are 4*13 = 52 11 | suits = ('Hearts','Diamond','spades','Clubs') 12 | ranks = ('Two','Three','Four','Five','Six','Seven','Eight','Nine','Ten','Jack','Queen','King','Ace') 13 | values = {'Two':2,'Three':3,'Four':4,'Five':5,'Six':6,'Seven':7,'Eight':8,'Nine':9,'Ten':10,'Jack':11,'Queen':12,'King':13,'Ace':14} 14 | 15 | # now generate the cards 16 | # you can view the card by printing them 17 | class Card: 18 | 19 | def __init__(self,suit,rank): 20 | 21 | self.suit = suit 22 | self.rank = rank 23 | self.value = values[rank] 24 | 25 | def __str__(self): 26 | return self.rank + 'of' + self.suit 27 | 28 | # now this class make decks for the players and it has member functions like shuffle and deal_one 29 | # to increase its functionality 30 | class Deck: 31 | 32 | def __init__(self): 33 | self.all_cards = [] 34 | for suit in suits: 35 | for rank in ranks: 36 | self.all_cards.append(Card(suit,rank)) 37 | 38 | def shuffle(self): 39 | 40 | random.shuffle(self.all_cards) 41 | 42 | def deal_one(self): 43 | 44 | return self.all_cards.pop() 45 | 46 | # this class makes the players and assign them functions that they can perform 47 | class Player: 48 | 49 | def __init__(self,name): 50 | self.name = name 51 | self.all_cards = [] 52 | 53 | def remove_one(self): 54 | return self.all_cards.pop(0) 55 | 56 | def add_cards(self,new_cards): 57 | if type(new_cards)==type([]): 58 | self.all_cards.extend(new_cards) 59 | else: 60 | self.all_cards.append(new_cards) 61 | 62 | def __str__(self): 63 | return f'Player {self.name} has {[len(self.all_cards)]} cards.' 64 | 65 | # making two players 66 | player_one = Player('One') 67 | player_two = Player('Two') 68 | 69 | # genterating decks and suffling the cards in it 70 | new_deck = Deck() 71 | new_deck.shuffle() 72 | 73 | # assigning the cards to the players 74 | for i in range(26): 75 | player_one.add_cards(new_deck.deal_one()) 76 | player_two.add_cards(new_deck.deal_one()) 77 | 78 | # this acts as the switch for the game to tune on and off 79 | game_on = True 80 | 81 | # main logic of the game 82 | round_num = 0 83 | while game_on: 84 | 85 | round_num +=1 86 | print(f'Round {round_num}') 87 | 88 | if len(player_one.all_cards) == 0: 89 | print('Player One out of cards! Game over') 90 | print('Player Two Wins!') 91 | game_on = False 92 | break 93 | 94 | if len(player_two.all_cards) == 0: 95 | print('Player Two out of cards! Game Over') 96 | print('Player One Wins!') 97 | game_on = False 98 | break 99 | 100 | 101 | player_one_cards = [] 102 | player_one_cards.append(player_one.remove_one()) 103 | 104 | player_two_cards = [] 105 | player_two_cards.append(player_two.remove_one()) 106 | 107 | at_war = True 108 | 109 | while at_war: 110 | 111 | if player_one_cards[-1].value > player_two_cards[-1].value: 112 | 113 | player_one.add_cards(player_one_cards) 114 | player_one.add_cards(player_two_cards) 115 | 116 | at_war = False 117 | 118 | elif player_one_cards[-1].value < player_two_cards[-1].value: 119 | 120 | player_two.add_cards(player_two_cards) 121 | player_two.add_cards(player_one_cards) 122 | 123 | at_war = False 124 | 125 | else: 126 | 127 | print('WAR!') 128 | 129 | if len(player_one.all_cards)<5: 130 | 131 | print('Player One unable to play war! Game Over at War') 132 | print('PLayer Two Wins! Player One Loses!') 133 | game_on = False 134 | 135 | elif len(player_two.all_cards)<5: 136 | 137 | print('Player Two unable to play war! Over at War') 138 | print('Player One Wins! Player Two Loses') 139 | game_on = False 140 | break 141 | 142 | else: 143 | for num in range(5): 144 | player_one_cards.append(player_one.remove_one()) 145 | player_two_cards.append(player_two.remove_one()) 146 | -------------------------------------------------------------------------------- /python/bubble_sort.py: -------------------------------------------------------------------------------- 1 | # Python program for implementation of Bubble Sort 2 | 3 | def bubbleSort(arr): 4 | n = len(arr) 5 | # optimize code, so if the array is already sorted, it doesn't need 6 | # to go through the entire process 7 | swapped = False 8 | # Traverse through all array elements 9 | for i in range(n-1): 10 | # range(n) also work but outer loop will 11 | # repeat one time more than needed. 12 | # Last i elements are already in place 13 | for j in range(0, n-i-1): 14 | 15 | # traverse the array from 0 to n-i-1 16 | # Swap if the element found is greater 17 | # than the next element 18 | if arr[j] > arr[j + 1]: 19 | swapped = True 20 | arr[j], arr[j + 1] = arr[j + 1], arr[j] 21 | 22 | if not swapped: 23 | # if we haven't needed to make a single swap, we 24 | # can just exit the main loop. 25 | return 26 | 27 | 28 | # Driver code to test above 29 | arr = [64, 34, 25, 12, 22, 11, 90] 30 | 31 | bubbleSort(arr) 32 | 33 | print("Sorted array is:") 34 | for i in range(len(arr)): 35 | print("% d" % arr[i], end=" ") 36 | -------------------------------------------------------------------------------- /python/circular_queue.py: -------------------------------------------------------------------------------- 1 | @@ -0,0 +1,74 @@ 2 | class CircularQueue: 3 | def __init__(self, size): 4 | self.size = size 5 | self.cqueue = [None] * self.size 6 | self.front = -1 7 | self.rear = -1 8 | 9 | def isFull(self): 10 | return (self.rear) % self.size == self.front and (self.cqueue.count(None) == 0) 11 | 12 | def isEmpty(self): 13 | return self.cqueue.count(None) == self.size 14 | 15 | def enqueue(self, item): 16 | if self.isFull(): 17 | print("Queue is Full") 18 | return 19 | elif self.isEmpty(): 20 | self.front = self.rear = 0 21 | 22 | self.cqueue[self.rear] = item 23 | self.rear = (self.rear + 1) % self.size 24 | 25 | def dequeue(self): 26 | if self.isEmpty(): 27 | print("Queue is empty") 28 | return 29 | print("Dequeued element is", self.cqueue[self.front]) 30 | self.cqueue[self.front] = None 31 | self.front = (self.front + 1) % self.size 32 | 33 | def display(self): 34 | print(self.cqueue) 35 | 36 | cq = CircularQueue(5) 37 | 38 | while True: 39 | print("\n1. Insert") 40 | print("2. Delete") 41 | print("3. Display") 42 | print("4. Exit") 43 | choice = int(input("Enter your choice: ")) 44 | if choice == 1: 45 | data = int(input("Enter the data: ")) 46 | cq.enqueue(data) 47 | elif choice == 2: 48 | cq.dequeue() 49 | elif choice == 3: 50 | cq.display() 51 | elif choice == 4: 52 | break 53 | 54 | # cq = CircularQueue(5) 55 | 56 | # cq.enqueue(1) 57 | # cq.enqueue(2) 58 | # cq.enqueue(3) 59 | # cq.enqueue(4) 60 | # cq.enqueue(5) 61 | # cq.enqueue(6) 62 | 63 | # cq.display() 64 | 65 | # cq.dequeue() 66 | # cq.dequeue() 67 | # cq.display() 68 | # cq.enqueue(10) 69 | # cq.enqueue(11) 70 | # cq.dequeue() 71 | 72 | # cq.display() 73 | 74 | # cq.enqueue(13) 75 | # cq.display() 76 | -------------------------------------------------------------------------------- /python/lcs.py: -------------------------------------------------------------------------------- 1 | ''' Longest Common Subsequence ''' 2 | 3 | ''' 4 | 5 | Example 6 | str1 = "abc" 7 | str2 = "bcd" 8 | 9 | ans = 2 = "bc" 10 | 11 | ''' 12 | #Using Memorization 13 | def fibb1(s1,s2,i,j,dp): 14 | if i<0 or j<0 : 15 | return 0 16 | if dp[i][j] != -1: 17 | return dp[i][j] 18 | if s1[i] == s2[j]: 19 | dp[i][j] = 1 + fibb1(s1,s2,i-1,j-1,dp) 20 | else: 21 | dp[i][j] = 0 + fibb1(s1,s2,i-1,j,dp), fibb1(s1,s2,i,j-1,dp)) 22 | 23 | return dp[i][j] 24 | 25 | 26 | #Using Tabulation 27 | def fibb2(s1,s2): 28 | n = len(s1) 29 | m = len(s2) 30 | 31 | dp = [[0 for _ in range(m+1)] for _ in range(n+1)] 32 | for i in range(1,n+1): 33 | for j in range(1,m+1): 34 | if s1[i-1] == s2[j-1]: 35 | dp[i][j] = 1 + dp[i-1][j-1] 36 | else: 37 | dp[i][j] = max(dp[i-1][j], dp[i][j-1]) 38 | 39 | return dp[n][m] 40 | 41 | 42 | if __name__ == "__main__": 43 | s1 = "abc" 44 | s2 = "bcd" 45 | n = len(s1) 46 | m = len(s2) 47 | dp = [[-1 for _ in range(m)] for _ in range(n)] 48 | ansmemo = fibb1(s1,s2,n-1,m-1,dp) 49 | print(ansmemo) 50 | 51 | anstab = fibb2(s1,s2) 52 | print(anstab) 53 | 54 | -------------------------------------------------------------------------------- /python/merge_sort.py: -------------------------------------------------------------------------------- 1 | # Python implementation of MergeSort 2 | 3 | # Merges two subarrays. 4 | # First subarray is arr[l..m] 5 | # Second subarray is arr[m+1..r] 6 | 7 | 8 | def merge(arr, l, m, r): 9 | n1 = m - l + 1 10 | n2 = r - m 11 | 12 | # create temp arrays 13 | L = [0] * (n1) 14 | R = [0] * (n2) 15 | 16 | # Copy data to temp arrays L[] and R[] 17 | for i in range(0, n1): 18 | L[i] = arr[l + i] 19 | 20 | for j in range(0, n2): 21 | R[j] = arr[m + 1 + j] 22 | 23 | # Merge the temp arrays back into arr[l..r] 24 | i = 0 # Initial index of first subarray of given array 25 | j = 0 # Initial index of second subarray of given array 26 | k = l # Initial index of merged subarray of given array 27 | 28 | while i < n1 and j < n2: 29 | if L[i] <= R[j]: 30 | arr[k] = L[i] 31 | i += 1 32 | else: 33 | arr[k] = R[j] 34 | j += 1 35 | k += 1 36 | 37 | # Copy the remaining elements of L[], if there 38 | # are any 39 | while i < n1: 40 | arr[k] = L[i] 41 | i += 1 42 | k += 1 43 | 44 | # Copy the remaining elements of R[], if there 45 | # are any 46 | while j < n2: 47 | arr[k] = R[j] 48 | j += 1 49 | k += 1 50 | 51 | # l is for left index and r is right index of the 52 | # sub-array of arr to be sorted 53 | 54 | 55 | def mergeSort(arr, l, r): 56 | if l < r: 57 | 58 | # Same as (l+r)//2, but avoids overflow for 59 | # large l and h 60 | m = l+(r-l)//2 61 | 62 | # Sort first and second halves 63 | mergeSort(arr, l, m) 64 | mergeSort(arr, m+1, r) 65 | merge(arr, l, m, r) 66 | 67 | 68 | # Driver code to test the above 69 | arr = [12, 11, 13, 5, 6, 7] 70 | n = len(arr) 71 | print("Given array is") 72 | for i in range(n): 73 | print("%d" % arr[i],end=" ") 74 | 75 | mergeSort(arr, 0, n-1) 76 | print("\n\nSorted array is") 77 | for i in range(n): 78 | print("%d" % arr[i],end=" ") 79 | --------------------------------------------------------------------------------