├── .gitignore ├── Ad dispenser server ├── README.md ├── index.php ├── script.js └── style.css ├── CONTRIBUTING.md ├── E-Commerce Website ├── README.md ├── index.php ├── script.js └── style.css ├── Facebook Application Development ├── README.md ├── index.php ├── script.js └── style.css ├── Image Processing and Generation ├── README.md ├── index.php ├── script.js └── style.css ├── LICENSE ├── Online Blood Bank ├── README.md ├── index.php ├── script.js └── style.css ├── Online Shopping Project ├── README.md ├── index.php ├── script.js └── style.css ├── Online Voting System ├── README.md ├── index.php ├── script.js └── style.css ├── Predictive Model for Customer Behavior ├── README.md ├── index.php ├── script.js └── style.css ├── README.md ├── Rating system ├── README.md ├── index.php ├── script.js └── style.css ├── Social Networking Website └── README.md ├── WordPress Plugins ├── README.md ├── index.php ├── script.js └── style.css ├── automatic time table creation ├── README.md ├── index.php ├── script.js └── style.css ├── c# └── hello.cs ├── c ├── Calculator.c ├── Circumference.c ├── Cscan.c ├── Disk_cscan.c ├── Disk_fcfs.c ├── Disk_scan.c ├── DoctorsAppointment.c ├── FIFOpage.c ├── Fcfsdisk.c ├── Greatestnumber.c ├── Heab_sort.c ├── LFUpage.c ├── LRUpage.c ├── Link.c ├── Power_using_function.c ├── Prime.c ├── Prod_Cons.c ├── Recursive.c ├── Scandisk.c ├── Seq.c ├── SimpleInterest.c ├── SpecialNumber.c ├── Sum upto N ├── UppercaseLowercase.c ├── bankers.c ├── bestfit.c ├── bogo_sort.c ├── circularqueue.c ├── firstfit.c ├── heap_sort.c ├── infix_postfix.c ├── is_odd.c ├── merge_sort.c ├── number.c ├── pagereplacementLRU.c ├── paging.c ├── palindrome.c ├── poli_mul.c ├── poly_add.c ├── postfix.c ├── postfix_val.c ├── power2_mod.c ├── queue_array.c ├── queue_linkedlist.c ├── quicksort.c ├── stack_linkedlist.c ├── string_conversion.c ├── swap_with_pointer.c └── worstfit.c ├── chatbot ├── README.md ├── index.php ├── script.js └── style.css ├── clothes recommendation system ├── README.md ├── index.php ├── script.js └── style.css ├── cpp ├── BasicCalculator.cpp ├── Counting.cpp ├── DoctorsAppointment.cpp ├── Fibonacci.cpp ├── Fibonacci_Triangle.cpp ├── Krushkal.cpp ├── LexicographicalNumbers.cpp ├── Linearsearch. cpp ├── Mirror.cpp ├── N_Queen.cpp ├── Nodes without siblings.cpp ├── PostOrder binary tree.cpp ├── PreOrder binary tree.cpp ├── Print level wise.cpp ├── Quick_Sort.cpp ├── Remove leaf node.cpp ├── Seive.cpp ├── Sum of nodes.cpp ├── binarysearch.cpp ├── binarytodecimal.cpp ├── decimaltobinary.cpp ├── diameterOfATree.cpp ├── largest_numbers.cpp ├── lcm_hcf.cpp ├── maxDepthofATree.cpp ├── merge_sort.cpp ├── middleOfLinkedList.cpp ├── minStack.cpp ├── n-meetings-in-one-room.cpp ├── palindromicLinkedlist.cpp ├── postfixevaluation.cpp ├── powerOf4.cpp ├── prims algo.cpp ├── queue_Insertion_deletion.cpp ├── radix-sort.cpp ├── sqrt.cpp ├── stackFuntion.cpp ├── tictactoe.cpp ├── toposort using bfs.cpp ├── uniquePathInAGrid.cpp └── word_length.cpp ├── dart └── hello.dart ├── data_structure ├── Insertion.cpp ├── Mergesort.c ├── Qsort_recursive.c ├── heap_sort.c ├── linkedlist.c ├── poly_add_ll.c ├── poly_multi_ll.c ├── postfix_eval.c ├── postfixevaln.c ├── queue_array.c ├── quicksort.cpp ├── stack_array.c └── stackll.c ├── decimal_to_binary.cpp ├── go └── helloworld.go ├── java ├── Anagram.java ├── BucketSort.java ├── Check.java ├── DFS.java ├── Details of students ├── Employees.java ├── FibonacciSeries.java ├── InsertionSortExample.java ├── Linked_list.java ├── MergeSort.java ├── OTPGenerator.java ├── OddOrEven.java ├── Shortest Path.java ├── Sides.java ├── Sieve of Eratosthenes.java ├── SpecialNum.java ├── StringToInt.java ├── Sum.java ├── Test.java ├── Tictactoe (2).java ├── Trafficlight.java ├── area_shapes.java ├── armstrong.java ├── banking.java ├── binary search.java ├── calculator.java ├── createdatabase_table.java ├── doublyll.java ├── factandsum.java ├── factors.java ├── file1.java ├── garbage.java ├── hello_world.java ├── implement a Binary Search Algorithm ├── key.java ├── linkedlist.java ├── mouse.java ├── multiplymatrix.java ├── multithread.java ├── odd_even_thread.java ├── pallindrome.java ├── perimeter_shapes.java ├── prime.java ├── quicksort.java ├── record.java ├── replace.java ├── replacearr.java ├── shapesides.java ├── square_cube.java ├── square_cube_thread.java ├── thread_oddeven.java ├── transpose.java └── waveprint.java ├── javascript ├── Celsiustofahrenheit.js ├── Countdown Timer.js ├── Largest.js ├── Remove All Whitespaces From a Text.js ├── Remove Duplicate Items using arry.js ├── To-Do-List.js ├── Triangle.js ├── convert date to number.js ├── dectobin.js ├── factorial.js ├── intbtw2values.js ├── quad.js └── sumbyrecursion.js ├── kotlin └── hello.kt ├── movie recomm ├── README.md ├── index.php ├── script.js └── style.css ├── musicplayer ├── README.md ├── index.php ├── script.js └── style.css ├── portal for docs ├── README.md ├── index.php ├── script.js └── style.css ├── python ├── Calculator.py ├── Check.py ├── Clear-Rightmost-SetBitNumber.py ├── Compute-Polynomial Equation.py ├── Count-SetBits.py ├── Count_Sort.py ├── Dijkstra-Algorithm.py ├── Heap_Sort.py ├── Huffman_Algorithm.py ├── Infix_Postfix.py ├── Jumbled-Word_Quiz.py ├── Knight_Walk.py ├── List.py ├── Possible-Combinations_Three Digits.py ├── Read-Contents_ofFile.py ├── Stock Profit.py ├── StringPal.py ├── age.py ├── bluecircle10.py ├── currenttime finder.py ├── datesort.py ├── dice_game.py ├── guessmynumber.py ├── longestCommomPrefix.py ├── mostoccuring.py ├── palindromeLinkedList.py ├── panda program.py ├── pattern.py ├── pattern1.py ├── ponggame.py ├── powers of 2.py ├── pythonquiz.py ├── readfilewordbyword.py ├── reverseString.py ├── romanToInteger.py ├── snake.py ├── snake_apple.py ├── snakehungry.py └── twosum.py ├── restorent ├── README.md ├── Script.js ├── index.html └── style.css ├── ruby └── hello.rb ├── rust └── hello.rs ├── servey form ├── README.md ├── form.css └── index.html ├── static-portfolio-templates ├── README.md └── akku_portfolio │ ├── index.html │ └── static │ ├── css │ └── style.css │ └── photos │ ├── github.png │ ├── intro.png │ ├── portfolio-01.jpg │ ├── portfolio-02.jpg │ └── portfolio-03.jpg ├── swift └── helloworld.swift ├── toposort_by_bfs.cpp └── watherforcast ├── README.md ├── index.html ├── script.js └── style.css /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # For c 3 | *.exe 4 | *.out 5 | *.app 6 | *.o 7 | *.ko 8 | *.obj 9 | *.elf 10 | 11 | 12 | 13 | # For python 14 | # Environments 15 | .env 16 | .venv 17 | env/ 18 | venv/ 19 | ENV/ 20 | env.bak/ 21 | venv.bak/ 22 | 23 | 24 | # For VSC 25 | .vscode/* 26 | .history/ 27 | *.code-workspace 28 | 29 | 30 | # For java 31 | *.class 32 | 33 | # Log file 34 | *.log 35 | 36 | # BlueJ files 37 | *.ctxt 38 | 39 | # Package Files 40 | *.jar 41 | *.war 42 | *.nar 43 | *.ear 44 | *.zip 45 | *.tar.gz 46 | *.rar -------------------------------------------------------------------------------- /Ad dispenser server/index.php: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/Ad dispenser server/index.php -------------------------------------------------------------------------------- /Ad dispenser server/script.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/Ad dispenser server/script.js -------------------------------------------------------------------------------- /Ad dispenser server/style.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/Ad dispenser server/style.css -------------------------------------------------------------------------------- /E-Commerce Website/index.php: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/E-Commerce Website/index.php -------------------------------------------------------------------------------- /E-Commerce Website/script.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/E-Commerce Website/script.js -------------------------------------------------------------------------------- /E-Commerce Website/style.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/E-Commerce Website/style.css -------------------------------------------------------------------------------- /Facebook Application Development/index.php: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/Facebook Application Development/index.php -------------------------------------------------------------------------------- /Facebook Application Development/script.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/Facebook Application Development/script.js -------------------------------------------------------------------------------- /Facebook Application Development/style.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/Facebook Application Development/style.css -------------------------------------------------------------------------------- /Image Processing and Generation/index.php: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/Image Processing and Generation/index.php -------------------------------------------------------------------------------- /Image Processing and Generation/script.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/Image Processing and Generation/script.js -------------------------------------------------------------------------------- /Image Processing and Generation/style.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/Image Processing and Generation/style.css -------------------------------------------------------------------------------- /Online Blood Bank/index.php: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/Online Blood Bank/index.php -------------------------------------------------------------------------------- /Online Blood Bank/script.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/Online Blood Bank/script.js -------------------------------------------------------------------------------- /Online Blood Bank/style.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/Online Blood Bank/style.css -------------------------------------------------------------------------------- /Online Shopping Project/index.php: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/Online Shopping Project/index.php -------------------------------------------------------------------------------- /Online Shopping Project/script.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/Online Shopping Project/script.js -------------------------------------------------------------------------------- /Online Shopping Project/style.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/Online Shopping Project/style.css -------------------------------------------------------------------------------- /Online Voting System/index.php: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/Online Voting System/index.php -------------------------------------------------------------------------------- /Online Voting System/script.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/Online Voting System/script.js -------------------------------------------------------------------------------- /Online Voting System/style.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/Online Voting System/style.css -------------------------------------------------------------------------------- /Predictive Model for Customer Behavior/index.php: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/Predictive Model for Customer Behavior/index.php -------------------------------------------------------------------------------- /Predictive Model for Customer Behavior/script.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/Predictive Model for Customer Behavior/script.js -------------------------------------------------------------------------------- /Predictive Model for Customer Behavior/style.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/Predictive Model for Customer Behavior/style.css -------------------------------------------------------------------------------- /Rating system/index.php: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/Rating system/index.php -------------------------------------------------------------------------------- /Rating system/script.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/Rating system/script.js -------------------------------------------------------------------------------- /Rating system/style.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/Rating system/style.css -------------------------------------------------------------------------------- /WordPress Plugins/index.php: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/WordPress Plugins/index.php -------------------------------------------------------------------------------- /WordPress Plugins/script.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/WordPress Plugins/script.js -------------------------------------------------------------------------------- /WordPress Plugins/style.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/WordPress Plugins/style.css -------------------------------------------------------------------------------- /automatic time table creation/index.php: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/automatic time table creation/index.php -------------------------------------------------------------------------------- /automatic time table creation/script.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/automatic time table creation/script.js -------------------------------------------------------------------------------- /automatic time table creation/style.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/automatic time table creation/style.css -------------------------------------------------------------------------------- /c#/hello.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace HelloWorld 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | Console.WriteLine("Hello World!"); 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /c/Calculator.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | double num1, num2; 6 | char opr; 7 | char choice; 8 | 9 | while (true) 10 | { 11 | printf("Enter first number: "); 12 | scanf("%lf", &num1); 13 | 14 | printf("Enter second number: "); 15 | scanf("%lf", &num2); 16 | 17 | printf("Enter an operator (+, -, *, /): "); 18 | scanf(" %c", &opr); 19 | printf("\n"); 20 | 21 | switch (opr) 22 | { 23 | case '+': 24 | printf("%.2lf + %.2lf = %.2lf", num1, num2, num1 + num2); 25 | break; 26 | case '-': 27 | printf("%.2lf - %.2lf = %.2lf", num1, num2, num1 - num2); 28 | break; 29 | case '*': 30 | printf("%.2lf * %.2lf = %.2lf", num1, num2, num1 * num2); 31 | break; 32 | case '/': 33 | if (num2 != 0) 34 | printf("%.2lf / %.2lf = %.2lf", num1, num2, num1 / num2); 35 | else 36 | printf("Error: Division by zero!"); 37 | break; 38 | default: 39 | printf("Error: Invalid operator!"); 40 | } 41 | 42 | printf("\n\nEnter 'c' to continue, Enter 'q' to exit\n"); 43 | scanf(" %c", &choice); 44 | if (choice == 'q') 45 | { 46 | break; 47 | } 48 | } 49 | 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /c/Circumference.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | 5 | int radius; 6 | 7 | float circumferance; 8 | 9 | 10 | printf("enter radius\n"); 11 | 12 | scanf("%d", &radius); 13 | 14 | circumferance = 2*3.14*radius; 15 | 16 | printf("circumferance is %f", circumferance); 17 | 18 | 19 | 20 | 21 | 22 | return 0; 23 | 24 | } 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /c/Disk_cscan.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | int main() 6 | { 7 | int RQ[100],i,j,n,TotalHeadMoment=0,initial,size,move; 8 | printf("Enter the number of Requests\n"); 9 | scanf("%d",&n); 10 | printf("Enter the Requests sequence\n"); 11 | for(i=0;iRQ[j+1]) 26 | { 27 | int temp; 28 | temp=RQ[j]; 29 | RQ[j]=RQ[j+1]; 30 | RQ[j+1]=temp; 31 | } 32 | 33 | } 34 | } 35 | 36 | int index; 37 | for(i=0;i=0;i--) 70 | { 71 | TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial); 72 | initial=RQ[i]; 73 | } 74 | 75 | TotalHeadMoment=TotalHeadMoment+abs(RQ[i+1]-0); 76 | 77 | TotalHeadMoment=TotalHeadMoment+abs(size-1-0); 78 | initial =size-1; 79 | for(i=n-1;i>=index;i--) 80 | { 81 | TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial); 82 | initial=RQ[i]; 83 | 84 | } 85 | } 86 | 87 | printf("Total head movement is %d",TotalHeadMoment); 88 | return 0; 89 | } 90 | -------------------------------------------------------------------------------- /c/Disk_fcfs.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | 7 | int RQ[100],i,n,TotalHeadMoment=0,initial; 8 | printf("Enter the number of Requests\n"); 9 | scanf("%d",&n); 10 | printf("Enter the Requests sequence\n"); 11 | for(i=0;i 2 | #include 3 | 4 | int main() 5 | { 6 | 7 | int RQ[100],i,j,n,TotalHeadMoment=0,initial,size,move; 8 | printf("Enter the number of Requests\n"); 9 | scanf("%d",&n); 10 | printf("Enter the Requests sequence\n"); 11 | for(i=0;iRQ[j+1]) 26 | { 27 | int temp; 28 | temp=RQ[j]; 29 | RQ[j]=RQ[j+1]; 30 | RQ[j+1]=temp; 31 | } 32 | 33 | } 34 | } 35 | 36 | int index; 37 | for(i=0;i=0;i--) 58 | { 59 | TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial); 60 | initial=RQ[i]; 61 | 62 | } 63 | } 64 | 65 | else 66 | { 67 | for(i=index-1;i>=0;i--) 68 | { 69 | TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial); 70 | initial=RQ[i]; 71 | } 72 | 73 | TotalHeadMoment=TotalHeadMoment+abs(RQ[i+1]-0); 74 | initial =0; 75 | for(i=index;i 2 | int main() 3 | { 4 | int i,j,pf=0,f=0,np,nf,c,k; 5 | printf("enter the no. of pages: "); 6 | scanf("%d",&np); 7 | int ap[np]; 8 | printf("enter the page numbers: \n"); 9 | for ( i = 0; i < np; i++) 10 | { 11 | scanf("%d",&ap[i]); 12 | } 13 | 14 | printf("enter the no. of frames: "); 15 | scanf("%d",&nf); 16 | int af[nf]; 17 | printf("enter the page numbers: \n"); 18 | for ( i = 0; i < nf; i++) 19 | { 20 | af[i]=-1; 21 | } 22 | 23 | 24 | 25 | for ( i = 0; i 2 | 3 | int main() 4 | 5 | { 6 | 7 | int queue[20],n,head,i,j,k,seek=0,max,diff; 8 | 9 | float avg; 10 | 11 | printf("Enter the max range of disk\n"); 12 | 13 | scanf("%d",&max); 14 | 15 | printf("Enter the size of queue request\n"); 16 | 17 | scanf("%d",&n); 18 | 19 | printf("Enter the queue of disk positions to be read\n"); 20 | 21 | for(i=1;i<=n;i++) 22 | 23 | scanf("%d",&queue[i]); 24 | 25 | printf("Enter the initial head position\n"); 26 | 27 | scanf("%d",&head); 28 | 29 | queue[0]=head; 30 | 31 | for(j=0;j<=n-1;j++) 32 | 33 | { 34 | 35 | diff=abs(queue[j+1]-queue[j]); 36 | 37 | seek+=diff; 38 | 39 | printf("Disk head moves from %d to %d with seek %d\n",queue[j],queue[j+1],diff); 40 | 41 | } 42 | 43 | printf("Total seek time is %d\n",seek); 44 | 45 | avg=seek/(float)n; 46 | 47 | printf("Average seek time is %f\n",avg); 48 | 49 | return 0; 50 | 51 | } 52 | -------------------------------------------------------------------------------- /c/Greatestnumber.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | int a, b, c, d; 5 | printf("Enter four numbers: \n"); 6 | scanf("%d%d%d%d",&a,&b,&c,&d); 7 | if(a>b && a>c && a>d){ 8 | printf("The greatest number is %d",a); 9 | } 10 | else if(b>a && b>c && b>d){ 11 | printf("The greatest number is %d", b); 12 | } 13 | else if(c>a && c>b && c>d){ 14 | printf("The greatest number is %d",c); 15 | } 16 | else{ 17 | printf("The greatest numner is %d",d); 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /c/Heab_sort.c: -------------------------------------------------------------------------------- 1 | #include 2 | /* function to heapify a subtree. Here 'i' is the 3 | index of root node in array a[], and 'n' is the size of heap. */ 4 | void heapify(int a[], int n, int i) 5 | { 6 | int largest = i; // Initialize largest as root 7 | int left = 2 * i + 1; // left child 8 | int right = 2 * i + 2; // right child 9 | // If left child is larger than root 10 | if (left < n && a[left] > a[largest]) 11 | largest = left; 12 | // If right child is larger than root 13 | if (right < n && a[right] > a[largest]) 14 | largest = right; 15 | // If root is not largest 16 | if (largest != i) { 17 | // swap a[i] with a[largest] 18 | int temp = a[i]; 19 | a[i] = a[largest]; 20 | a[largest] = temp; 21 | 22 | heapify(a, n, largest); 23 | } 24 | } 25 | /*Function to implement the heap sort*/ 26 | void heapSort(int a[], int n) 27 | { 28 | for (int i = n / 2 - 1; i >= 0; i--) 29 | heapify(a, n, i); 30 | // One by one extract an element from heap 31 | for (int i = n - 1; i >= 0; i--) { 32 | /* Move current root element to end*/ 33 | // swap a[0] with a[i] 34 | int temp = a[0]; 35 | a[0] = a[i]; 36 | a[i] = temp; 37 | 38 | heapify(a, i, 0); 39 | } 40 | } 41 | /* function to print the array elements */ 42 | void printArr(int arr[], int n) 43 | { 44 | for (int i = 0; i < n; ++i) 45 | { 46 | printf("%d", arr[i]); 47 | printf(" "); 48 | } 49 | 50 | } 51 | int main() 52 | { 53 | int a[] = {48, 10, 23, 43, 28, 26, 1}; 54 | int n = sizeof(a) / sizeof(a[0]); 55 | printf("Before sorting array elements are - \n"); 56 | printArr(a, n); 57 | heapSort(a, n); 58 | printf("\nAfter sorting array elements are - \n"); 59 | printArr(a, n); 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /c/LFUpage.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int i,j,pf=0,np,nf,c,k,m; 5 | printf("enter the no. of pages: "); 6 | scanf("%d",&np); 7 | int ap[np],f[np]; 8 | printf("enter the page numbers: \n"); 9 | for ( i = 0; i < np; i++) 10 | { 11 | scanf("%d",&ap[i]); 12 | f[i]=0; 13 | } 14 | 15 | printf("enter the no. of frames: "); 16 | scanf("%d",&nf); 17 | int af[nf][3]; 18 | printf("enter the page numbers: \n"); 19 | for ( i = 0; i < nf; i++) 20 | { 21 | af[i][0]=-1; 22 | af[i][1]=0; 23 | af[i][2]=-1; 24 | } 25 | 26 | 27 | for ( i = 0; i < np; i++) 28 | { 29 | for ( j = 0; j < nf; j++) 30 | { 31 | if(af[j][0]==-1) 32 | { 33 | af[j][0]=ap[i]; 34 | af[j][1]=1; 35 | af[j][2]=i; 36 | pf++; 37 | printf("%d \t",ap[i]); 38 | for ( k = 0; k 2 | int main() 3 | { 4 | int i,j,pf=0,f=0,np,nf,c,k,m; 5 | printf("enter the no. of pages: "); 6 | scanf("%d",&np); 7 | int ap[np][2]; 8 | printf("enter the page numbers: \n"); 9 | for ( i = 0; i < np; i++) 10 | { 11 | scanf("%d",&ap[i][0]); 12 | ap[i][1]=i; 13 | } 14 | 15 | printf("enter the no. of frames: "); 16 | scanf("%d",&nf); 17 | int af[nf][2]; 18 | printf("enter the page numbers: \n"); 19 | for ( i = 0; i < nf; i++) 20 | { 21 | af[i][0]=-1; 22 | } 23 | 24 | 25 | 26 | for ( i = 0; i 2 | 3 | int main() 4 | 5 | { 6 | 7 | int n,i,an,s,l,c; 8 | 9 | printf("Enter total number of blocks in the disk:"); 10 | 11 | scanf("%d",&n); 12 | 13 | int a[n]; 14 | 15 | for(i=0;i%d\n",s); 56 | 57 | a[s++]=1; 58 | 59 | } 60 | 61 | else 62 | 63 | { 64 | 65 | while(a[s]!=0) 66 | 67 | { 68 | 69 | printf("%d is already allocated\n",s); 70 | 71 | s++; 72 | 73 | } 74 | 75 | printf("-->%d\n",s); 76 | 77 | a[s++]=1; 78 | 79 | } 80 | 81 | } 82 | 83 | printf("\nDo you want to continue?(1.yes/0.No):"); 84 | 85 | scanf("%d",&c); 86 | 87 | }while(c!=0); 88 | 89 | return 0; 90 | 91 | } 92 | 93 | Footer 94 | -------------------------------------------------------------------------------- /c/Power_using_function.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void power(); 5 | 6 | int main() 7 | { 8 | float p; 9 | power(p); 10 | return 0; 11 | } 12 | 13 | void power() 14 | { 15 | float p, n, a; 16 | printf("Enter any number and the power: "); 17 | scanf("%f %f", &n, &a); 18 | 19 | p = pow(n, a); 20 | 21 | printf("The result is: %f", p); 22 | } 23 | -------------------------------------------------------------------------------- /c/Prime.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | 5 | int n, i, flag = 0; 6 | 7 | printf("Enter a positive integer: "); 8 | 9 | scanf("%d", &n); 10 | 11 | // 0 and 1 are not prime numbers 12 | 13 | // change flag to 1 for non-prime number 14 | 15 | if (n == 0 || n == 1) 16 | 17 | flag = 1; 18 | 19 | for (i = 2; i <= n / 2; ++i) { 20 | 21 | // if n is divisible by i, then n is not prime 22 | 23 | // change flag to 1 for non-prime number 24 | 25 | if (n % i == 0) { 26 | 27 | flag = 1; 28 | 29 | break; 30 | 31 | } 32 | 33 | } 34 | 35 | // flag is 0 for prime numbers 36 | 37 | if (flag == 0) 38 | 39 | printf("%d is a prime number.", n); 40 | 41 | else 42 | 43 | printf("%d is not a prime number.", n); 44 | 45 | return 0; 46 | 47 | } 48 | -------------------------------------------------------------------------------- /c/Prod_Cons.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int mutex=1,full=0,empty=3,x=0; 5 | 6 | int main() 7 | { 8 | int n; 9 | void producer(); 10 | void consumer(); 11 | int wait(int); 12 | int signal(int); 13 | printf("\n1.Producer\n2.Consumer\n3.Exit"); 14 | while(1) 15 | { 16 | printf("\nEnter your choice:"); 17 | scanf("%d",&n); 18 | switch(n) 19 | { 20 | case 1: if((mutex==1)&&(empty!=0)) 21 | producer(); 22 | else 23 | printf("Buffer is full!!"); 24 | break; 25 | case 2: if((mutex==1)&&(full!=0)) 26 | consumer(); 27 | else 28 | printf("Buffer is empty!!"); 29 | break; 30 | case 3: 31 | exit(0); 32 | break; 33 | } 34 | } 35 | return 0; 36 | } 37 | 38 | int wait(int s) 39 | { 40 | return (--s); 41 | } 42 | 43 | int signal(int s) 44 | { 45 | return(++s); 46 | } 47 | 48 | void producer() 49 | { 50 | mutex=wait(mutex); 51 | full=signal(full); 52 | empty=wait(empty); 53 | x++; 54 | printf("\nProducer produces the item %d",x); 55 | mutex=signal(mutex); 56 | } 57 | 58 | void consumer() 59 | { 60 | mutex=wait(mutex); 61 | full=wait(full); 62 | empty=signal(empty); 63 | printf("\nConsumer consumes item %d",x); 64 | x--; 65 | mutex=signal(mutex); 66 | } 67 | -------------------------------------------------------------------------------- /c/Recursive.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void simplemerge(int x[] , int l , int s , int r ) 4 | 5 | { 6 | 7 | int temp[30], k=0, i=l, j=s ; 8 | 9 | while(i 2 | 3 | int main() 4 | 5 | { 6 | 7 | int i,h,n,sum=0,d,t,j; printf("Enter no.of request:"); 8 | 9 | scanf("%d",&n); 10 | 11 | int r[n]; 12 | 13 | printf("Enter request sequence:\n"); 14 | 15 | for(i=0;ir[j+1]) 44 | 45 | { 46 | 47 | int temp; 48 | 49 | temp=r[j]; 50 | 51 | r[j]=r[j+1]; 52 | 53 | r[j+1]=temp; 54 | 55 | } 56 | 57 | } 58 | 59 | } 60 | 61 | if(d==0) 62 | 63 | { 64 | 65 | for(i=0;i=0;i=i-1) 82 | 83 | { 84 | 85 | sum=sum+(h-r[i]); 86 | 87 | h=r[i]; 88 | 89 | if(i==0) 90 | 91 | { 92 | 93 | sum=sum+h; 94 | 95 | h=0; 96 | 97 | } 98 | 99 | } 100 | 101 | for(i=j;i=0;i=i-1) 154 | 155 | { 156 | 157 | sum=sum+(h-r[i]); 158 | 159 | h=r[i]; 160 | 161 | } 162 | 163 | } 164 | 165 | printf("Total head movement:%d",sum); 166 | 167 | return 0; 168 | 169 | } 170 | -------------------------------------------------------------------------------- /c/Seq.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | 5 | { 6 | 7 | int n,s,l,c,i,count; printf("Enter total number of blocks in the disk:"); 8 | 9 | scanf("%d",&n); 10 | 11 | int a[n]; 12 | 13 | for(i=0;i 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/SpecialNumber.c: -------------------------------------------------------------------------------- 1 | //A special number is equal to the sum of the factorial of its digits i.e. 145 = 1! + 4! + 5! 2 | #include 3 | int fact(int x){ 4 | if(x == 0 || x == 1){ 5 | return 1; 6 | 7 | } 8 | return x*(fact(x-1)); 9 | } 10 | int main(){ 11 | int x, num, digit, sum = 0; 12 | printf("Enter the number: "); 13 | scanf("%d", &x); 14 | num = x; 15 | while(num > 0){ 16 | digit = num%10; 17 | sum += fact(digit); 18 | num = num/10; 19 | } 20 | if(sum == x){ 21 | printf("%d is a Special number.", x); 22 | }else{ 23 | printf("%d is not a Special number.", x); 24 | } 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /c/Sum upto N: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | 5 | int main(){ 6 | 7 | 8 | 9 | 10 | 11 | int n, sum=0,a; 12 | 13 | 14 | 15 | 16 | 17 | printf("enter the value of n"); 18 | scanf("%d",&n); 19 | 20 | 21 | 22 | for (int i=1; i<=n; i++) 23 | { 24 | 25 | 26 | 27 | 28 | sum=sum+i; 29 | 30 | 31 | 32 | 33 | 34 | } 35 | 36 | a=sum; 37 | 38 | printf("%d",a); 39 | 40 | return 0; 41 | 42 | } 43 | 44 | -------------------------------------------------------------------------------- /c/UppercaseLowercase.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | char ch; 6 | printf("Enter a character: \n"); 7 | scanf("%c",&ch); 8 | if(ch>=65 && ch<=90){ 9 | printf("The given input character is an uppercase character"); 10 | } 11 | else if(ch>=97 && ch<=122){ 12 | printf("The given input character is a lowercase character"); 13 | } 14 | else{ 15 | printf("The given input is not a character"); 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /c/bankers.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int r,c,min=-1,s,ct; 6 | printf("Enter number of processes:"); 7 | scanf("%d",&r); 8 | int p[r]; 9 | for(int i=1;i<=r;i++) 10 | { 11 | p[i]=0; 12 | } 13 | printf("Enter number of resources:"); 14 | scanf("%d",&c); 15 | 16 | int max[r][c]; 17 | printf("Enter max.number of resources required for each process:\n"); 18 | for( int i=1;i<=r;i++) 19 | { 20 | printf("P[%d]:\n",i); 21 | for(int j=1;j<=c;j++) 22 | { 23 | printf("\tR[%d]:",j); 24 | scanf("%d",&max[i][j]); 25 | } 26 | } 27 | 28 | int allo[r][c]; 29 | printf("Enter number of resources allocated for each process:\n"); 30 | for( int i=1;i<=r;i++) 31 | { 32 | printf("P[%d]:\n",i); 33 | for(int j=1;j<=c;j++) 34 | { 35 | printf("\tR[%d]:",j); 36 | scanf("%d",&allo[i][j]); 37 | } 38 | } 39 | 40 | int need[r][c]; 41 | for( int i=1;i<=r;i++) 42 | { 43 | for(int j=1;j<=c;j++) 44 | { 45 | need[i][j]=max[i][j]-allo[i][j]; 46 | } 47 | } 48 | 49 | int avl[1][c]; 50 | printf("Enter number of available resources:\n"); 51 | { 52 | for( int j=1;j<=c;j++) 53 | { 54 | scanf("%d",&avl[1][j]); 55 | } 56 | } 57 | 58 | for(int i=1;i<=r;i++) 59 | { 60 | if(p[i]!=1) 61 | { 62 | ct=0; 63 | for(int j=1;j<=c;j++) 64 | { 65 | if(need[i][j]<=avl[1][j]) 66 | { 67 | ct=ct+1; 68 | } 69 | else 70 | { 71 | break; 72 | } 73 | } 74 | if(ct==c) 75 | { 76 | p[i]=1; 77 | printf("P[%d]\t",i); 78 | for(int j=1;j<=c;j++) 79 | { 80 | avl[1][j]+=allo[i][j]; 81 | } 82 | i=0; 83 | } 84 | } 85 | } 86 | for(int i=1;i<=r;i++) 87 | { 88 | if(p[i]==1) 89 | { 90 | continue; 91 | } 92 | else 93 | { 94 | printf("\n Not safe"); 95 | return 0; 96 | } 97 | } 98 | printf("\nSafe"); 99 | return 0; 100 | } 101 | -------------------------------------------------------------------------------- /c/bestfit.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int np,nb,min=1000,i,j,pos=0; 5 | printf("enter the no. of processes: "); 6 | scanf("%d",&np); 7 | int ap[np][2]; 8 | printf("enter the size of processes: \n"); 9 | for(i=0;i 11 | #include 12 | #include 13 | 14 | bool is_sorted(int c[], int size) 15 | { 16 | for (int i = 0; i < size - 1; i++) 17 | { 18 | if (c[i] > c[i + 1]) 19 | { 20 | return 0; 21 | } 22 | } 23 | return 1; 24 | } 25 | 26 | void bogo_sort(int c[], int size) 27 | { 28 | int x; 29 | int r; 30 | for (int i = 0; i < size; i++) 31 | { 32 | x = c[i]; 33 | r = rand()%size; 34 | c[i] = c[r]; 35 | c[r] = x; 36 | } 37 | } 38 | 39 | int main() 40 | { 41 | int init[5]={23,4,800,33,90}; 42 | while(!is_sorted(init,sizeof(init)/4)){ 43 | bogo_sort(init,sizeof(init)/4); 44 | 45 | } 46 | 47 | 48 | } -------------------------------------------------------------------------------- /c/circularqueue.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define SIZE 5 4 | 5 | int items[SIZE]; 6 | int front = -1, rear = -1; 7 | 8 | int isFull() { 9 | if ((front == rear + 1) || (front == 0 && rear == SIZE - 1)) return 1; 10 | return 0; 11 | } 12 | 13 | int isEmpty() { 14 | if (front == -1) return 1; 15 | return 0; 16 | } 17 | 18 | void enQueue(int element) { 19 | if (isFull()) 20 | printf("\n Queue is full!! \n"); 21 | else { 22 | if (front == -1) front = 0; 23 | rear = (rear + 1) % SIZE; 24 | items[rear] = element; 25 | printf("\n Inserted -> %d", element); 26 | } 27 | } 28 | 29 | int deQueue() { 30 | int element; 31 | if (isEmpty()) { 32 | printf("\n Queue is empty !! \n"); 33 | return (-1); 34 | } else { 35 | element = items[front]; 36 | if (front == rear) { 37 | front = -1; 38 | rear = -1; 39 | } 40 | else { 41 | front = (front + 1) % SIZE; 42 | } 43 | printf("\n Deleted element -> %d \n", element); 44 | return (element); 45 | } 46 | } 47 | 48 | void display() { 49 | int i; 50 | if (isEmpty()) 51 | printf(" \n Empty Queue\n"); 52 | else { 53 | printf("\n Front -> %d ", front); 54 | printf("\n Items -> "); 55 | for (i = front; i != rear; i = (i + 1) % SIZE) { 56 | printf("%d ", items[i]); 57 | } 58 | printf("%d ", items[i]); 59 | printf("\n Rear -> %d \n", rear); 60 | } 61 | } 62 | 63 | int main() { 64 | deQueue(); 65 | 66 | enQueue(1); 67 | enQueue(2); 68 | enQueue(3); 69 | enQueue(4); 70 | enQueue(5); 71 | 72 | enQueue(6); 73 | 74 | display(); 75 | deQueue(); 76 | 77 | display(); 78 | 79 | enQueue(7); 80 | display(); 81 | 82 | enQueue(8); 83 | 84 | return 0; 85 | } 86 | -------------------------------------------------------------------------------- /c/firstfit.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int np,nb,i,j; 5 | printf("enter the no. of processes: "); 6 | scanf("%d",&np); 7 | int ap[np][2]; 8 | printf("enter the size of processes: \n"); 9 | for(i=0;i 2 | #define MAX 10 3 | void RestoreHeapUp(int *,int); 4 | void RestoreHeapDown(int*,int,int); 5 | 6 | int main() { 7 | int Heap[MAX],n,i,j; 8 | 9 | printf("Enter the number of elements : "); 10 | scanf("%d",&n); 11 | printf("Enter the elements : "); 12 | for(i=1;i<=n;i++) { 13 | scanf("%d",&Heap[i]); 14 | RestoreHeapUp(Heap, i); 15 | } 16 | 17 | j=n; 18 | for(i=1;i<=j;i++) { 19 | int temp; 20 | temp=Heap[1]; 21 | Heap[1]= Heap[n]; 22 | Heap[n]=temp; 23 | n = n-1; 24 | RestoreHeapDown(Heap,1,n); 25 | } 26 | n=j; 27 | printf("The sorted elements are: "); 28 | for(i=1;i<=n;i++) 29 | printf("%4d",Heap[i]); 30 | return 0; 31 | } 32 | 33 | void RestoreHeapUp(int *Heap,int index) { 34 | int val = Heap[index]; 35 | while( (index>1) && (Heap[index/2] < val) ) { 36 | Heap[index]=Heap[index/2]; 37 | index /= 2; 38 | } 39 | Heap[index]=val; 40 | } 41 | 42 | void RestoreHeapDown(int *Heap,int index,int n) { 43 | int val = Heap[index]; 44 | int j=index*2; 45 | while(j<=n) { 46 | if( (j 3 | #include 4 | /** 5 | * @file 6 | * @brief Checks if int is even or odd. 7 | * [Explanation](https://www.geeksforgeeks.org/check-if-a-number-is-odd-or-even-using-bitwise-operators/) 8 | * @author [XenoxJeager] (https://github.com/XenoxJeager) 9 | * @details 10 | * Checks if int is even or odd depending on its LSB(1 or 0). 11 | */ 12 | 13 | /** 14 | * @brief performs bitwise and with i and 1 and returns result. 15 | * 16 | * @param i int 17 | * @return true 18 | * @return false 19 | */ 20 | bool isodd(int i){ 21 | return i & 1; 22 | } 23 | 24 | int main(){ 25 | // returns 0 since 42 is even 26 | printf("%d \n",isodd(42)); 27 | 28 | } 29 | 30 | 31 | -------------------------------------------------------------------------------- /c/merge_sort.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void printArray(int *A, int n) 4 | { 5 | for (int i = 0; i < n; i++) 6 | { 7 | printf("%d ", A[i]); 8 | } 9 | printf("\n"); 10 | } 11 | 12 | void merge(int A[], int mid, int low, int high) 13 | { 14 | int i, j, k, B[100]; 15 | i = low; 16 | j = mid + 1; 17 | k = low; 18 | 19 | while (i <= mid && j <= high) 20 | { 21 | if (A[i] < A[j]) 22 | { 23 | B[k] = A[i]; 24 | i++; 25 | k++; 26 | } 27 | else 28 | { 29 | B[k] = A[j]; 30 | j++; 31 | k++; 32 | } 33 | } 34 | while (i <= mid) 35 | { 36 | B[k] = A[i]; 37 | k++; 38 | i++; 39 | } 40 | while (j <= high) 41 | { 42 | B[k] = A[j]; 43 | k++; 44 | j++; 45 | } 46 | for (int i = low; i <= high; i++) 47 | { 48 | A[i] = B[i]; 49 | } 50 | 51 | } 52 | 53 | void mergeSort(int A[], int low, int high){ 54 | int mid; 55 | if(low 2 | #include 3 | 4 | int main() 5 | { 6 | float val; 7 | float fVal,cVal; 8 | 9 | printf("Enter a float value: "); 10 | scanf("%f",&val); 11 | 12 | fVal=floor(val); 13 | cVal=ceil(val); 14 | printf("floor value:%f \n",fVal) 15 | printf("ceil value:%f \n",cVal); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /c/pagereplacementLRU.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int np,nf,i,j,f=-1,c,pfc=0,n,m,k; 5 | printf("Enter number of pages "); 6 | scanf("%d",&np); 7 | int ap[np][2]; 8 | printf("Enter page number : \n"); 9 | for(i=0;i 2 | int main() 3 | { 4 | int m,p,i,fn,np,pid,npg,j,c=0; 5 | printf("Enter total memory size:"); 6 | scanf("%d",&m); 7 | printf("Enter page size:"); 8 | scanf("%d",&p); 9 | fn=m/p; 10 | int a[fn][2]; 11 | for(i=0;i 2 | #include 3 | #include 4 | 5 | 6 | bool isPalindrome(const char *str) { 7 | int length = strlen(str); 8 | int i, j; 9 | 10 | for (i = 0, j = length - 1; i < j; i++, j--) { 11 | if (str[i] != str[j]) { 12 | return false; 13 | } 14 | } 15 | return true; 16 | } 17 | 18 | int main() { 19 | char input[100]; 20 | 21 | printf("Enter a string (up to 99 characters): "); 22 | scanf("%99s", input); 23 | 24 | if (isPalindrome(input)) { 25 | printf("%s is a palindrome.\n", input); 26 | } else { 27 | printf("%s is not a palindrome.\n", input); 28 | } 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /c/postfix.c: -------------------------------------------------------------------------------- 1 | #include 2 | int stack[20]; 3 | int top = -1; 4 | 5 | void push(int x) 6 | { 7 | stack[++top] = x; 8 | } 9 | 10 | int pop() 11 | { 12 | return stack[top--]; 13 | } 14 | 15 | int main() 16 | { 17 | char exp[20]; 18 | char *e; 19 | int n1,n2,n3,num; 20 | printf("Enter the expression :: "); 21 | scanf("%s",exp); 22 | e = exp; 23 | while(*e != '\0') 24 | { 25 | if(isdigit(*e)) 26 | { 27 | num = *e - 48; 28 | push(num); 29 | } 30 | else 31 | { 32 | n1 = pop(); 33 | n2 = pop(); 34 | switch(*e) 35 | { 36 | case '+': 37 | { 38 | n3 = n1 + n2; 39 | break; 40 | } 41 | case '-': 42 | { 43 | n3 = n2 - n1; 44 | break; 45 | } 46 | case '*': 47 | { 48 | n3 = n1 * n2; 49 | break; 50 | } 51 | case '/': 52 | { 53 | n3 = n2 / n1; 54 | break; 55 | } 56 | } 57 | push(n3); 58 | } 59 | e++; 60 | } 61 | printf("\nThe result of expression %s = %d\n\n",exp,pop()); 62 | return 0; 63 | } 64 | 65 | -------------------------------------------------------------------------------- /c/postfix_val.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include 6 | 7 | float compute(char symbol, float op1, float op2) 8 | 9 | { 10 | 11 | switch (symbol) 12 | 13 | { 14 | 15 | case '+': return op1 + op2; 16 | 17 | case '-': return op1 - op2; 18 | 19 | case '*': return op1 * op2; 20 | 21 | case '/': return op1 / op2; 22 | 23 | case '$': 24 | 25 | case '^': return pow(op1,op2); 26 | 27 | default : return 0; 28 | 29 | } 30 | 31 | } 32 | 33 | void main() 34 | 35 | { 36 | 37 | float s[20], res, op1, op2; 38 | 39 | int top, i; 40 | 41 | char postfix[20], symbol; 42 | 43 | printf("\nEnter the postfix expression:\n"); 44 | 45 | scanf ("%s", postfix); 46 | 47 | top=-1; 48 | 49 | for (i=0; i 2 | /** 3 | * @file c/power2_mod.c 4 | * @brief Returns the mod of an unsigned int, the modulo number supplied needs to be 2^n and n >=0 = and n < 31 . 5 | * @author [XenoxJeager] (https://github.com/XenoxJeager) 6 | */ 7 | 8 | /** 9 | * @brief returns the square root of powers of 2 from 0 to 2^31. 10 | * 11 | * @param d has to be a power of 2 otherwise the function is not precise. 12 | * @return unsigned int pow which discribes the n in 2^n. 13 | */ 14 | unsigned int square_root(unsigned int d){ 15 | int pow = 0; 16 | while ( !(2147483648&d)){ 17 | d = d<<1; 18 | pow++; 19 | } 20 | return 31-pow; 21 | 22 | } 23 | 24 | /** 25 | * @brief 26 | * 27 | * @param number any number n ranging from n=0 to n=2^32-1. 28 | * @param mod has to be a power of 2. 29 | * @return unsigned int which represents the mod. 30 | */ 31 | unsigned int mod_power2(unsigned int number, unsigned int mod){ 32 | int mask = 0; 33 | for (int i = 0; i < square_root(mod) ;i++ ){ 34 | mask |=1 << i; 35 | } 36 | 37 | return number& mask; 38 | } 39 | int main (){ 40 | printf("mod: %u \n",mod_power2(32,16)); 41 | } -------------------------------------------------------------------------------- /c/queue_array.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define size 50 4 | 5 | int Q[size], rear=-1,front=0; 6 | 7 | int isempty() { 8 | if(front == -1 || front > rear) 9 | return 1; 10 | else 11 | return 0; 12 | } 13 | 14 | int isfull() { 15 | if(rear == size - 1) 16 | return 1; 17 | else 18 | return 0; 19 | } 20 | 21 | void InsertQ(int item) { 22 | if(isfull()) 23 | printf("Queue is Full"); 24 | else { 25 | if(front == -1) 26 | front = 0; 27 | rear = rear+1; 28 | Q[rear] = item; 29 | } 30 | 31 | } 32 | 33 | int DeleteQ() { 34 | int index = -1; 35 | if(isempty()) { 36 | printf("Queue is empty"); 37 | } 38 | else { 39 | index = front++; 40 | } 41 | return index; 42 | } 43 | 44 | void Display() { 45 | 46 | if(isempty()){ 47 | printf("Queue is empty"); 48 | } 49 | int i; 50 | printf("\n Queue :"); 51 | for (i = front; i != rear+1; i = (i + 1) % size) { 52 | printf("%d ", Q[i]); 53 | } 54 | } 55 | 56 | int main() { 57 | int ch; 58 | printf("Queue"); 59 | do { 60 | printf("\n1. Insert 2. Delete 3.Display 4.Exit \n"); 61 | scanf("%d",&ch); 62 | switch(ch) { 63 | case 1: { 64 | int item; 65 | printf("Item to be entered : "); 66 | scanf("%d",&item); 67 | InsertQ(item); 68 | break; 69 | } 70 | case 2: { 71 | int val = DeleteQ(); 72 | if(val != -1) 73 | printf("The deleted item is %d",Q[val]); 74 | break; 75 | } 76 | case 3: 77 | Display(); 78 | break; 79 | case 4: 80 | exit(0); 81 | } 82 | } while(1); 83 | return 0; 84 | } -------------------------------------------------------------------------------- /c/queue_linkedlist.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct NODE { 4 | int info; 5 | struct NODE *link; 6 | } ; 7 | typedef struct NODE node; 8 | 9 | node *rear=NULL; node *front = NULL; 10 | node *newnode(int val) { node *p; 11 | p=(node *)malloc(sizeof(node)); 12 | p->info=val; 13 | p->link=NULL; 14 | return p; 15 | } 16 | 17 | void InsertQ(int item) { 18 | node *p; 19 | p = newnode(item); 20 | if(p == NULL ) 21 | printf("Full"); 22 | else { 23 | p->info = item; 24 | p->link = NULL; 25 | if(front == NULL) 26 | front = rear = p; 27 | else 28 | rear->link = p; 29 | rear = p; 30 | } 31 | } 32 | void Delete() { 33 | node *p; 34 | if(front == NULL) 35 | printf("underflow"); 36 | else 37 | p = front; 38 | front = front->link; 39 | free(p); 40 | } 41 | void Display() { 42 | 43 | node *curr; 44 | curr=front; 45 | while(curr!=NULL) { 46 | printf("%d", curr->info); 47 | curr=curr->link; 48 | if(curr !=NULL) 49 | printf(" --> "); 50 | } 51 | } 52 | 53 | void main() { 54 | int ch,item; 55 | 56 | do { 57 | printf("\n1. Insert \n2. Delete\n3. Display\n4. Quit\nEnter your Choice : "); 58 | scanf("%d",&ch); 59 | switch(ch) { 60 | case 1: 61 | printf("\nvalue to be inserted:"); 62 | scanf("%d",&item); 63 | InsertQ(item); 64 | break; 65 | case 2: 66 | Delete(); 67 | break; 68 | 69 | case 3: 70 | Display(); 71 | break; 72 | case 4: 73 | break; 74 | 75 | default:printf("Invalid choice"); 76 | } 77 | }while(ch!=4); 78 | 79 | } -------------------------------------------------------------------------------- /c/quicksort.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void swap(int *a, int *b) { 4 | int t = *a; 5 | *a = *b; 6 | *b = t; 7 | } 8 | 9 | int partition(int array[], int low, int high) { 10 | 11 | 12 | int pivot = array[high]; 13 | 14 | int i = (low - 1); 15 | 16 | for (int j = low; j < high; j++) { 17 | if (array[j] <= pivot) { 18 | 19 | 20 | i++; 21 | 22 | swap(&array[i], &array[j]); 23 | } 24 | } 25 | 26 | swap(&array[i + 1], &array[high]); 27 | 28 | return (i + 1); 29 | } 30 | 31 | void quickSort(int array[], int low, int high) { 32 | if (low < high) { 33 | 34 | int pi = partition(array, low, high); 35 | 36 | 37 | quickSort(array, low, pi - 1); 38 | 39 | quickSort(array, pi + 1, high); 40 | } 41 | } 42 | 43 | void printArray(int array[], int size) { 44 | for (int i = 0; i < size; ++i) { 45 | printf("%d ", array[i]); 46 | } 47 | printf("\n"); 48 | } 49 | 50 | 51 | int main() { 52 | int data[] = {8, 7, 2, 1, 0, 9, 6}; 53 | 54 | int n = sizeof(data) / sizeof(data[0]); 55 | 56 | printf("Unsorted Array\n"); 57 | printArray(data, n); 58 | 59 | 60 | quickSort(data, 0, n - 1); 61 | 62 | printf("Sorted array in ascending order: \n"); 63 | printArray(data, n); 64 | } 65 | -------------------------------------------------------------------------------- /c/stack_linkedlist.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct NODE { 5 | int info; 6 | struct NODE *link; 7 | } ; 8 | 9 | typedef struct NODE node; 10 | node *top=NULL; 11 | 12 | node *newnode(int val) { 13 | node *p; 14 | p=(node *)malloc(sizeof(node)); 15 | p->info=val; 16 | p->link=NULL; 17 | return p; 18 | } 19 | 20 | void Display() { 21 | node *curr; 22 | curr=top; 23 | while(curr!=NULL) { 24 | printf("%d", curr->info); 25 | curr=curr->link; 26 | if(curr !=NULL) 27 | printf(" --> "); 28 | } 29 | } 30 | 31 | void push(int item) { 32 | node *p; 33 | p=newnode(item); 34 | if(p==NULL) 35 | printf("overflow"); 36 | else 37 | p->info = item; 38 | p->link = top; 39 | top = p; 40 | } 41 | 42 | void pop() { 43 | node *ptr; 44 | ptr = top; 45 | if(ptr == NULL) 46 | printf("Underflow"); 47 | else 48 | ptr = top; 49 | top = top->link; 50 | free(ptr); 51 | } 52 | void main() { 53 | int ch,item; 54 | 55 | do { 56 | printf("\n1. Insert \n2. Delete\n3. Display\n4. Quit\nEnter your Choice : "); 57 | scanf("%d",&ch); 58 | switch(ch) { 59 | case 1: 60 | printf("\nvalue to be inserted:"); 61 | scanf("%d",&item); 62 | push(item); 63 | break; 64 | case 2: 65 | pop(); 66 | break; 67 | case 3: 68 | Display(); 69 | break; 70 | case 4: 71 | break; 72 | 73 | default:printf("Invalid choice"); 74 | } 75 | }while(ch!=4); 76 | 77 | } -------------------------------------------------------------------------------- /c/string_conversion.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // String Lowecase to Uppercase 4 | 5 | int main() 6 | { 7 | char string[100]; 8 | 9 | printf("Enter the string in Lowercase: "); 10 | scanf("%s", &string); 11 | 12 | printf("The string in lowercase ='%s'\n", string); 13 | 14 | for(int i=0; string[i]; i++) 15 | { 16 | if(string[i] >= 97 && string[i] <= 122) 17 | { 18 | string[i] = string[i] - 32; 19 | } 20 | } 21 | 22 | printf("The string in Uppercase: '%s'\n", string); 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /c/swap_with_pointer.c: -------------------------------------------------------------------------------- 1 | # include 2 | 3 | int main() { 4 | int a = 10, b = 20, temp; 5 | int *c = &a; 6 | int *d = &b; 7 | 8 | printf("Before the swapping of: a = %d, b = %d\n", a, b); 9 | 10 | temp = *c; 11 | *c = *d; 12 | *d = temp; 13 | 14 | printf("After the swapping of: a = %d, b = %d\n", a, b); 15 | 16 | return 0; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /c/worstfit.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int np,nb,max=-1,i,j,pos; 5 | printf("enter the no. of processes: "); 6 | scanf("%d",&np); 7 | int ap[np][2]; 8 | printf("enter the size of processes: \n"); 9 | for(i=0;imax) 38 | { 39 | max=ab[j][0]-ap[i][0]; 40 | pos=j; 41 | } 42 | } 43 | } 44 | if(ap[i][0] 2 | using namespace std; 3 | 4 | int main() { 5 | 6 | char op; 7 | float num1, num2; 8 | 9 | cout << "Enter operator: +, -, *, /: "; 10 | cin >> op; 11 | 12 | cout << "Enter two operands: "; 13 | cin >> num1 >> num2; 14 | 15 | switch(op) { 16 | 17 | case '+': 18 | cout << num1 << " + " << num2 << " = " << num1 + num2; 19 | break; 20 | 21 | case '-': 22 | cout << num1 << " - " << num2 << " = " << num1 - num2; 23 | break; 24 | 25 | case '*': 26 | cout << num1 << " * " << num2 << " = " << num1 * num2; 27 | break; 28 | 29 | case '/': 30 | cout << num1 << " / " << num2 << " = " << num1 / num2; 31 | break; 32 | 33 | default: 34 | // If the operator is other than +, -, * or /, error message is shown 35 | cout << "Error! operator is not correct"; 36 | break; 37 | } 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /cpp/Counting.cpp: -------------------------------------------------------------------------------- 1 | // Also Known as Bucket Sort 2 | 3 | #include 4 | using namespace std; 5 | 6 | const int N = 1e6+5; 7 | 8 | int main() 9 | { 10 | int n,arr[100],Aux[N]={0},i,max=-1,sorted[100]; 11 | cin >> n; // No. of integers 12 | for(i=0;i> arr[i]; 15 | Aux[arr[i]]++; 16 | if( arr[i]>max) // stores the max element in the given i/p 17 | max=arr[i]; 18 | } 19 | // max is the size of Auxialary array 20 | 21 | int temp,k=0; 22 | for(i=0;i<=max;i++) // Traverse Auxialary Array 23 | { 24 | temp =Aux[i]; 25 | while(temp) 26 | { 27 | cout << i <<" "; 28 | temp--; 29 | } 30 | } 31 | cout << endl; 32 | return 0; 33 | } -------------------------------------------------------------------------------- /cpp/Fibonacci.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int n, t1 = 0, t2 = 1, nextTerm = 0; 6 | 7 | cout << "Enter the number of terms: "; 8 | cin >> n; 9 | 10 | cout << "Fibonacci Series: "; 11 | 12 | for (int i = 1; i <= n; ++i) { 13 | // Prints the first two terms. 14 | if(i == 1) { 15 | cout << t1 << ", "; 16 | continue; 17 | } 18 | if(i == 2) { 19 | cout << t2 << ", "; 20 | continue; 21 | } 22 | nextTerm = t1 + t2; 23 | t1 = t2; 24 | t2 = nextTerm; 25 | 26 | cout << nextTerm << ", "; 27 | } 28 | return 0; 29 | } -------------------------------------------------------------------------------- /cpp/Fibonacci_Triangle.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int a=0,b=1,i,c,n,j; 6 | cout<<"Limit Set: "; 7 | cin>>n; 8 | for(i=1; i<=n; i++) 9 | { 10 | a=0; 11 | b=1; 12 | cout< 2 | using namespace std; 3 | 4 | struct edge // Edge Template 5 | { 6 | int u,v,w; 7 | }; 8 | 9 | int dsu[5000005]; 10 | int find(int u) 11 | { 12 | while(dsu[u]!=-1) 13 | { 14 | u = dsu[u]; 15 | } 16 | return u; // root 17 | } 18 | 19 | void Union(int u,int v) 20 | { 21 | u=find(u) ; v=find(v); // now u contain parent of u and v contains the parent of v 22 | if(u==v) // if both has same parent 23 | return ; 24 | else 25 | dsu[u]=v; // u become child of v 26 | } 27 | 28 | bool cmp(edge i1,edge i2) // Comparator function 29 | { 30 | if(i1.w==i2.w) 31 | return (i1.w+i1.u+i1.v < i2.w+i2.u+i2.v); // Just remember (a i2.w .... 34 | } 35 | int main() 36 | { 37 | int i,n,m,w,u,v,ans=0; 38 | edge E[500005]; // show 1000 edges 39 | cin>>n>>m; // n is no. of vertices and m is the no. of edges 40 | 41 | for(i=0;i>E[i].u >>E[i].v >>E[i].w; 43 | 44 | for(i=1;i<=n;i++) 45 | dsu[i]=-1; // shows that vertex has no parent 46 | 47 | sort(E,E+m,cmp); // sort the edges on the basis of (u+v+w) 48 | 49 | for(i=0;i &res) { 5 | 6 | if(i > n) 7 | return; 8 | 9 | res.push_back(i); 10 | 11 | for(int j=0; j<=9; j++) { 12 | dfs(10 * i + j, n, res); 13 | } 14 | 15 | return; 16 | } 17 | 18 | vector lexicalOrder(int n) { 19 | 20 | vector res; 21 | 22 | for(int i=1; i<=9; i++) { 23 | dfs(i, n, res); 24 | } 25 | 26 | return res; 27 | } 28 | 29 | }; -------------------------------------------------------------------------------- /cpp/Linearsearch. cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | 7 | { 8 | 9 | int A[15],n,a; 10 | 11 | cout << "Enter the size of Array : "; 12 | 13 | cin >> n; 14 | 15 | cout << "Enter the Elements of Array : "; 16 | 17 | for(int i = 0;i < n;i++) 18 | 19 | { 20 | 21 | cin >> A[i]; 22 | 23 | } 24 | 25 | cout << "Enter the number to search : "; 26 | 27 | cin >> a; 28 | 29 | for(int i = 0;i < n;i++) 30 | 31 | { 32 | 33 | if(a == A[i]) 34 | 35 | { 36 | 37 | cout << "Search sucessful." << endl; 38 | 39 | cout << "The number is found at " << i << endl; 40 | 41 | return 0; 42 | 43 | } 44 | 45 | } 46 | 47 | cout << "Search unsuccessful."; 48 | 49 | } 50 | -------------------------------------------------------------------------------- /cpp/Mirror.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Mirror 3 | For a given Binary Tree of type integer, update it with its corresponding mirror image. 4 | 5 | Example: 6 | 1 1 7 | / \ / \ 8 | 2 3 -----> 3 2 9 | / \ / \ / \ / \ 10 | 4 5 6 7 7 6 5 4 11 | Input Format: 12 | The first and the only line of input will contain the node data, all separated by a single space. Since -1 is used as an indication whether the left or 13 | right node data exist for root, it will not be a part of the node data. 14 | 15 | Output Format: 16 | The only line of output prints the mirrored tree in a level-wise order. 17 | Each level will be printed on a new line. Elements printed at each level will be separated by a single line. 18 | 19 | Note: 20 | You are not required to print anything explicitly. It has already been taken care of. 21 | 22 | Constraints: 23 | 1 <= N <= 10^5 24 | Where N is the total number of nodes in the binary tree. 25 | 26 | Time Limit: 1 sec 27 | 28 | Sample Input 1: 29 | 1 2 3 4 5 6 7 -1 -1 -1 -1 -1 -1 -1 -1 30 | 31 | Sample Output 1: 32 | 1 33 | 3 2 34 | 7 6 5 4 35 | 36 | 37 | Sample Input 2: 38 | 5 10 6 2 3 -1 -1 -1 -1 -1 9 -1 -1 39 | 40 | Sample Output 2: 41 | 5 42 | 6 10 43 | 3 2 44 | 9 45 | */ 46 | 47 | /********************************************************** 48 | Following is the Binary Tree Node class structure 49 | 50 | template 51 | class BinaryTreeNode { 52 | public : 53 | T data; 54 | BinaryTreeNode *left; 55 | BinaryTreeNode *right; 56 | 57 | BinaryTreeNode(T data) { 58 | this -> data = data; 59 | left = NULL; 60 | right = NULL; 61 | } 62 | }; 63 | 64 | */ 65 | 66 | void mirrorBinaryTree(BinaryTreeNode* root) { 67 | // Write your code here 68 | //corner case 69 | if(root == NULL) { 70 | return; 71 | } 72 | 73 | mirrorBinaryTree(root -> left); 74 | mirrorBinaryTree(root -> right); 75 | 76 | swap(root -> left, root -> right); 77 | 78 | return; 79 | } 80 | -------------------------------------------------------------------------------- /cpp/Nodes without siblings.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Nodes without sibling 3 | For a given Binary Tree of type integer, print all the nodes without any siblings. 4 | 5 | Input Format: 6 | The first and the only line of input will contain the node data, all separated by a single space. Since -1 is used as an indication whether the 7 | left or right node data exist for root, it will not be a part of the node data. 8 | 9 | Output Format: 10 | The only line of output prints the node data in a top to down fashion with reference to the root. 11 | Node data in the left subtree will be printed first and then the right subtree. 12 | A single space will separate them all. 13 | 14 | Constraints: 15 | 1 <= N <= 10^5 16 | Where N is the total number of nodes in the binary tree. 17 | 18 | Time Limit: 1 second 19 | 20 | Sample Input 1: 21 | 5 6 10 2 3 -1 -1 -1 -1 -1 9 -1 -1 22 | 23 | Sample Output 1: 24 | 9 25 | 26 | 27 | Sample Input 2: 28 | 2 4 5 6 -1 -1 7 20 30 80 90 -1 -1 -1 -1 -1 -1 -1 -1 29 | 30 | Sample Output 2: 31 | 6 7 32 | */ 33 | 34 | /************************************************************ 35 | 36 | Following is the Binary Tree node structure 37 | 38 | template 39 | class BinaryTreeNode 40 | { 41 | public : 42 | T data; 43 | BinaryTreeNode *left; 44 | BinaryTreeNode *right; 45 | 46 | BinaryTreeNode(T data) 47 | { 48 | this -> data = data; 49 | left = NULL; 50 | right = NULL; 51 | } 52 | }; 53 | 54 | ************************************************************/ 55 | void printNodesWithoutSibling(BinaryTreeNode *root) { 56 | // Write your code here 57 | //corner case 58 | if(root == NULL) { 59 | return; 60 | } 61 | 62 | if(root -> left == NULL and root -> right) { 63 | cout << root -> right -> data << " "; 64 | } else if (root -> left and root -> right == NULL) { 65 | cout << root -> left -> data << " "; 66 | } 67 | 68 | printNodesWithoutSibling(root -> left); 69 | printNodesWithoutSibling(root -> right); 70 | 71 | } 72 | -------------------------------------------------------------------------------- /cpp/PostOrder binary tree.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Postorder Binary Tree 3 | For a given Binary Tree of integers, print the post-order traversal. 4 | 5 | Input Format: 6 | The first and the only line of input will contain the node data, all separated by a single space. Since -1 is used as an indication whether the left or 7 | right node data exist for root, it will not be a part of the node data. 8 | 9 | Output Format: 10 | The only line of output prints the post-order traversal of the given binary tree. 11 | 12 | Constraints: 13 | 1 <= N <= 10^6 14 | Where N is the total number of nodes in the binary tree. 15 | 16 | Time Limit: 1 sec 17 | 18 | Sample Input 1: 19 | 1 2 3 4 5 6 7 -1 -1 -1 -1 -1 -1 -1 -1 20 | 21 | Sample Output 1: 22 | 4 5 2 6 7 3 1 23 | 24 | 25 | Sample Input 2: 26 | 5 6 10 2 3 -1 -1 -1 -1 -1 9 -1 -1 27 | 28 | Sample Output 2: 29 | 2 9 3 6 10 5 30 | */ 31 | 32 | /********************************************************** 33 | Following is the Binary Tree Node class structure 34 | 35 | template 36 | class BinaryTreeNode { 37 | public : 38 | T data; 39 | BinaryTreeNode *left; 40 | BinaryTreeNode *right; 41 | 42 | BinaryTreeNode(T data) { 43 | this -> data = data; 44 | left = NULL; 45 | right = NULL; 46 | } 47 | }; 48 | 49 | ***********************************************************/ 50 | 51 | void postOrder(BinaryTreeNode *root) { 52 | // Write your code here 53 | if(root == NULL) { 54 | return; 55 | } 56 | 57 | postOrder(root -> left); 58 | postOrder(root -> right); 59 | cout << root -> data << " "; 60 | 61 | return; 62 | } 63 | -------------------------------------------------------------------------------- /cpp/PreOrder binary tree.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Preorder Binary Tree 3 | You are given the root node of a binary tree. Print its preorder traversal. 4 | 5 | Input Format: 6 | The first and the only line of input will contain the node data, all separated by a single space. Since -1 is used as an indication whether the left or 7 | right node data exist for root, it will not be a part of the node data. 8 | 9 | Output Format: 10 | The only line of output prints the preorder traversal of the given binary tree. 11 | 12 | Constraints: 13 | 1 <= N <= 10^6 14 | Where N is the total number of nodes in the binary tree. 15 | 16 | Time Limit: 1 sec 17 | 18 | Sample Input 1: 19 | 1 2 3 4 5 6 7 -1 -1 -1 -1 -1 -1 -1 -1 20 | 21 | Sample Output 1: 22 | 1 2 4 5 3 6 7 23 | 24 | 25 | Sample Input 2: 26 | 5 6 10 2 3 -1 -1 -1 -1 -1 9 -1 -1 27 | 28 | Sample Output 2: 29 | 5 6 2 3 9 10 30 | */ 31 | 32 | /*********************************************************** 33 | Following is the Binary Tree Node class structure 34 | 35 | template 36 | class BinaryTreeNode { 37 | public : 38 | T data; 39 | BinaryTreeNode *left; 40 | BinaryTreeNode *right; 41 | 42 | BinaryTreeNode(T data) { 43 | this -> data = data; 44 | left = NULL; 45 | right = NULL; 46 | } 47 | }; 48 | 49 | ************************************************************/ 50 | 51 | void preOrder(BinaryTreeNode *root) { 52 | // Write your code here 53 | if(root == NULL) { 54 | return; 55 | } 56 | 57 | cout << root -> data << " "; 58 | preOrder(root -> left); 59 | preOrder(root -> right); 60 | } 61 | -------------------------------------------------------------------------------- /cpp/Quick_Sort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int partition(int arr[], int start, int end) 5 | { 6 | 7 | int pivot = arr[start]; 8 | 9 | int count = 0; 10 | for (int i = start + 1; i <= end; i++) { 11 | if (arr[i] <= pivot) 12 | count++; 13 | } 14 | 15 | 16 | int pivotIndex = start + count; 17 | swap(arr[pivotIndex], arr[start]); 18 | 19 | int i = start, j = end; 20 | 21 | while (i < pivotIndex && j > pivotIndex) { 22 | 23 | while (arr[i] <= pivot) { 24 | i++; 25 | } 26 | 27 | while (arr[j] > pivot) { 28 | j--; 29 | } 30 | 31 | if (i < pivotIndex && j > pivotIndex) { 32 | swap(arr[i++], arr[j--]); 33 | } 34 | } 35 | 36 | return pivotIndex; 37 | } 38 | 39 | void quickSort(int arr[], int start, int end) 40 | { 41 | 42 | if (start >= end) 43 | return; 44 | 45 | int p = partition(arr, start, end); 46 | 47 | 48 | quickSort(arr, start, p - 1); 49 | 50 | quickSort(arr, p + 1, end); 51 | } 52 | 53 | int main() 54 | { 55 | 56 | int arr[] = { 9, 3, 4, 2, 1, 8 }; 57 | int n = 6; 58 | 59 | quickSort(arr, 0, n - 1); 60 | 61 | for (int i = 0; i < n; i++) { 62 | cout << arr[i] << " "; 63 | } 64 | 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /cpp/Remove leaf node.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Remove Leaf nodes 3 | Given a binary tree, remove all leaf nodes from it. Leaf nodes are those nodes, which don't have any children. 4 | 5 | Note: 6 | 1. Root will also be a leaf node if it doesn't have left and right child. 7 | 2. You don't need to print the tree, just remove all leaf nodes and return the updated root. 8 | 9 | Input format: 10 | The first line of input contains data of the nodes of the tree in level order form. The data of the nodes of the tree is separated by space. 11 | If any node does not have a left or right child, take -1 in its place. Since -1 is used as an indication whether the left or right nodes exist, therefore, it will not be a part of the data of any node. 12 | 13 | Output Format: 14 | The updated binary tree, after removing leaf nodes, is printed level wise. Each level is printed in new line. 15 | 16 | Constraints 17 | Time Limit: 1 second 18 | 19 | Sample Input 1: 20 | 8 3 10 1 6 -1 14 -1 -1 4 7 13 -1 -1 -1 -1 -1 -1 -1 21 | 22 | Sample Output 1: 23 | 8 24 | 3 10 25 | 6 14 26 | */ 27 | 28 | /********************************************************** 29 | Following is the Binary Tree Node class structure 30 | 31 | template 32 | class BinaryTreeNode { 33 | public : 34 | T data; 35 | BinaryTreeNode *left; 36 | BinaryTreeNode *right; 37 | 38 | BinaryTreeNode(T data) { 39 | this -> data = data; 40 | left = NULL; 41 | right = NULL; 42 | } 43 | }; 44 | 45 | ***********************************************************/ 46 | 47 | BinaryTreeNode* removeLeafNodes(BinaryTreeNode *root) { 48 | // Write your code here 49 | //corner case 50 | if(root == NULL) { 51 | return root; 52 | } 53 | // A node will be leaf if it has no children 54 | if(!root -> left and !root -> right) { 55 | return NULL; 56 | } 57 | 58 | root -> left = removeLeafNodes(root -> left); 59 | root -> right = removeLeafNodes(root -> right); 60 | 61 | return root; 62 | } 63 | -------------------------------------------------------------------------------- /cpp/Seive.cpp: -------------------------------------------------------------------------------- 1 | /* If a number n is not a prime, it can be factored into two factors a and b: 2 | 3 | n = a*b 4 | 5 | If both a and b were greater than the square root of n, a*b would be greater 6 | than n. So at least one of those factors must be less or equal to the square 7 | root of n, and to check if n is prime, we only need to test for factors less 8 | than or equal to the square root. 9 | 10 | */ 11 | 12 | #include 13 | using namespace std; 14 | int arr[10000005]; 15 | int main() 16 | { 17 | int n,i,j; 18 | cin >> n; // i.e Prime Till n 19 | memset(arr,0,n*sizeof(int)); // It's better to make bool array. 20 | for(i=2;i*i<=n;i++) 21 | { 22 | if( arr[i] == 0) 23 | { 24 | // More efficient 25 | // Factors less than i*i will already covered by smallers numbers. 26 | // E.g. say i=7. So, we start from 49 and 14,21,28,35,42 were 27 | // already marked as not prime by 2,3,4,5,6 respectively. 28 | for(j=i*i;j<=n;j+=i) 29 | arr[j]=1; 30 | 31 | // Less efficient 32 | // for(j=2;i*j<=n;j++) 33 | // arr[i*j]=1; 34 | } 35 | } 36 | int count=0; 37 | for(i=2;i 46 | class BinaryTreeNode { 47 | public : 48 | T data; 49 | BinaryTreeNode *left; 50 | BinaryTreeNode *right; 51 | 52 | BinaryTreeNode(T data) { 53 | this -> data = data; 54 | left = NULL; 55 | right = NULL; 56 | } 57 | }; 58 | 59 | ***********************************************************/ 60 | 61 | int getSum(BinaryTreeNode* root) { 62 | // Write your code here 63 | //corner case 64 | if(root == NULL) { 65 | return 0; 66 | } 67 | 68 | return root -> data + getSum(root -> left) + getSum(root -> right); 69 | } 70 | -------------------------------------------------------------------------------- /cpp/binarysearch.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int Arr[15] = {6,8,13,17,20,22,25,28,30,35}, low = 0 , high = 9 , mid , srch; 7 | cout << "Enter the Element to search : "; 8 | cin >> srch; 9 | 10 | while(low <= high) 11 | { 12 | mid = (low + high)/2; 13 | if(srch == Arr[mid]) 14 | { 15 | cout << "Search successful." << endl; 16 | cout << "The Element is found at " << mid << endl; 17 | return 0; 18 | } 19 | else if(srch < Arr[mid]) 20 | { 21 | high = mid - 1; 22 | } 23 | else 24 | { 25 | low = mid + 1; 26 | } 27 | } 28 | cout << "Search unsuccessful." << endl; 29 | cout << "Element not found." << endl; 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /cpp/binarytodecimal.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "stack.cpp" 3 | using namespace std; 4 | class binary{ 5 | int num,bit,del; 6 | stackst; 7 | public: 8 | void read(); 9 | void display();}; 10 | 11 | void binary::read(){ 12 | cout<<"enter the decimal number\n"; 13 | cin>>num; 14 | dec=num; 15 | while(num>0){ 16 | bit=num%2; 17 | s1.push(bit); 18 | num=num/2;}} 19 | 20 | void binary::displaty(){ 21 | cout<<"\n the binary of the vdecimal number"< 2 | #include "stack.cpp" 3 | using namespace std; 4 | template 5 | class binary 6 | { 7 | T num,bit,dec; 8 | stack st; 9 | public: 10 | void read(); 11 | void display();}; 12 | template 13 | void binary::read() 14 | { 15 | cout<<"enter decimal number:"; 16 | cin>>num; 17 | dec=num; 18 | while(num>0) 19 | { 20 | bit=num%2; 21 | st.push(bit); 22 | num=num/2;}} 23 | 24 | template 25 | void binary::display() 26 | { 27 | cout<<"\n the binary of decimal number "< h; 36 | 37 | h.read(); 38 | h.display(); 39 | return 0;} 40 | -------------------------------------------------------------------------------- /cpp/diameterOfATree.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | int diameter(TreeNode* root,int& height){ 3 | if(root == NULL){ 4 | height=0; 5 | return 0; 6 | } 7 | int lh=0,rh=0; 8 | int lDiameter = diameter(root->left,lh); 9 | int rDiameter = diameter(root->right,rh); 10 | int currDiameter = lh+rh; 11 | height = max(rh,lh)+1; 12 | return max(currDiameter,max(lDiameter,rDiameter)); 13 | } 14 | public: 15 | int diameterOfBinaryTree(TreeNode* root) { 16 | int height=0; 17 | return diameter(root,height); 18 | } 19 | }; -------------------------------------------------------------------------------- /cpp/largest_numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | float a, b, c; 6 | cin >> a >> b >> c; 7 | if(a >= b && a >= c) 8 | cout << "Largest number: " << a; 9 | if(b >= a && b >= c) 10 | cout << "Largest number: " << b; 11 | if(c >= a && c >= b) 12 | cout << "Largest number: " << c; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /cpp/lcm_hcf.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void main(){ 5 | int m, n, a, b, temp; 6 | 7 | START: 8 | printf("\nEnter the numbers m and n :"); 9 | scanf("%d%d",&m,&n); 10 | a = n; b = m; 11 | if (m*n == 0) 12 | printf("HCF and LCM cannot be enumerated for 0"); 13 | else{ 14 | while (n>0){ 15 | temp = n; 16 | n = m % n; 17 | m = temp; 18 | } 19 | printf("HCF = %d\t LCM = %d\n",m,a*b/m); 20 | 21 | goto START; 22 | } 23 | _getch(); 24 | 25 | 26 | } -------------------------------------------------------------------------------- /cpp/maxDepthofATree.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | void maxdepth(TreeNode* root,int &ans, int currHeight){ 3 | if(root==NULL) 4 | return ; 5 | ans = max(ans,currHeight); 6 | if(root->left) 7 | maxdepth(root->left,ans,currHeight+1); 8 | if(root->right) 9 | maxdepth(root->right,ans,currHeight+1); 10 | } 11 | public: 12 | int maxDepth(TreeNode* root) { 13 | if(root == NULL) 14 | return 0; 15 | 16 | return 1 + max(maxDepth(root->left),maxDepth(root->right)); 17 | } 18 | }; -------------------------------------------------------------------------------- /cpp/middleOfLinkedList.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | ListNode* middleNode(ListNode* head) { 4 | ListNode* fast = head; 5 | ListNode* slow = head; 6 | 7 | while(fast && fast->next){ 8 | slow = slow->next; 9 | fast = fast->next->next; 10 | } 11 | return slow; 12 | } 13 | }; -------------------------------------------------------------------------------- /cpp/minStack.cpp: -------------------------------------------------------------------------------- 1 | class MinStack { 2 | public: 3 | stack> st; 4 | MinStack() { 5 | 6 | } 7 | 8 | void push(int val) { 9 | if(st.empty()){ 10 | st.push({val,val}); 11 | return ; 12 | } 13 | if(st.top().second>v; 10 | for(int i =0; inext); 10 | if(head->val != p->val) { 11 | return false; 12 | } 13 | head = head->next; 14 | return isPal; 15 | } 16 | }; -------------------------------------------------------------------------------- /cpp/postfixevaluation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "stack1.cpp" 4 | using namespace std; 5 | class postfixevaluation{ 6 | char exp[25]; 7 | int i,j,k,len; 8 | int op1,op2,val,result; 9 | stack st; 10 | public: 11 | void read(); 12 | void display(); 13 | void doevaluation();}; 14 | 15 | 16 | 17 | void postfixevaluation :: read(){ 18 | cout<<"enter the postfix expression:\n"; 19 | cin>>exp; 20 | len = strlen(exp); 21 | } 22 | 23 | void postfixevaluation::display(){ 24 | result=st.pop(); 25 | cout<<"\n the evaluated value of the postfix expression "< 2 | #include 3 | #define size 5 4 | using namespace std; 5 | template 6 | class queue 7 | { 8 | T q[size]; 9 | int front,rear; 10 | public: 11 | queue() 12 | { 13 | front=-1; 14 | rear=-1; 15 | } 16 | void insert (T data); 17 | void del(); 18 | void display(); 19 | }; 20 | template 21 | void queue::insert(T data) 22 | { 23 | if((rear==size-1)&&(front==0)) 24 | { 25 | cout<<"Queue is full"; 26 | } 27 | else 28 | { 29 | rear=rear+1; 30 | q[rear]=data; 31 | cout< 36 | void queue::del() 37 | { 38 | int y; 39 | if((front==rear+1 && front==-1)){ 40 | cout<<"queue is empty"< 62 | void queue::display() 63 | { 64 | int z; 65 | if((front==-1)&&(rear==-1)) 66 | { 67 | cout<<"Queue is empty"; 68 | } 69 | else 70 | { 71 | cout<<"elements are"; 72 | for(z=0;z<=rear;z++) 73 | { 74 | cout<<"\n"<q1; 82 | int data; 83 | do 84 | { 85 | cout<<"\n enter your choice:\n 1.insert \n 2.delete \n 3.display\n"; 86 | cin>>ch; 87 | switch(ch) 88 | { 89 | case 1:cout<<"\n enter the element to insert"; 90 | cin>>data; 91 | q1.insert(data); 92 | break; 93 | case 2:q1.del(); 94 | break; 95 | case 3:q1.display(); 96 | break; 97 | default:cout<<"wrong input"; 98 | } 99 | } 100 | while(ch); 101 | return 0; 102 | } 103 | -------------------------------------------------------------------------------- /cpp/radix-sort.cpp: -------------------------------------------------------------------------------- 1 | // C++ implementation of Radix Sort 2 | 3 | #include 4 | using namespace std; 5 | 6 | // A utility function to get maximum value in arr[] 7 | int getMax(int arr[], int n) 8 | { 9 | int mx = arr[0]; 10 | for (int i = 1; i < n; i++) 11 | if (arr[i] > mx) 12 | mx = arr[i]; 13 | return mx; 14 | } 15 | 16 | // A function to do counting sort of arr[] according to 17 | // the digit represented by exp. 18 | void countSort(int arr[], int n, int exp) 19 | { 20 | int output[n]; // output array 21 | int i, count[10] = { 0 }; 22 | 23 | // Store count of occurrences in count[] 24 | for (i = 0; i < n; i++) 25 | count[(arr[i] / exp) % 10]++; 26 | 27 | // Change count[i] so that count[i] now contains actual 28 | // position of this digit in output[] 29 | for (i = 1; i < 10; i++) 30 | count[i] += count[i - 1]; 31 | 32 | // Build the output array 33 | for (i = n - 1; i >= 0; i--) { 34 | output[count[(arr[i] / exp) % 10] - 1] = arr[i]; 35 | count[(arr[i] / exp) % 10]--; 36 | } 37 | 38 | // Copy the output array to arr[], so that arr[] now 39 | // contains sorted numbers according to current digit 40 | for (i = 0; i < n; i++) 41 | arr[i] = output[i]; 42 | } 43 | 44 | // The main function to that sorts arr[] of size n using 45 | // Radix Sort 46 | void radixsort(int arr[], int n) 47 | { 48 | // Find the maximum number to know number of digits 49 | int m = getMax(arr, n); 50 | 51 | // Do counting sort for every digit. Note that instead 52 | // of passing digit number, exp is passed. exp is 10^i 53 | // where i is current digit number 54 | for (int exp = 1; m / exp > 0; exp *= 10) 55 | countSort(arr, n, exp); 56 | } 57 | 58 | // A utility function to print an array 59 | void print(int arr[], int n) 60 | { 61 | for (int i = 0; i < n; i++) 62 | cout << arr[i] << " "; 63 | } 64 | 65 | // Driver Code 66 | int main() 67 | { 68 | int arr[] = { 170, 45, 75, 90, 802, 24, 2, 66 }; 69 | int n = sizeof(arr) / sizeof(arr[0]); 70 | 71 | // Function Call 72 | radixsort(arr, n); 73 | print(arr, n); 74 | return 0; 75 | } 76 | -------------------------------------------------------------------------------- /cpp/sqrt.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // Recursive function that returns square root 5 | // of a number with precision upto 5 decimal places 6 | double Square(double n, double i, double j) 7 | { 8 | double mid = (i + j) / 2; 9 | double mul = mid * mid; 10 | 11 | // If mid itself is the square root, 12 | // return mid 13 | if ((mul == n) || (abs(mul - n) < 0.00001)) 14 | return mid; 15 | 16 | // If mul is less than n, recur second half 17 | else if (mul < n) 18 | return Square(n, mid, j); 19 | 20 | // Else recur first half 21 | else 22 | return Square(n, i, mid); 23 | } 24 | 25 | // Function to find the square root of n 26 | void findSqrt(double n) 27 | { 28 | double i = 1; 29 | 30 | // While the square root is not found 31 | bool found = false; 32 | while (!found) { 33 | 34 | // If n is a perfect square 35 | if (i * i == n) { 36 | cout << fixed << setprecision(0) << i; 37 | found = true; 38 | } 39 | else if (i * i > n) { 40 | 41 | // Square root will lie in the 42 | // interval i-1 and i 43 | double res = Square(n, i - 1, i); 44 | cout << fixed << setprecision(5) << res; 45 | found = true; 46 | } 47 | i++; 48 | } 49 | } 50 | 51 | // Driver code 52 | int main() 53 | { 54 | double n = 3; 55 | 56 | findSqrt(n); 57 | 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /cpp/toposort using bfs.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | class Graph { 8 | int V; 9 | vector> adj; 10 | 11 | public: 12 | Graph(int vertices) : V(vertices), adj(vertices) {} 13 | 14 | void addEdge(int u, int v) { 15 | adj[u].push_back(v); 16 | } 17 | 18 | vector topologicalSort() { 19 | vector inDegree(V, 0); 20 | for (int u = 0; u < V; ++u) { 21 | for (int v : adj[u]) { 22 | inDegree[v]++; 23 | } 24 | } 25 | 26 | queue q; 27 | for (int u = 0; u < V; ++u) { 28 | if (inDegree[u] == 0) { 29 | q.push(u); 30 | } 31 | } 32 | 33 | vector topoOrder; 34 | while (!q.empty()) { 35 | int u = q.front(); 36 | q.pop(); 37 | topoOrder.push_back(u); 38 | 39 | for (int v : adj[u]) { 40 | if (--inDegree[v] == 0) { 41 | q.push(v); 42 | } 43 | } 44 | } 45 | 46 | if (topoOrder.size() != V) { 47 | cout << "The graph contains a cycle!" << endl; 48 | return vector(); 49 | } 50 | 51 | return topoOrder; 52 | } 53 | }; 54 | 55 | int main() { 56 | int V, E; 57 | cin >> V >> E; 58 | Graph graph(V); 59 | 60 | for (int i = 0; i < E; ++i) { 61 | int u, v; 62 | cin >> u >> v; 63 | graph.addEdge(u, v); 64 | } 65 | 66 | vector topoOrder = graph.topologicalSort(); 67 | if (!topoOrder.empty()) { 68 | for (int u : topoOrder) { 69 | cout << u << " "; 70 | } 71 | cout << endl; 72 | } 73 | 74 | return 0; 75 | } 76 | -------------------------------------------------------------------------------- /cpp/uniquePathInAGrid.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | int dp[101][101]; 3 | public: Solution(){ 4 | for(int i=0;i<101;i++) 5 | for(int j=0;j<101;j++) 6 | dp[i][j]=-1; 7 | } 8 | public: 9 | int uniquePaths(int m, int n) { 10 | vector> dp(m,vector(n,0)); 11 | for(int i=0;i 2 | #include 3 | 4 | void printBinary(int n){ 5 | char bin[33]; 6 | bin[32] = '\0'; 7 | int count = sizeof(int)* 8; 8 | while (count-- > 0){ 9 | if (n & 1) 10 | bin[count] = '1'; 11 | else 12 | bin[count] = '0'; 13 | n >>= 1; 14 | } 15 | puts(bin); 16 | } 17 | 18 | 19 | void main(){ 20 | 21 | 22 | 23 | int c = 0, n = -4; 24 | printf("%d\n", n); 25 | while (c<32){ 26 | n = n >> 1; 27 | printf("%10d\t", n); 28 | printBinary(n); 29 | c++; 30 | } 31 | printf("%d",c); 32 | _getch(); 33 | 34 | 35 | 36 | } -------------------------------------------------------------------------------- /dart/hello.dart: -------------------------------------------------------------------------------- 1 | void main() { 2 | print("Hello World"); 3 | } 4 | -------------------------------------------------------------------------------- /data_structure/Insertion.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int n,arr[100],temp,i,j; 6 | cin >> n; // No. of integers 7 | for(i=0;i> arr[i]; 9 | 10 | for(i=1;i=0 && arr[j] > temp ) 15 | { 16 | arr[j+1]=arr[j]; 17 | j--; 18 | } 19 | arr[j+1]=temp; 20 | } 21 | 22 | for(i=0;i 2 | 3 | void merge(int a[],int l,int m,int r){ 4 | 5 | int a1[m-l+1],a2[r-m],i,j,k; for(i=0;i<(m-l+1);i++) 6 | 7 | a1[i]=a[l+i]; 8 | 9 | for(j=0;j<(r-m);j++){ 10 | 11 | a2[j]=a[m+j+1]; 12 | 13 | } 14 | 15 | i=0;j=0;k=l; 16 | 17 | while(i 2 | int partition(int [], int, int); 3 | void qsort(int [], int, int); 4 | void swap(int *, int *); 5 | void print(int [],int); 6 | int main() { 7 | int n; 8 | printf("Enter the number of elements in the array : "); 9 | scanf("%d",&n); 10 | int a[n]; 11 | printf("Enter the array elements : "); 12 | for(int i=0;ikey && j>l) 35 | j--; 36 | if(i 2 | #define MAX 10 3 | void RestoreHeapUp(int *,int); 4 | void RestoreHeapDown(int*,int,int); 5 | 6 | int main() { 7 | int Heap[MAX],n,i,j; 8 | 9 | printf("\n Enter the number of elements : "); 10 | scanf("%d",&n); 11 | printf("\n Enter the elements : "); 12 | for(i=1;i<=n;i++) { 13 | scanf("%d",&Heap[i]); 14 | RestoreHeapUp(Heap, i); 15 | } 16 | 17 | j=n; 18 | for(i=1;i<=j;i++) { 19 | int temp; 20 | temp=Heap[1]; 21 | Heap[1]= Heap[n]; 22 | Heap[n]=temp; 23 | n = n-1; 24 | RestoreHeapDown(Heap,1,n); 25 | } 26 | n=j; 27 | printf("\n The sorted elements are: "); 28 | for(i=1;i<=n;i++) 29 | printf("%4d",Heap[i]); 30 | return 0; 31 | } 32 | 33 | void RestoreHeapUp(int *Heap,int index) { 34 | int val = Heap[index]; 35 | while( (index>1) && (Heap[index/2] < val) ) { 36 | Heap[index]=Heap[index/2]; 37 | index /= 2; 38 | } 39 | Heap[index]=val; 40 | } 41 | 42 | void RestoreHeapDown(int *Heap,int index,int n) { 43 | int val = Heap[index]; 44 | int j=index*2; 45 | while(j<=n) { 46 | if( (j 2 | 3 | #include 4 | 5 | #include 6 | 7 | float compute(char symbol, float op1, float op2) 8 | 9 | { 10 | 11 | switch (symbol) 12 | 13 | { 14 | 15 | case '+': return op1 + op2; 16 | 17 | case '-': return op1 - op2; 18 | 19 | case '*': return op1 * op2; 20 | 21 | case '/': return op1 / op2; 22 | 23 | case '$': 24 | 25 | case '^': return pow(op1,op2); 26 | 27 | default : return 0; 28 | 29 | } 30 | 31 | } 32 | 33 | void main() 34 | 35 | { 36 | 37 | float s[20], res, op1, op2; 38 | 39 | int top, i; 40 | 41 | char postfix[20], symbol; 42 | 43 | printf("\nEnter the postfix expression:\n"); 44 | 45 | scanf ("%s", postfix); 46 | 47 | top=-1; 48 | 49 | for (i=0; i 2 | #include 3 | #include 4 | char c[50]; 5 | int top=-1; 6 | float op1,op2,r,a; 7 | float s[50]; 8 | int push(int top,float tok){ 9 | s[++top]=tok; 10 | return top; 11 | } 12 | float pop(int top){ 13 | r=s[top]; 14 | return r; 15 | } 16 | int operate(int top,char tok){ 17 | if(top==-1) 18 | return top; 19 | op1=pop(top); 20 | top=top-1; 21 | op2=pop(top); 22 | top=top-1; 23 | switch(tok){ 24 | case '+':a=op2+op1; 25 | top=push(top,a); 26 | break; 27 | case '-':a=op2-op1; 28 | top=push(top,a); 29 | break; 30 | case '*':a=op2*op1; 31 | top=push(top,a); 32 | break; 33 | case '/':a=op2/op1; 34 | top=push(top,a); 35 | break; 36 | } 37 | return top; 38 | } 39 | int main(){ 40 | printf("Enter postfix expression:\n"); 41 | scanf("%s",c); 42 | for(int i=0;i 2 | #include 3 | #define size 50 4 | 5 | int Q[size], rear=-1,front=0; 6 | 7 | int isempty() { 8 | if(front == -1 || front > rear) 9 | return 1; 10 | else 11 | return 0; 12 | } 13 | 14 | int isfull() { 15 | if(rear == size - 1) 16 | return 1; 17 | else 18 | return 0; 19 | } 20 | 21 | void InsertQ(int item) { 22 | if(isfull()) 23 | printf("Queue is Full"); 24 | else { 25 | if(front == -1) 26 | front = 0; 27 | rear = rear+1; 28 | Q[rear] = item; 29 | } 30 | 31 | } 32 | 33 | int DeleteQ() { 34 | int index = -1; 35 | if(isempty()) { 36 | printf("Queue is empty"); 37 | } 38 | else { 39 | index = front++; 40 | } 41 | return index; 42 | } 43 | 44 | void Display() { 45 | 46 | if(isempty()){ 47 | printf("Queue is empty"); 48 | } 49 | int i; 50 | printf("\n Queue :"); 51 | for (i = front; i != rear+1; i = (i + 1) % size) { 52 | printf("%d ", Q[i]); 53 | } 54 | } 55 | 56 | int main() { 57 | int ch; 58 | printf("Queue"); 59 | do { 60 | printf("\n1. Insert 2. Delete 3.Display 4.Exit \n"); 61 | scanf("%d",&ch); 62 | switch(ch) { 63 | case 1: { 64 | int item; 65 | printf("Item to be entered : "); 66 | scanf("%d",&item); 67 | InsertQ(item); 68 | break; 69 | } 70 | case 2: { 71 | int val = DeleteQ(); 72 | if(val != -1) 73 | printf("The deleted item is %d",Q[val]); 74 | break; 75 | } 76 | case 3: 77 | Display(); 78 | break; 79 | case 4: 80 | exit(0); 81 | } 82 | } while(1); 83 | return 0; 84 | } 85 | -------------------------------------------------------------------------------- /data_structure/quicksort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | void quicksort(int number[25],int first,int last){ 3 | int i, j, pivot, temp; 4 | if(firstnumber[pivot]) 12 | j--; 13 | if(i 2 | #define n 50 3 | int s[n],top=0,item; 4 | 5 | int IsEmpty() { 6 | if(top==0) 7 | return 1; 8 | else 9 | return 0; 10 | } 11 | 12 | int IsFull() { 13 | if(top==n) 14 | return 1; 15 | else 16 | return 0; 17 | } 18 | 19 | void Push(int item) { 20 | if(IsFull()) 21 | printf("Stack is full"); 22 | else{ 23 | s[top]=item; 24 | top+=1; 25 | } 26 | } 27 | 28 | int Pop() { 29 | int index=-1; 30 | if(IsEmpty()) 31 | printf("Stack is empty"); 32 | else { 33 | top-=1; 34 | index=top; 35 | } 36 | return index; 37 | } 38 | 39 | int Peek() { 40 | int index=-1; 41 | if(IsEmpty()) 42 | printf("Stack is empty"); 43 | else 44 | index=top-1; 45 | return index; 46 | } 47 | 48 | void Display() { 49 | if(IsEmpty()) 50 | printf("Stack is empty"); 51 | else { 52 | printf("Stack contents are:"); 53 | for(int i=top-1;i>=0;i--) 54 | printf("%d ",s[i]);} 55 | } 56 | void main() { 57 | int ch,val,p; 58 | do { 59 | printf("\n1.Push\n2.Pop\n3.Peek\n4.Display\n5.Exit\n"); 60 | printf("Enter your choice:"); 61 | scanf("%d",&ch); 62 | 63 | switch(ch) { 64 | case 1: 65 | printf("Enter the item to be pushed:"); 66 | scanf("%d",&item); 67 | Push(item); 68 | break; 69 | case 2: 70 | val=Pop(); 71 | if(val!=-1) 72 | printf("The popped value is:%d",s[val]); 73 | break; 74 | case 3: 75 | p=Peek(); 76 | if(p!=-1) 77 | printf("The top item is:%d",s[p]); 78 | break; 79 | case 4: 80 | Display(); 81 | break; 82 | case 5: 83 | break; 84 | } 85 | }while(ch!=5); 86 | } 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /data_structure/stackll.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct NODE { 5 | int info; 6 | struct NODE *link; 7 | } ; 8 | 9 | typedef struct NODE node; 10 | node *top=NULL; 11 | 12 | node *newnode(int val) { 13 | node *p; 14 | p=(node *)malloc(sizeof(node)); 15 | p->info=val; 16 | p->link=NULL; 17 | return p; 18 | } 19 | 20 | void Display() { 21 | node *curr; 22 | curr=top; 23 | while(curr!=NULL) { 24 | printf("%d", curr->info); 25 | curr=curr->link; 26 | if(curr !=NULL) 27 | printf(" --> "); 28 | } 29 | } 30 | 31 | void push(int item) { 32 | node *p; 33 | p=newnode(item); 34 | if(p==NULL) 35 | printf("overflow"); 36 | else 37 | p->info = item; 38 | p->link = top; 39 | top = p; 40 | } 41 | 42 | void pop() { 43 | node *ptr; 44 | ptr = top; 45 | if(ptr == NULL) 46 | printf("Underflow"); 47 | else 48 | ptr = top; 49 | top = top->link; 50 | free(ptr); 51 | } 52 | void main() { 53 | int ch,item; 54 | 55 | do { 56 | printf("\n1. Insert \n2. Delete\n3. Display\n4. Quit\nEnter your Choice : "); 57 | scanf("%d",&ch); 58 | switch(ch) { 59 | case 1: 60 | printf("\nvalue to be inserted:"); 61 | scanf("%d",&item); 62 | push(item); 63 | break; 64 | case 2: 65 | pop(); 66 | break; 67 | case 3: 68 | Display(); 69 | break; 70 | case 4: 71 | break; 72 | 73 | default:printf("Invalid choice"); 74 | } 75 | }while(ch!=4); 76 | 77 | } 78 | -------------------------------------------------------------------------------- /decimal_to_binary.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main(){ 5 | cout<<"Program to convert decimal to binary"<>n; 9 | int ans=0; 10 | int i=0; 11 | while(n!=0){ 12 | int bit=n&1; 13 | ans=(bit*pow(10,i))+ans; 14 | n=n>>1; 15 | i++; 16 | } 17 | cout<<"Answer is " <[] bucket = new ArrayList[n]; 12 | 13 | // Create empty buckets 14 | for (int i = 0; i < n; i++) 15 | bucket[i] = new ArrayList(); 16 | 17 | // Add elements into the buckets 18 | for (int i = 0; i < n; i++) { 19 | int bucketIndex = (int) arr[i] * n; 20 | bucket[bucketIndex].add(arr[i]); 21 | } 22 | 23 | // Sort the elements of each bucket 24 | for (int i = 0; i < n; i++) { 25 | Collections.sort((bucket[i])); 26 | } 27 | 28 | // Get the sorted array 29 | int index = 0; 30 | for (int i = 0; i < n; i++) { 31 | for (int j = 0, size = bucket[i].size(); j < size; j++) { 32 | arr[index++] = bucket[i].get(j); 33 | } 34 | } 35 | } 36 | 37 | // Driver code 38 | public static void main(String[] args) { 39 | BucketSort b = new BucketSort(); 40 | float[] arr = { (float) 0.42, (float) 0.32, (float) 0.33, (float) 0.52, (float) 0.37, (float) 0.47, 41 | (float) 0.51 }; 42 | b.bucketSort(arr, 7); 43 | 44 | for (float i : arr) 45 | System.out.print(i + " "); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /java/Check.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class Check 3 | { 4 | public static void main(String args[]) 5 | {Scanner sc=new Scanner(System.in); 6 | System.out.print("enter the no tobe checked"); 7 | int n=sc.nextInt(); 8 | if(n%2==0) 9 | System.out.println("EVEN"); 10 | else 11 | System.out.println("ODD"); 12 | sc.close(); 13 | 14 | } 15 | } -------------------------------------------------------------------------------- /java/DFS.java: -------------------------------------------------------------------------------- 1 | // Java program to print DFS 2 | // traversal from a given 3 | // graph 4 | import java.io.*; 5 | import java.util.*; 6 | 7 | // This class represents a 8 | // directed graph using adjacency 9 | // list representation 10 | class Graph { 11 | private int V; // No. of vertices 12 | 13 | // Array of lists for 14 | // Adjacency List Representation 15 | private LinkedList adj[]; 16 | 17 | // Constructor 18 | @SuppressWarnings("unchecked") Graph(int v) 19 | { 20 | V = v; 21 | adj = new LinkedList[v]; 22 | for (int i = 0; i < v; ++i) 23 | adj[i] = new LinkedList(); 24 | } 25 | 26 | // Function to add an edge into the graph 27 | void addEdge(int v, int w) 28 | { 29 | adj[v].add(w); // Add w to v's list. 30 | } 31 | 32 | // A function used by DFS 33 | void DFSUtil(int v, boolean visited[]) 34 | { 35 | // Mark the current node as visited and print it 36 | visited[v] = true; 37 | System.out.print(v + " "); 38 | 39 | // Recur for all the vertices adjacent to this 40 | // vertex 41 | Iterator i = adj[v].listIterator(); 42 | while (i.hasNext()) { 43 | int n = i.next(); 44 | if (!visited[n]) 45 | DFSUtil(n, visited); 46 | } 47 | } 48 | 49 | // The function to do DFS traversal. 50 | // It uses recursive 51 | // DFSUtil() 52 | void DFS(int v) 53 | { 54 | // Mark all the vertices as 55 | // not visited(set as 56 | // false by default in java) 57 | boolean visited[] = new boolean[V]; 58 | 59 | // Call the recursive helper 60 | // function to print DFS 61 | // traversal 62 | DFSUtil(v, visited); 63 | } 64 | 65 | // Driver's Code 66 | public static void main(String args[]) 67 | { 68 | Graph g = new Graph(4); 69 | 70 | g.addEdge(0, 1); 71 | g.addEdge(0, 2); 72 | g.addEdge(1, 2); 73 | g.addEdge(2, 0); 74 | g.addEdge(2, 3); 75 | g.addEdge(3, 3); 76 | 77 | System.out.println( 78 | "Following is Depth First Traversal " 79 | + "(starting from vertex 2)"); 80 | 81 | // Function call 82 | g.DFS(2); 83 | } 84 | } 85 | // This code is contributed by Aakash Hasija 86 | -------------------------------------------------------------------------------- /java/Employees.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | class Employee 3 | { 4 | 5 | void display() 6 | { 7 | 8 | System.out.println("Name of class is Employee."); 9 | 10 | } 11 | 12 | void calcSalary() 13 | { 14 | 15 | System.out.println("Salary of Employee is 10000"); 16 | 17 | } 18 | 19 | } 20 | 21 | class Engineer extends Employee 22 | { 23 | 24 | void calcSalary() 25 | { 26 | super.calcSalary(); 27 | System.out.println("Salary of Engineer is 20000"); 28 | 29 | } 30 | 31 | } 32 | class Employees 33 | { 34 | 35 | public static void main(String args[]) 36 | { 37 | 38 | Engineer e = new Engineer(); 39 | e.display(); 40 | e.calcSalary(); 41 | 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /java/FibonacciSeries.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | public class FibonacciSeries{ 3 | public static void main(String args[]){ 4 | int n; 5 | Scanner sc = new Scanner(System.in); 6 | System.out.println("Enter the value of n."); 7 | n= sc.nextInt(); 8 | int a = 0; 9 | int b = 1; 10 | System.out.println("The fibonacci series till term number "+n+" is:"); 11 | for(int i = 1; i <=(n+1)/2; i++){ 12 | System.out.print(a+" "); 13 | if(n%2!=0 && i==(n+1)/2){ 14 | break; 15 | } 16 | else{ 17 | System.out.print(b+" "); 18 | a+=b; 19 | b+=a; 20 | } 21 | 22 | } 23 | sc.close(); 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /java/InsertionSortExample.java: -------------------------------------------------------------------------------- 1 | public class InsertionSortExample { 2 | //program for insertion sort 3 | public static void main(String args[]){ 4 | int[] intArray = {20, 35, -17, 7, 55, 1, -22}; 5 | for(int firstUnsortedIndex = 1; firstUnsortedIndex < intArray.length; firstUnsortedIndex++){ 6 | 7 | int operand = intArray[firstUnsortedIndex]; 8 | int i; 9 | 10 | for( i = firstUnsortedIndex; i>0 && operand< intArray[i-1]; i--){ 11 | intArray[i] = intArray[i-1]; 12 | 13 | } 14 | intArray[i]= operand; 15 | } 16 | for(int i =0; i ll=new LinkedList(); 5 | System.out.println("Initial list of elements: "+ll); 6 | ll.add("Ravi"); 7 | ll.add("Vijay"); 8 | ll.add("Ajay"); 9 | System.out.println("After invoking add(E e) method: "+ll); 10 | //Adding an element at the specific position 11 | ll.add(1, "Gaurav"); 12 | System.out.println("After invoking add(int index, E element) method: "+ll); 13 | LinkedList ll2=new LinkedList(); 14 | ll2.add("Sonoo"); 15 | ll2.add("Hanumat"); 16 | //Adding second list elements to the first list 17 | ll.addAll(ll2); 18 | System.out.println("After invoking addAll(Collection c) method: "+ll); 19 | LinkedList ll3=new LinkedList(); 20 | ll3.add("John"); 21 | ll3.add("Rahul"); 22 | //Adding second list elements to the first list at specific position 23 | ll.addAll(1, ll3); 24 | System.out.println("After invoking addAll(int index, Collection c) method: "+ll); 25 | //Adding an element at the first position 26 | ll.addFirst("Lokesh"); 27 | System.out.println("After invoking addFirst(E e) method: "+ll); 28 | //Adding an element at the last position 29 | ll.addLast("Harsh"); 30 | System.out.println("After invoking addLast(E e) method: "+ll); 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /java/MergeSort.java: -------------------------------------------------------------------------------- 1 | public class MergeSort { 2 | public static void main(String[] args) { 3 | System.out.println("hey hey hey!"); 4 | int arr [] = {-1, 6, 7, 4, -3, 43}; 5 | mergeSort(arr, 0, arr.length); 6 | for(int i = 0; iarrIn[mid]){ 24 | return; 25 | } 26 | 27 | int i = start; 28 | int j = mid; 29 | int temp[] = new int[end - start]; 30 | int tempIndex = 0; 31 | 32 | while(i= arrIn[j] ? arrIn[i++] : arrIn[j++]; 34 | 35 | } 36 | System.arraycopy(arrIn, i,arrIn, start+tempIndex, mid-i); 37 | System.arraycopy(temp, 0, arrIn, start, tempIndex); 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /java/OddOrEven.java: -------------------------------------------------------------------------------- 1 | Class OddOrEven 2 | { 3 | public Static void main(String arg[]) 4 | { 5 | 6 | } 7 | } -------------------------------------------------------------------------------- /java/Sides.java: -------------------------------------------------------------------------------- 1 | abstract class Shape 2 | { 3 | void numberofSides(){} 4 | } 5 | 6 | class Rectangle extends Shape 7 | { 8 | void numberofSides() 9 | { 10 | System.out.println("Rectangle has 4 sides."); 11 | } 12 | } 13 | 14 | class Triangle extends Shape 15 | { 16 | void numberofSides() 17 | { 18 | System.out.println("Triangle has 3 sides."); 19 | } 20 | } 21 | 22 | class Hexagon extends Shape 23 | { 24 | void numberofSides() 25 | { 26 | System.out.println("Hexagon has 6 sides."); 27 | } 28 | } 29 | 30 | public class Sides { 31 | public static void main(String[] args) 32 | { 33 | Rectangle r = new Rectangle(); 34 | r.numberofSides(); 35 | Triangle t = new Triangle(); 36 | t.numberofSides(); 37 | Hexagon h = new Hexagon(); 38 | h.numberofSides(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /java/Sieve of Eratosthenes.java: -------------------------------------------------------------------------------- 1 | // Java program to print all primes smaller than or equal to 2 | // n using Sieve of Eratosthenes 3 | 4 | class SieveOfEratosthenes 5 | { 6 | void sieveOfEratosthenes(int n) 7 | { 8 | // Create a boolean array "prime[0..n]" and initialize 9 | // all entries it as true. A value in prime[i] will 10 | // finally be false if i is Not a prime, else true. 11 | boolean prime[] = new boolean[n+1]; 12 | for(int i=0;i<=n;i++) 13 | prime[i] = true; 14 | 15 | for(int p = 2; p*p <=n; p++) 16 | { 17 | // If prime[p] is not changed, then it is a prime 18 | if(prime[p] == true) 19 | { 20 | // Update all multiples of p 21 | for(int i = p*p; i <= n; i += p) 22 | prime[i] = false; 23 | } 24 | } 25 | 26 | // Print all prime numbers 27 | for(int i = 2; i <= n; i++) 28 | { 29 | if(prime[i] == true) 30 | System.out.print(i + " "); 31 | } 32 | } 33 | 34 | // Driver Program to test above function 35 | public static void main(String args[]) 36 | { 37 | int n = 30; 38 | System.out.print("Following are the prime numbers "); 39 | System.out.println("smaller than or equal to " + n); 40 | SieveOfEratosthenes g = new SieveOfEratosthenes(); 41 | g.sieveOfEratosthenes(n); 42 | } 43 | } 44 | 45 | // This code has been contributed by Amit Khandelwal. 46 | -------------------------------------------------------------------------------- /java/SpecialNum.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class SpecialNum{ 3 | public static int fact(int x){ 4 | if(x == 0 || x == 1){ 5 | return 1; 6 | 7 | } 8 | return x*(fact(x-1)); 9 | } 10 | public static void main(String [] args){ 11 | Scanner sc = new Scanner(System.in); 12 | int x, num, digit, sum = 0; 13 | System.out.print("Enter the number: "); 14 | x = sc.nextInt(); 15 | num = x; 16 | while(num > 0){ 17 | digit = num%10; 18 | sum += fact(digit); 19 | num = num/10; 20 | } 21 | if(sum == x){ 22 | System.out.println(x + " is a Special number."); 23 | }else{ 24 | System.out.println(x + " is not a Special number."); 25 | } 26 | 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /java/StringToInt.java: -------------------------------------------------------------------------------- 1 | public class StringToIntExample1{ 2 | public static void main(String args[]){ 3 | //Declaring String variable 4 | String s="200"; 5 | //Converting String into int using Integer.parseInt() 6 | int i=Integer.parseInt(s); 7 | //Printing value of i 8 | System.out.println(i); 9 | }} 10 | -------------------------------------------------------------------------------- /java/Sum.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class Sum 3 | { 4 | public static void main(String args[]) 5 | {int a,b; 6 | Scanner sc=new Scanner(System.in); 7 | System.out.println("enter the nos"); 8 | a=sc.nextInt(); 9 | b=sc.nextInt(); 10 | int c=a+b; 11 | System.out.println("The sum is "+c); 12 | sc.close(); 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /java/Test.java: -------------------------------------------------------------------------------- 1 | class Single 2 | { 3 | void msg1() 4 | { 5 | System.out.println("hello world"); 6 | } 7 | } 8 | class Person extends Single 9 | {void msg2() 10 | { 11 | System.out.println("good morning"); 12 | } 13 | } 14 | class Teacher extends Single 15 | { 16 | void msg3() 17 | { 18 | System.out.println("good evening"); 19 | } 20 | } 21 | class Test 22 | { 23 | public static void main(String args[]) 24 | { 25 | Teacher t=new Teacher(); 26 | Person p=new Person(); 27 | t.msg1(); 28 | t.msg3(); 29 | p.msg1(); 30 | p.msg2(); 31 | } 32 | } -------------------------------------------------------------------------------- /java/Trafficlight.java: -------------------------------------------------------------------------------- 1 | import java.awt.*; 2 | import java.awt.event.*; 3 | class TrafficLight extends Frame implements ItemListener { 4 | String clr=""; 5 | TrafficLight() { 6 | Checkbox c1,c2,c3; 7 | CheckboxGroup cbg=new CheckboxGroup(); 8 | c1=new Checkbox("red",true,cbg); 9 | c2=new Checkbox("green",true,cbg); 10 | c3=new Checkbox("yellow",true,cbg); 11 | setSize(500,500); 12 | setTitle("Traffic Signal"); 13 | setVisible(true); 14 | setLayout(new FlowLayout(FlowLayout.CENTER)); 15 | add(c1); 16 | add(c2); 17 | add(c3); 18 | c1.addItemListener(this); 19 | c2.addItemListener(this); 20 | c3.addItemListener(this); 21 | addWindowListener(new WindowAdapter() { 22 | public void windowClosing(WindowEvent e) { 23 | System.exit(0); 24 | } 25 | }); 26 | } 27 | public static void main(String[] args) { 28 | new TrafficLight(); 29 | } 30 | 31 | public void itemStateChanged(ItemEvent e) { 32 | clr=(e.getItem()).toString(); 33 | repaint(); 34 | } 35 | 36 | public void paint(Graphics g) { 37 | g.drawString("Traffic signals",200,250); 38 | g.drawRect(200,80,100,250); 39 | g.setColor(Color.black); 40 | g.fillRect(200,80,100,250); 41 | if(clr.equals("red")) { 42 | g.setColor(Color.red); 43 | g.fillOval(225,125,50,50); 44 | } 45 | if(clr.equals("green")) { 46 | g.setColor(Color.green); 47 | g.fillOval(225,175,50,50); 48 | } 49 | if(clr.equals("yellow")) { 50 | g.setColor(Color.yellow); 51 | g.fillOval(225,225,50,50); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /java/area_shapes.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class area_shapes { 3 | public static void main(String args[]) 4 | { 5 | Scanner sc = new Scanner(System.in); 6 | System.out.println("1.Circle/2.Rectangle/3.Triangle"); 7 | System.out.println("Select an option(1/2/3) :"); 8 | int a = sc.nextInt(); 9 | area_shapes obj = new area_shapes(); 10 | if (a==1) { 11 | System.out.println("Enter the radius :"); 12 | int b =sc.nextInt(); 13 | obj.area(b); 14 | } 15 | else if (a==2){ 16 | System.out.println("Enter the length :"); 17 | int b =sc.nextInt(); 18 | System.out.println("Enter the breadth :"); 19 | int c =sc.nextInt(); 20 | obj.area(b,c); 21 | } 22 | else if (a==3) { 23 | System.out.println("Enter the base :"); 24 | double b =sc.nextDouble(); 25 | System.out.println("Enter the height :"); 26 | double c =sc.nextDouble(); 27 | obj.area(b,c); 28 | } 29 | else 30 | System.out.println("Error"); 31 | sc.close(); 32 | } 33 | void area(int a) 34 | { 35 | System.out.println("Area of circle is:"+(3.14*a*a)); 36 | } 37 | void area(int n,int m) 38 | { 39 | System.out.println("Area of Rectangle is:"+(n*m)); 40 | } 41 | void area(double c,double d) 42 | { 43 | System.out.println("Area of triangle is:"+(0.5*c*d)); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /java/armstrong.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | class armstrong 3 | { 4 | public static void main(String args[]) 5 | { 6 | int num,result=0,rem; 7 | System.out.println("enter the number:"); 8 | Scanner sc=new Scanner(System.in); 9 | num=sc.nextInt(); 10 | int temp=num; 11 | while(num>0) 12 | { 13 | rem=num%10; 14 | result=result+(rem*rem*rem); 15 | num=num/10; 16 | } 17 | if(result==temp) 18 | System.out.println("armstrong"); 19 | else 20 | System.out.println("not armstrong"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /java/banking.java: -------------------------------------------------------------------------------- 1 | class Customer { 2 | int amount=10000; 3 | synchronized void withdraw(int amount) { 4 | System.out.println("Going to Withdraw..."); 5 | if(this.amountA[mid]) 36 | { 37 | beg=mid+1; 38 | } 39 | else 40 | { 41 | end=mid-1; 42 | } 43 | } 44 | return 0; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /java/createdatabase_table.java: -------------------------------------------------------------------------------- 1 | import java.sql.*; 2 | public class createdatabase_table { 3 | public static void main (String args[]) { 4 | try { 5 | 6 | Class.forName("com.mysql.jdbc.Driver"); 7 | Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306","root","failers@12345"); 8 | Statement stmt=con.createStatement(); 9 | 10 | int a = stmt.executeUpdate("create database student"); 11 | System.out.print(a); 12 | 13 | int b = stmt.executeUpdate("use student"); 14 | System.out.print(b); 15 | 16 | int c = stmt.executeUpdate("create table details (adm_no int,name varchar(30),age int,address varchar(50))"); 17 | System.out.print(c); 18 | 19 | PreparedStatement stmt1=con.prepareStatement("insert into details values(101,?,20,?)"); 20 | 21 | stmt1.setString(1,"Akhil"); 22 | stmt1.setString(2,"Krishna nivas"); 23 | int d =stmt1.executeUpdate(); 24 | System.out.print(d); 25 | 26 | 27 | } 28 | catch(Exception e){System.out.print(e);} 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /java/factandsum.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class factandsum { 3 | public static void main(String args[]) { 4 | factandsum obj = new factandsum(); 5 | Scanner ob=new Scanner(System.in); 6 | System.out.println("Enter the number:"); 7 | int x=ob.nextInt(); 8 | ob.close(); 9 | obj.sum(x); 10 | obj.fact(x); 11 | } 12 | void sum(int x){ 13 | int s=0,a; 14 | while(x>0) { 15 | a=x%10; 16 | s=s+a; 17 | x=x/10; 18 | } 19 | System.out.println("sum :"+s); 20 | } 21 | 22 | void fact(int n) { 23 | int fat=1,i; 24 | for(i=1;i<=n;i++) { 25 | fat=fat*i; 26 | } 27 | System.out.println("Factorial :"+fat); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /java/factors.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | public class factors { 3 | public static void main(String args[]) { 4 | int n; 5 | Scanner obj = new Scanner(System.in); 6 | System.out.println("Enter the number : "); 7 | n = obj.nextInt(); 8 | obj.close(); 9 | System.out.println("Factors of "+ n +" are "); 10 | for (int i = 1;i<=n;i++) { 11 | if (n%i==0) 12 | System.out.println(i); 13 | } 14 | } 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /java/file1.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | class file1 3 | { 4 | public static void main(String args[]) 5 | { 6 | try 7 | { 8 | FileReader f1= new FileReader("Hi.txt"); 9 | BufferedReader b1=new BufferedReader(f1); 10 | int i=0; 11 | int j=1; 12 | String s =b1.readLine(); 13 | while(s!=null) 14 | { 15 | System.out.print(j+". "); 16 | System.out.print(s); 17 | s=b1.readLine(); 18 | System.out.println(); 19 | j++; 20 | } 21 | } 22 | catch(Exception e) 23 | {} 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /java/garbage.java: -------------------------------------------------------------------------------- 1 | public class garbage 2 | { 3 | String name; 4 | public static void main(String[] args) 5 | { 6 | garbage garb=new garbage(); 7 | garb.name="Gayathri"; 8 | garb=null; 9 | System.gc(); 10 | } 11 | public void finalize() 12 | { 13 | System.out.println("Object is garbage collected"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /java/hello_world.java: -------------------------------------------------------------------------------- 1 | class hello_world 2 | { 3 | public static void main(String args[]) 4 | { 5 | System.out.println("Hello World"); 6 | } 7 | } -------------------------------------------------------------------------------- /java/implement a Binary Search Algorithm: -------------------------------------------------------------------------------- 1 | public class BinarySearch { 2 | // Java implementation of recursive Binary Search 3 | // Returns index of x if it is present in arr[l.. 4 | // r], else return -1 5 | int binarySearch(int arr[], int l, int r, int x) 6 | { 7 | if (r >= l) { 8 | int mid = l + (r - l) / 2; 9 | // If the element is present at the 10 | // middle itself 11 | if (arr[mid] == x) 12 | return mid; 13 | // If element is smaller than mid, then 14 | // it can only be present in left subarray 15 | if (arr[mid] >x) 16 | return binarySearch(arr, l, mid - 1, x); 17 | // Else the element can only be present 18 | // in right subarray 19 | return binarySearch(arr, mid + 1, r, x); 20 | } 21 | // We reach here when element is not present 22 | // in array 23 | return -1; 24 | } 25 | public static void main(String args[]) 26 | { 27 | BinarySearch ob = new BinarySearch(); 28 | int arr[] = { 2, 3, 4, 10, 40 }; 29 | int n = arr.length; 30 | int x = 40; 31 | int result = ob.binarySearch(arr, 0, n - 1, x); 32 | if (result == -1) 33 | System.out.println("Element not present"); 34 | else 35 | System.out.println("Element found at index " + result); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /java/key.java: -------------------------------------------------------------------------------- 1 | import java.awt.*; 2 | import java.awt.event.*; 3 | import javax.swing.*; 4 | public class keypress extends KeyAdapter{ 5 | static JLabel l; 6 | public void keyPressed(KeyEvent e) { 7 | l.setText("User pressed a key"); 8 | } 9 | public void keyReleased(KeyEvent e) { 10 | l.setText("User released the Key"); 11 | } 12 | public void keyTyped(KeyEvent e) { 13 | l.setText("Typing"); 14 | } 15 | public static void main(String[] args) { 16 | JFrame f = new JFrame("Key"); 17 | f.setSize(300,300); 18 | keypress k = new keypress(); 19 | f.addKeyListener(k); 20 | JPanel p = new JPanel(); 21 | l = new JLabel(); 22 | p.add(l); 23 | f.add(p); 24 | f.setVisible(true); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /java/linkedlist.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class LinkedList2{ 3 | public static void main(String args[]){ 4 | LinkedList ll=new LinkedList(); 5 | System.out.println("Initial list of elements: "+ll); 6 | ll.add("Ravi"); 7 | ll.add("Vijay"); 8 | ll.add("Ajay"); 9 | System.out.println("After invoking add(E e) method: "+ll); 10 | 11 | ll.add(1, "Gaurav"); 12 | System.out.println("After invoking add(int index, E element) method: "+ll); 13 | LinkedList ll2=new LinkedList(); 14 | ll2.add("Sonoo"); 15 | ll2.add("Hanumat"); 16 | 17 | ll.addAll(ll2); 18 | System.out.println("After invoking addAll(Collection c) method: "+ll); 19 | LinkedList ll3=new LinkedList(); 20 | ll3.add("John"); 21 | ll3.add("Rahul"); 22 | 23 | ll.addAll(1, ll3); 24 | System.out.println("After invoking addAll(int index, Collection c) method: "+ll); 25 | 26 | ll.addFirst("Lokesh"); 27 | System.out.println("After invoking addFirst(E e) method: "+ll); 28 | 29 | ll.addLast("Harsh"); 30 | System.out.println("After invoking addLast(E e) method: "+ll); 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /java/mouse.java: -------------------------------------------------------------------------------- 1 | import java.awt.*; 2 | import java.awt.event.*; 3 | import javax.swing.*; 4 | public class mouse extends Frame implements MouseListener{ 5 | static JLabel l; 6 | mouse() 7 | { 8 | 9 | } 10 | public void mouseClicked(MouseEvent e) { 11 | l.setText("Mouse Clicked"); 12 | } 13 | public void mouseEntered(MouseEvent e) { 14 | l.setText("Mouse Entered"); 15 | } 16 | public void mouseExited(MouseEvent e) { 17 | l.setText("Mouse Exited"); 18 | } 19 | public void mousePressed(MouseEvent e) { 20 | l.setText("Mouse Pressed"); 21 | } 22 | public void mouseReleased(MouseEvent e) { 23 | l.setText("Mouse Released"); 24 | } 25 | public static void main(String[] args) { 26 | JFrame f = new JFrame("Mouse"); 27 | f.setSize(300,300); 28 | mouse m = new mouse(); 29 | f.addMouseListener(m); 30 | JPanel p = new JPanel(); 31 | l = new JLabel(); 32 | p.add(l); 33 | f.add(p); 34 | f.setVisible(true); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /java/multiplymatrix.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class multiplymatrix 3 | { 4 | public static void main(String args[]) 5 | { 6 | int r1, r2,c1,c2,i,j,k,sum; 7 | Scanner in = new Scanner(System.in); 8 | System.out.println("Enter the number of rows of matrix1"); 9 | r1 = in.nextInt(); 10 | System.out.println("Enter the number columns of matrix 1"); 11 | c1 = in.nextInt(); 12 | System.out.println("Enter the number of rows of matrix2"); 13 | r2 = in.nextInt(); 14 | System.out.println("Enter the number of columns of matrix 2"); 15 | c2 = in.nextInt(); 16 | if(c1==r2) 17 | { 18 | int mat1[][] = new int[r1][c1]; 19 | int mat2[][] = new int[r2][c2]; 20 | int res[][] = new int[r1][c2]; 21 | System.out.println("Enter the elements of matrix1"); 22 | for(i=0;i0) { 13 | r = a%10; 14 | rev = (rev*10)+r; 15 | a = a/10; 16 | } 17 | if (rev==org) 18 | System.out.println("Pallindrome"); 19 | else 20 | System.out.println("Not pallindrome"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /java/perimeter_shapes.java: -------------------------------------------------------------------------------- 1 | /*Write a Java program to calculate the perimeter of different shapes 2 | namely circle and rectangle using the concept of constructor 3 | overloading.*/ 4 | import java.util.*; 5 | public class perimeter_shapes { 6 | public static void main(String args[]) 7 | { 8 | Scanner sc = new Scanner(System.in); 9 | System.out.println("Enter the radius of circle :"); 10 | int a = sc.nextInt(); 11 | System.out.println("Enter the length of rectangle :"); 12 | int b = sc.nextInt(); 13 | System.out.println("Enter the breadth of rectangle :"); 14 | int c = sc.nextInt(); 15 | perimeter_shapes obj=new perimeter_shapes(a); 16 | perimeter_shapes obj1=new perimeter_shapes(b,c); 17 | sc.close(); 18 | } 19 | perimeter_shapes(int a) 20 | { 21 | System.out.println("Perimeter of circle is:"+(3.14*2*a)); 22 | } 23 | perimeter_shapes(int n,int m) 24 | { 25 | int p=n+m; 26 | int t=2*p; 27 | System.out.println("Perimeter of Rectangle is:"+t); 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /java/prime.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class Prime 3 | { 4 | public static void main(String arfgs[]) 5 | {int n,i,flag=0; 6 | Scanner sc=new Scanner(System.in); 7 | System.out.println("enter the no"); 8 | n=sc.nextInt(); 9 | if(n==0 || n==1) 10 | System.out.println("not prime"); 11 | else 12 | {for(i=2;i<=n/2;i++) 13 | {if(n%i==0) 14 | {flag=1; 15 | System.out.println("not prime"); 16 | break; 17 | } 18 | sc.close(); 19 | } 20 | if(flag==0) 21 | System.out.println("prime"); 22 | 23 | } 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /java/quicksort.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | class quicksort 3 | { 4 | 5 | public static void main(String[] args) 6 | { 7 | quicksort q = new quicksort(); 8 | Scanner sc = new Scanner(System.in); 9 | System.out.print("Enter the number of element in the array : "); 10 | int n = sc.nextInt(); 11 | int[] a = new int[n]; 12 | System.out.print("Enter the array elements : "); 13 | for(int i=0;ikey && j>l) 39 | j--; 40 | if(i= num2 && num1 >= num3) { 11 | largest = num1; 12 | } 13 | else if (num2 >= num1 && num2 >= num3) { 14 | largest = num2; 15 | } 16 | else { 17 | largest = num3; 18 | } 19 | 20 | // display the result 21 | console.log("The largest number is " + largest); 22 | -------------------------------------------------------------------------------- /javascript/Remove All Whitespaces From a Text.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | const string = ' Hello World '; 4 | 5 | const result = string.split(' ').join(''); 6 | 7 | console.log(result); 8 | -------------------------------------------------------------------------------- /javascript/Remove Duplicate Items using arry.js: -------------------------------------------------------------------------------- 1 | // program to merge and remove duplicate value from an array 2 | 3 | function getUniqueAfterMerge(arr1, arr2){ 4 | 5 | // merge two arrays 6 | 7 | let arr = arr1.concat(arr2); 8 | 9 | let uniqueArr = []; 10 | 11 | // loop through array 12 | 13 | for(let i of arr) { 14 | 15 | if(uniqueArr.indexOf(i) === -1) { 16 | 17 | uniqueArr.push(i); 18 | 19 | } 20 | 21 | } 22 | 23 | console.log(uniqueArr); 24 | 25 | } 26 | 27 | const array1 = [1, 2, 3]; 28 | 29 | const array2 = [2, 3, 5] 30 | 31 | // calling the function 32 | 33 | // passing array argument 34 | 35 | getUniqueAfterMerge(array1, array2); 36 | -------------------------------------------------------------------------------- /javascript/To-Do-List.js: -------------------------------------------------------------------------------- 1 | document.querySelector('#tip-form').onchange = function(){ 2 | 3 | var bill = Number(document.getElementById('billTotal').value); 4 | var tip = document.getElementById('tipInput').value; 5 | document.getElementById('tipOutput').innerHTML = `${tip}%`; 6 | var tipValue = bill * (tip/100) 7 | var finalBill = bill + tipValue 8 | console.log(finalBill) 9 | var tipAmount = document.querySelector('#tipAmount') 10 | var totalBillWithTip = document.querySelector('#totalBillWithTip') 11 | 12 | tipAmount.value = tipValue.toFixed(2); 13 | totalBillWithTip.value =finalBill.toFixed(2); 14 | 15 | 16 | document.getElementById('results').style.display='block' 17 | } 18 | -------------------------------------------------------------------------------- /javascript/Triangle.js: -------------------------------------------------------------------------------- 1 | const baseValue = prompt('Enter the base of a triangle: '); 2 | const heightValue = prompt('Enter the height of a triangle: '); 3 | 4 | // calculate the area 5 | const areaValue = (baseValue * heightValue) / 2; 6 | 7 | console.log( 8 | `The area of the triangle is ${areaValue}` 9 | ); 10 | -------------------------------------------------------------------------------- /javascript/convert date to number.js: -------------------------------------------------------------------------------- 1 | // create date 2 | const d1 = new Date(); 3 | console.log(d1); 4 | 5 | // converting to number 6 | const result = d1.getTime(); 7 | console.log(result); 8 | -------------------------------------------------------------------------------- /javascript/dectobin.js: -------------------------------------------------------------------------------- 1 | // program to convert decimal to binary 2 | function convertToBinary(x) { 3 | let bin = 0; 4 | let rem, i = 1, step = 1; 5 | while (x != 0) { 6 | rem = x % 2; 7 | console.log( 8 | `Step ${step++}: ${x}/2, Remainder = ${rem}, Quotient = ${parseInt(x/2)}` 9 | ); 10 | x = parseInt(x / 2); 11 | bin = bin + rem * i; 12 | i = i * 10; 13 | } 14 | console.log(`Binary: ${bin}`); 15 | } 16 | 17 | // take input 18 | let number = prompt('Enter a decimal number: '); 19 | 20 | convertToBinary(number); 21 | -------------------------------------------------------------------------------- /javascript/factorial.js: -------------------------------------------------------------------------------- 1 | // program to find the factorial of a number 2 | 3 | // take input from the user 4 | const number = parseInt(prompt('Enter a positive integer: ')); 5 | 6 | // checking if number is negative 7 | if (number < 0) { 8 | console.log('Error! Factorial for negative number does not exist.'); 9 | } 10 | 11 | // if number is 0 12 | else if (number === 0) { 13 | console.log(`The factorial of ${number} is 1.`); 14 | } 15 | 16 | // if number is positive 17 | else { 18 | let fact = 1; 19 | for (i = 1; i <= number; i++) { 20 | fact *= i; 21 | } 22 | console.log(`The factorial of ${number} is ${fact}.`); 23 | } 24 | -------------------------------------------------------------------------------- /javascript/intbtw2values.js: -------------------------------------------------------------------------------- 1 | // input from the user 2 | const min = parseInt(prompt("Enter a min value: ")); 3 | const max = parseInt(prompt("Enter a max value: ")); 4 | 5 | // generating a random number 6 | const a = Math.floor(Math.random() * (max - min + 1)) + min; 7 | 8 | // display a random number 9 | console.log(`Random value between ${min} and ${max} is ${a}`); 10 | -------------------------------------------------------------------------------- /javascript/quad.js: -------------------------------------------------------------------------------- 1 | // program to solve quadratic equation 2 | let root1, root2; 3 | 4 | // take input from the user 5 | let a = prompt("Enter the first number: "); 6 | let b = prompt("Enter the second number: "); 7 | let c = prompt("Enter the third number: "); 8 | 9 | // calculate discriminant 10 | let discriminant = b * b - 4 * a * c; 11 | 12 | // condition for real and different roots 13 | if (discriminant > 0) { 14 | root1 = (-b + Math.sqrt(discriminant)) / (2 * a); 15 | root2 = (-b - Math.sqrt(discriminant)) / (2 * a); 16 | 17 | // result 18 | console.log(`The roots of quadratic equation are ${root1} and ${root2}`); 19 | } 20 | 21 | // condition for real and equal roots 22 | else if (discriminant == 0) { 23 | root1 = root2 = -b / (2 * a); 24 | 25 | // result 26 | console.log(`The roots of quadratic equation are ${root1} and ${root2}`); 27 | } 28 | 29 | // if roots are not real 30 | else { 31 | let realPart = (-b / (2 * a)).toFixed(2); 32 | let imagPart = (Math.sqrt(-discriminant) / (2 * a)).toFixed(2); 33 | 34 | // result 35 | console.log( 36 | `The roots of quadratic equation are ${realPart} + ${imagPart}i and ${realPart} - ${imagPart}i` 37 | ); 38 | } 39 | -------------------------------------------------------------------------------- /javascript/sumbyrecursion.js: -------------------------------------------------------------------------------- 1 | // program to find the sum of natural numbers using recursion 2 | 3 | function sum(num) { 4 | if(num > 0) { 5 | return num + sum(num - 1); 6 | } 7 | else { 8 | return num; 9 | } 10 | } 11 | 12 | // take input from the user 13 | const number = parseInt(prompt('Enter a positive integer: ')); 14 | 15 | const result = sum(number); 16 | 17 | // display the result 18 | console.log(`The sum is ${result}`); 19 | -------------------------------------------------------------------------------- /kotlin/hello.kt: -------------------------------------------------------------------------------- 1 | // Kotlin Hello World Program 2 | fun main(args: Array) { 3 | println("Hello, World!") 4 | } -------------------------------------------------------------------------------- /movie recomm/index.php: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/movie recomm/index.php -------------------------------------------------------------------------------- /movie recomm/script.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/movie recomm/script.js -------------------------------------------------------------------------------- /movie recomm/style.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/movie recomm/style.css -------------------------------------------------------------------------------- /musicplayer/index.php: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/musicplayer/index.php -------------------------------------------------------------------------------- /musicplayer/script.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/musicplayer/script.js -------------------------------------------------------------------------------- /musicplayer/style.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/musicplayer/style.css -------------------------------------------------------------------------------- /portal for docs/index.php: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/portal for docs/index.php -------------------------------------------------------------------------------- /portal for docs/script.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/portal for docs/script.js -------------------------------------------------------------------------------- /portal for docs/style.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/portal for docs/style.css -------------------------------------------------------------------------------- /python/Check.py: -------------------------------------------------------------------------------- 1 | def check(list1, val): 2 | for x in list1: 3 | if val >= x: 4 | return False 5 | return True 6 | 7 | # Taking list input from user 8 | input_list = input("Enter a list of numbers separated by spaces: ") 9 | list1 = [int(item) for item in input_list.split()] 10 | 11 | # Taking input from user for 'val' 12 | val = int(input("Enter a value: ")) 13 | 14 | if check(list1, val): 15 | print("Yes") 16 | else: 17 | print("No") 18 | -------------------------------------------------------------------------------- /python/Clear-Rightmost-SetBitNumber.py: -------------------------------------------------------------------------------- 1 | def clear_rightmost_set_bit(n): 2 | """Clear rightmost set bit of n and return it.""" 3 | return n & (n - 1) 4 | 5 | 6 | n = int(input('Number: ')) 7 | ans = clear_rightmost_set_bit(n) 8 | print('n with its rightmost set bit cleared equals:', ans) 9 | -------------------------------------------------------------------------------- /python/Compute-Polynomial Equation.py: -------------------------------------------------------------------------------- 1 | import math 2 | print("Coefficients of the form ax^3 + bx^2 + cx + d") 3 | lst=[] 4 | for i in range(0,4): 5 | a=int(input("Coefficient:")) 6 | lst.append(a) 7 | x=int(input("Value of x:")) 8 | sum1=0 9 | j=3 10 | for i in range(0,3): 11 | while(j>0): 12 | sum1=sum1+(lst[i]*math.pow(x,j)) 13 | break 14 | j=j-1 15 | sum1=sum1+lst[3] 16 | print("Value of the polynomial is:",sum1) 17 | -------------------------------------------------------------------------------- /python/Count-SetBits.py: -------------------------------------------------------------------------------- 1 | def count_set_bits(n): 2 | count = 0 3 | while n: 4 | n &= n - 1 5 | count += 1 6 | return count 7 | -------------------------------------------------------------------------------- /python/Count_Sort.py: -------------------------------------------------------------------------------- 1 | def countingSort(array): 2 | size = len(array) 3 | output = [0] * size 4 | 5 | count = [0] * 10 6 | 7 | for i in range(0, size): 8 | count[array[i]] += 1 9 | 10 | for i in range(1, 10): 11 | count[i] += count[i - 1] 12 | 13 | i = size - 1 14 | while i >= 0: 15 | output[count[array[i]] - 1] = array[i] 16 | count[array[i]] -= 1 17 | i -= 1 18 | 19 | for i in range(0, size): 20 | array[i] = output[i] 21 | 22 | 23 | data = [4, 2, 2, 8, 3, 3, 1] 24 | countingSort(data) 25 | print("Sorted Array in Ascending Order: ") 26 | print(data) 27 | -------------------------------------------------------------------------------- /python/Dijkstra-Algorithm.py: -------------------------------------------------------------------------------- 1 | from heapq import * 2 | from collections import defaultdict 3 | 4 | def dijkstra(edges, strat_node, end_node): 5 | g = defaultdict(list) 6 | for start, end, weight in edges: 7 | g[start].append((weight, end)) 8 | q, visited = [(0, strat_node,())], set() 9 | while q: 10 | (cost,v1,path) = heappop(q) 11 | if v1 not in visited: 12 | visited.add(v1) 13 | path = (v1, path) 14 | if v1 == end_node: 15 | return (cost, path) 16 | for c, v2 in g.get(v1, ()): 17 | if v2 not in visited: 18 | heappush(q, (cost+c, v2, path)) 19 | print (q) 20 | return float("inf") 21 | 22 | if __name__ == "__main__": 23 | 24 | edges = [ 25 | ("A", "B", 7), 26 | ("A", "D", 5), 27 | ("B", "C", 8), 28 | ("B", "D", 9), 29 | ("B", "E", 7), 30 | ("C", "E", 5), 31 | ("D", "E", 7), 32 | ("D", "F", 6), 33 | ("E", "F", 8), 34 | ("E", "G", 9), 35 | ("F", "G", 11) 36 | ] 37 | 38 | print ("=== Dijkstra ===") 39 | print ("A >> G:") 40 | print (dijkstra(edges, "A", "G")) 41 | -------------------------------------------------------------------------------- /python/Heap_Sort.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # Python program for implementation of heap Sort 4 | 5 | # To heapify subtree rooted at index i. 6 | # n is size of heap 7 | 8 | 9 | def heapify(arr, n, i): 10 | largest = i # Initialize largest as root 11 | l = 2 * i + 1 # left = 2*i + 1 12 | r = 2 * i + 2 # right = 2*i + 2 13 | 14 | # See if left child of root exists and is 15 | # greater than root 16 | 17 | if l < n and arr[i] < arr[l]: 18 | largest = l 19 | 20 | # See if right child of root exists and is 21 | # greater than root 22 | 23 | if r < n and arr[largest] < arr[r]: 24 | largest = r 25 | 26 | # Change root, if needed 27 | 28 | if largest != i: 29 | (arr[i], arr[largest]) = (arr[largest], arr[i]) # swap 30 | 31 | # Heapify the root. 32 | 33 | heapify(arr, n, largest) 34 | 35 | 36 | # The main function to sort an array of given size 37 | 38 | def heapSort(arr): 39 | n = len(arr) 40 | 41 | # Build a maxheap. 42 | # Since last parent will be at ((n//2)-1) we can start at that location. 43 | 44 | for i in range(n // 2 - 1, -1, -1): 45 | heapify(arr, n, i) 46 | 47 | # One by one extract elements 48 | 49 | for i in range(n - 1, 0, -1): 50 | (arr[i], arr[0]) = (arr[0], arr[i]) 51 | heapify(arr, i, 0) 52 | 53 | arr = [12, 11, 13, 5, 6, 7, ] 54 | heapSort(arr) 55 | n = len(arr) 56 | print('Sorted array is') 57 | for i in range(n): 58 | print(arr[i]) 59 | -------------------------------------------------------------------------------- /python/Huffman_Algorithm.py: -------------------------------------------------------------------------------- 1 | import heapq 2 | from collections import defaultdict, Counter 3 | 4 | class HuffmanNode: 5 | def __init__(self, char, freq): 6 | self.char = char 7 | self.freq = freq 8 | self.left = None 9 | self.right = None 10 | 11 | def __lt__(self, other): 12 | return self.freq < other.freq 13 | 14 | def build_huffman_tree(data): 15 | char_freq = Counter(data) 16 | priority_queue = [HuffmanNode(char, freq) for char, freq in char_freq.items()] 17 | heapq.heapify(priority_queue) 18 | 19 | while len(priority_queue) > 1: 20 | left_node = heapq.heappop(priority_queue) 21 | right_node = heapq.heappop(priority_queue) 22 | internal_node = HuffmanNode(None, left_node.freq + right_node.freq) 23 | internal_node.left = left_node 24 | internal_node.right = right_node 25 | heapq.heappush(priority_queue, internal_node) 26 | 27 | return priority_queue[0] 28 | 29 | def build_huffman_codes(node, prefix="", code_map=None): 30 | if code_map is None: 31 | code_map = {} 32 | 33 | if node is not None: 34 | if node.char is not None: 35 | code_map[node.char] = prefix 36 | build_huffman_codes(node.left, prefix + "0", code_map) 37 | build_huffman_codes(node.right, prefix + "1", code_map) 38 | 39 | return code_map 40 | 41 | def huffman_encode(data): 42 | root = build_huffman_tree(data) 43 | codes = build_huffman_codes(root) 44 | encoded_data = ''.join(codes[char] for char in data) 45 | return encoded_data, codes 46 | 47 | def huffman_decode(encoded_data, codes): 48 | decoded_data = "" 49 | current_code = "" 50 | 51 | for bit in encoded_data: 52 | current_code += bit 53 | for char, code in codes.items(): 54 | if code == current_code: 55 | decoded_data += char 56 | current_code = "" 57 | break 58 | 59 | return decoded_data 60 | 61 | if __name__ == "__main__": 62 | input_data = input("Enter the text to encode: ") 63 | encoded_data, huffman_codes = huffman_encode(input_data) 64 | print(f"Encoded data: {encoded_data}") 65 | 66 | decoded_data = huffman_decode(encoded_data, huffman_codes) 67 | print(f"Decoded data: {decoded_data}") 68 | -------------------------------------------------------------------------------- /python/Knight_Walk.py: -------------------------------------------------------------------------------- 1 | # Python3 program to solve Knight Tour problem using Backtracking 2 | 3 | # Chessboard Size 4 | n = 8 5 | 6 | 7 | def isSafe(x, y, board): 8 | ''' 9 | A utility function to check if i,j are valid indexes 10 | for N*N chessboard 11 | ''' 12 | if(x >= 0 and y >= 0 and x < n and y < n and board[x][y] == -1): 13 | return True 14 | return False 15 | 16 | 17 | def printSolution(n, board): 18 | ''' 19 | A utility function to print Chessboard matrix 20 | ''' 21 | for i in range(n): 22 | for j in range(n): 23 | print(board[i][j], end=' ') 24 | print() 25 | 26 | 27 | def solveKT(n): 28 | ''' 29 | This function solves the Knight Tour problem using 30 | Backtracking. This function mainly uses solveKTUtil() 31 | to solve the problem. It returns false if no complete 32 | tour is possible, otherwise return true and prints the 33 | tour. 34 | Please note that there may be more than one solutions, 35 | this function prints one of the feasible solutions. 36 | ''' 37 | 38 | # Initialization of Board matrix 39 | board = [[-1 for i in range(n)]for i in range(n)] 40 | 41 | # move_x and move_y define next move of Knight. 42 | # move_x is for next value of x coordinate 43 | # move_y is for next value of y coordinate 44 | move_x = [2, 1, -1, -2, -2, -1, 1, 2] 45 | move_y = [1, 2, 2, 1, -1, -2, -2, -1] 46 | 47 | # Since the Knight is initially at the first block 48 | board[0][0] = 0 49 | 50 | # Step counter for knight's position 51 | pos = 1 52 | 53 | # Checking if solution exists or not 54 | if(not solveKTUtil(n, board, 0, 0, move_x, move_y, pos)): 55 | print("Solution does not exist") 56 | else: 57 | printSolution(n, board) 58 | 59 | 60 | def solveKTUtil(n, board, curr_x, curr_y, move_x, move_y, pos): 61 | ''' 62 | A recursive utility function to solve Knight Tour 63 | problem 64 | ''' 65 | 66 | if(pos == n**2): 67 | return True 68 | 69 | # Try all next moves from the current coordinate x, y 70 | for i in range(8): 71 | new_x = curr_x + move_x[i] 72 | new_y = curr_y + move_y[i] 73 | if(isSafe(new_x, new_y, board)): 74 | board[new_x][new_y] = pos 75 | if(solveKTUtil(n, board, new_x, new_y, move_x, move_y, pos+1)): 76 | return True 77 | 78 | # Backtracking 79 | board[new_x][new_y] = -1 80 | return False 81 | 82 | 83 | # Driver Code 84 | if __name__ == "__main__": 85 | 86 | # Function Call 87 | solveKT(n) 88 | 89 | -------------------------------------------------------------------------------- /python/List.py: -------------------------------------------------------------------------------- 1 | lst = [] 2 | n = int(input("Enter number of elements : ")) 3 | for i in range(0, n): 4 | ele = int(input()) 5 | 6 | lst.append(ele) 7 | 8 | print(lst) 9 | -------------------------------------------------------------------------------- /python/Possible-Combinations_Three Digits.py: -------------------------------------------------------------------------------- 1 | a=int(input("Enter first number:")) 2 | b=int(input("Enter second number:")) 3 | c=int(input("Enter third number:")) 4 | k=[] 5 | e.append(a) 6 | e.append(b) 7 | e.append(c) 8 | for i in range(0,3): 9 | for j in range(0,3): 10 | for k in range(0,3): 11 | if(i!=j&j!=k&k!=i): 12 | print(e[i],e[j],e[k]) 13 | -------------------------------------------------------------------------------- /python/Read-Contents_ofFile.py: -------------------------------------------------------------------------------- 1 | a=str(input("Enter the name of the file with .txt extension:")) 2 | file2=open(a,'r') 3 | line=file2.readline() 4 | while(line!=""): 5 | print(line) 6 | line=file2.readline() 7 | file2.close() 8 | -------------------------------------------------------------------------------- /python/Stock Profit.py: -------------------------------------------------------------------------------- 1 | import array as arr 2 | global curpro 3 | def profit(a,i,n,curpro): 4 | small=a[i] 5 | 6 | maxpro=0 7 | for i in range(i,n): 8 | if i+1==n: 9 | curpro=curpro+maxpro 10 | 11 | break 12 | elif smallmaxpro): 15 | maxpro=a[i+1]-small 16 | 17 | elif small>a[i+1]: 18 | 19 | small=a[i+1] 20 | flag=i+1 21 | 22 | 23 | curpro=curpro+maxpro 24 | 25 | curpro=profit(a,flag,n,curpro) 26 | break 27 | else: 28 | if i==0: 29 | flag=i+1 30 | profit(a,flag,n,curpro) 31 | return curpro 32 | 33 | n=int(input("Enter no of stock prices:")) 34 | l=[] 35 | for i in range(n): 36 | a=int(input(":")) 37 | l.append(a) 38 | curpro=0 39 | a=arr.array('i',l) 40 | pro=profit(a,0,n,curpro) 41 | print("Maximum profit earned:",pro) 42 | -------------------------------------------------------------------------------- /python/StringPal.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | def isPalindrome(s): 4 | return s == s[::-1] 5 | 6 | 7 | # Driver code 8 | s = "malayalam" 9 | ans = isPalindrome(s) 10 | 11 | if ans: 12 | print("Yes") 13 | else: 14 | print("No") 15 | -------------------------------------------------------------------------------- /python/age.py: -------------------------------------------------------------------------------- 1 | # input age 2 | age = int(input("Enter Age : ")) 3 | 4 | # condition to check voting eligibility 5 | if age>=18: 6 | status="Eligible" 7 | else: 8 | status="Not Eligible" 9 | 10 | print("You are ",status," for Vote.") 11 | -------------------------------------------------------------------------------- /python/bluecircle10.py: -------------------------------------------------------------------------------- 1 | import turtle 2 | turtle.bgcolor('black') 3 | turtle.speed(0) 4 | turtle.pensize(2) 5 | turtle.pencolor('blue') 6 | 7 | def drawcircle(radius): 8 | for i in range(20): 9 | turtle.circle(radius) 10 | radius=radius-7 11 | def drawdesign(): 12 | for i in range(10): 13 | drawcircle(150) 14 | turtle.right(36) 15 | 16 | drawdesign() 17 | turtle.done() -------------------------------------------------------------------------------- /python/currenttime finder.py: -------------------------------------------------------------------------------- 1 | from datetime import * 2 | import pytz 3 | 4 | 5 | tz_INDIA = pytz.timezone('Asia/Kolkata') 6 | datetime_INDIA = datetime.now(tz_INDIA) 7 | print("INDIA time:", datetime_INDIA.strftime("%H:%M:%S")) 8 | -------------------------------------------------------------------------------- /python/datesort.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | 3 | lt = list() 4 | n = int(input("Enter the range: ")) 5 | for i in range(n): 6 | lt.append(input()) 7 | print("In ascending order: ") 8 | lt.sort(key=lambda date: datetime.strptime(date, "%d/%b/%Y")) 9 | print(lt) 10 | print("In descending order: ") 11 | lt.sort(key=lambda date: datetime.strptime(date, "%d/%b/%Y"), reverse=True) 12 | print(lt) 13 | -------------------------------------------------------------------------------- /python/dice_game.py: -------------------------------------------------------------------------------- 1 | import random 2 | import time 3 | 4 | def wait(): 5 | time.sleep(2.0) 6 | 7 | print("*"*50) 8 | print("Welcome to the Dice Game!") 9 | print("A Game of Luck") 10 | print("*"*50) 11 | print("Roll the die and if you roll a lucky six; You Win! :)") 12 | 13 | while (True): 14 | user_input = input("Press 1 to role Die\n") 15 | 16 | if(user_input == '1' or user_input == 1): 17 | num = random.randint(1,6) 18 | print("\nRolling the Die") 19 | wait() 20 | if(num == 6): 21 | print("You got",num) 22 | print("Yay! You won!\n") 23 | else: 24 | print("\nYou got",num,"\nAww! You Lost!\n") 25 | 26 | choice = input("Press Y to Play again\nPress N to Exit Game\n") 27 | 28 | if (choice == 'Y' or choice == 'y'): 29 | continue 30 | elif (choice == 'N' or choice == 'n'): 31 | break 32 | else: 33 | print("\nPlease Enter Y/N.") 34 | 35 | else: 36 | print("\nNot a valid option") -------------------------------------------------------------------------------- /python/guessmynumber.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | while True: 4 | 5 | print("\nNUMBER GUESSING GAME\n") 6 | 7 | j=int(input("Enter the number of rounds u need:")) 8 | 9 | y = int (input("\nGuess the number:")) 10 | 11 | s=random.randint(1,100) 12 | 13 | i=1 14 | 15 | while (y!=s): 16 | 17 | if i==j: 18 | 19 | print("Oops!You have used all your chances.You lost this game") 20 | 21 | input("Press any key to continue") 22 | 23 | c=1 24 | 25 | break 26 | 27 | elif y>s: 28 | 29 | print("Your guess is greater than actual number!Try again") 30 | 31 | y = int(input("Guess the number:")) 32 | 33 | i+=1 34 | 35 | elif y 1) 18 | 19 | pygame.init() 20 | screen = pygame.display.set_mode((600,600)) 21 | pygame.display.set_caption('Snake') 22 | 23 | #direções 24 | up = 0 25 | right = 1 26 | down = 2 27 | left = 3 28 | 29 | snake = [(200,200), (210,200), (220,200)] 30 | snake_direction = left 31 | snake_skin = pygame.Surface((10,10)) 32 | snake_skin.fill((255,255,255)) 33 | 34 | apple_position = apple_random_position() 35 | apple = pygame.Surface((10,10)) 36 | apple.fill((255,0,0)) 37 | 38 | clock = pygame.time.Clock() 39 | 40 | while True: 41 | clock.tick(20) 42 | 43 | for event in pygame.event.get(): 44 | if event.type == QUIT: 45 | pygame.quit() 46 | if event.type == KEYDOWN: 47 | if event.key == K_UP and not snake_direction == down: 48 | snake_direction = up 49 | if event.key == K_DOWN and not snake_direction == up: 50 | snake_direction = down 51 | if event.key == K_RIGHT and not snake_direction == left: 52 | snake_direction = right 53 | if event.key == K_LEFT and not snake_direction == right: 54 | snake_direction = left 55 | 56 | if collision(snake[0], apple_position): 57 | apple_position = apple_random_position() 58 | snake.append((0,0)) 59 | 60 | if collision_lose(snake[0]) or self_collision(snake[0], snake): 61 | pygame.quit() 62 | 63 | 64 | 65 | for i in range(len(snake) - 1, 0, -1): 66 | snake[i] = (snake[i-1][0], snake[i-1][1]) 67 | 68 | if snake_direction == up: 69 | snake[0] = (snake[0][0], snake[0][1] - 10) 70 | if snake_direction == down: 71 | snake[0] = (snake[0][0], snake[0][1] + 10) 72 | if snake_direction == right: 73 | snake[0] = (snake[0][0] + 10, snake[0][1]) 74 | if snake_direction == left: 75 | snake[0] = (snake[0][0] - 10, snake[0][1]) 76 | 77 | screen.fill((0,0,0)) 78 | screen.blit(apple, apple_position) 79 | for position in snake: 80 | screen.blit(snake_skin,position) 81 | 82 | pygame.display.update() -------------------------------------------------------------------------------- /python/twosum.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. 3 | 4 | You may assume that each input would have exactly one solution, and you may not use the same element twice. 5 | 6 | You can return the answer in any order. 7 | ''' 8 | #Leetcode sollution 9 | class Solution(object): 10 | def twoSum(self, nums, target): 11 | c = [] 12 | for i in range(len(nums)): 13 | for j in range(i+1,len(nums)): 14 | k = nums[i]+nums[j] 15 | if k== target: 16 | c.append(i) 17 | c.append(j) 18 | break 19 | return c 20 | -------------------------------------------------------------------------------- /restorent/Script.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/restorent/Script.js -------------------------------------------------------------------------------- /restorent/index.html: -------------------------------------------------------------------------------- 1 | < 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /restorent/style.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/restorent/style.css -------------------------------------------------------------------------------- /ruby/hello.rb: -------------------------------------------------------------------------------- 1 | puts 'Hello, world!' -------------------------------------------------------------------------------- /rust/hello.rs: -------------------------------------------------------------------------------- 1 | // This is a comment, and is ignored by the compiler. 2 | // You can test this code by clicking the "Run" button over there -> 3 | // or if you prefer to use your keyboard, you can use the "Ctrl + Enter" 4 | // shortcut. 5 | 6 | // This code is editable, feel free to hack it! 7 | // You can always return to the original code by clicking the "Reset" button -> 8 | 9 | // This is the main function. 10 | fn main() { 11 | // Statements here are executed when the compiled binary is called. 12 | 13 | // Print text to the console. 14 | println!("Hello World!"); 15 | } -------------------------------------------------------------------------------- /servey form/form.css: -------------------------------------------------------------------------------- 1 | input, 2 | textarea, 3 | select { 4 | outline: none; 5 | } 6 | 7 | input[type="radio"] 8 | select { 9 | cursor: pointer; 10 | } 11 | 12 | body { 13 | font-family: Arial, sans-serif; 14 | background-color: #f4f4f4; 15 | margin: 0; 16 | padding: 0; 17 | display: flex; 18 | align-items: center; 19 | justify-content: center; 20 | height: 100vh; 21 | height: 100dvh; 22 | } 23 | 24 | .container { 25 | max-width: 500px; 26 | margin: 0 auto; 27 | padding: 20px; 28 | background-color: #fff; 29 | border-radius: 5px; 30 | box-shadow: 0 0 10px rgba(0, 0, 0, 0.2); 31 | } 32 | 33 | h1 { 34 | text-align: center; 35 | color: #333; 36 | margin: 0; 37 | } 38 | 39 | p { 40 | text-align: center; 41 | color: #666; 42 | } 43 | 44 | form { 45 | margin-top: 20px; 46 | padding-inline: 20px; 47 | } 48 | 49 | .form-group { 50 | display: flex; 51 | align-items: center; 52 | justify-content: space-between; 53 | gap: 12px; 54 | } 55 | 56 | label { 57 | display: block; 58 | font-weight: bold; 59 | } 60 | 61 | input[type="text"], 62 | input[type="email"], 63 | input[type="number"], 64 | textarea, 65 | select { 66 | width: 100%; 67 | padding: 10px; 68 | margin-bottom: 20px; 69 | margin-top: 10px; 70 | border: 1px solid #ccc; 71 | border-radius: 3px; 72 | font-size: 16px; 73 | background: hsl(0, 0%, 50%, 0.1); 74 | } 75 | 76 | select { 77 | height: 40px; 78 | } 79 | 80 | .radio-group { 81 | margin-bottom: 33px; 82 | } 83 | 84 | .radio-elements { 85 | 86 | margin-top: 12px; 87 | display: flex; 88 | align-items: center; 89 | justify-content: flex-start; 90 | gap: 5px; 91 | } 92 | 93 | input[type="radio"] { 94 | margin-right: 5px; 95 | } 96 | 97 | button { 98 | display: block; 99 | width: 100%; 100 | padding: 10px; 101 | background-color: #007BFF; 102 | color: #fff; 103 | border: none; 104 | border-radius: 3px; 105 | cursor: pointer; 106 | } 107 | 108 | button:hover { 109 | background-color: #0056b3; 110 | } -------------------------------------------------------------------------------- /static-portfolio-templates/README.md: -------------------------------------------------------------------------------- 1 | 2 |

HacktoberFest 2023

3 | 4 | 5 | # Guidelines 6 | 7 | 8 | * Create a folder and add the files inside that folder. 9 | * Use unique names for the folder. 10 | * Refer akku_portfolio for the file structure. -------------------------------------------------------------------------------- /static-portfolio-templates/akku_portfolio/static/photos/github.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/static-portfolio-templates/akku_portfolio/static/photos/github.png -------------------------------------------------------------------------------- /static-portfolio-templates/akku_portfolio/static/photos/intro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/static-portfolio-templates/akku_portfolio/static/photos/intro.png -------------------------------------------------------------------------------- /static-portfolio-templates/akku_portfolio/static/photos/portfolio-01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/static-portfolio-templates/akku_portfolio/static/photos/portfolio-01.jpg -------------------------------------------------------------------------------- /static-portfolio-templates/akku_portfolio/static/photos/portfolio-02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/static-portfolio-templates/akku_portfolio/static/photos/portfolio-02.jpg -------------------------------------------------------------------------------- /static-portfolio-templates/akku_portfolio/static/photos/portfolio-03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnapatidar458/hacktoberfest2024/04be8bc79596e54b248d99fd2fbb257a536d7d20/static-portfolio-templates/akku_portfolio/static/photos/portfolio-03.jpg -------------------------------------------------------------------------------- /swift/helloworld.swift: -------------------------------------------------------------------------------- 1 | // Swift "Hello, World!" Program 2 | 3 | print("Hello, World!") -------------------------------------------------------------------------------- /toposort_by_bfs.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Solution 4 | { 5 | public: 6 | //Function to return list containing vertices in Topological order. 7 | vector topoSort(int v, vector adj[]) 8 | { 9 | // code here 10 | vectorans; 11 | vectorind(v,0); 12 | for(int i=0;iq; 18 | for(int i=0;i adj[7]; 38 | adj[2].push_back(1); 39 | adj[5].push_back(0); 40 | adj[4].push_back(0); 41 | adj[4].push_back(1); 42 | adj[3].push_back(1); 43 | adj[2].push_back(3); 44 | adj[6].push_back(3); 45 | Solution obj; 46 | vector v=obj.topoSort(7, adj); 47 | for(auto it:v) 48 | cout<