├── Loops ├── tempCodeRunnerFile.cpp ├── 1.exe ├── 1.cpp ├── Factorial.cpp └── nested_loop_in_cpp ├── some basic data structures in cpp ├── temp.cpp ├── binary_search.cpp └── quicksort.cpp ├── iostreams ├── My.txt ├── Serialization.exe ├── file_reading.exe ├── file_writing.exe ├── manipulators.exe ├── manipulators.cpp ├── file_writing.cpp ├── file_reading.cpp └── Serialization.cpp ├── Base Class Pointer ├── tempCodeRunnerFile.cpp ├── try.exe └── try.cpp ├── Polymorphism ├── tempCodeRunnerFile.cpp ├── Virtual_Functions.exe ├── function_overriding.exe ├── strudent_excercise.exe ├── function_overriding.cpp ├── Virtual_Functions.cpp └── strudent_excercise.cpp ├── Dipankar ├── a.exe └── swap_without_third_variable.cpp ├── Array_operation.exe ├── Pointers ├── intro.exe ├── StudentClass.exe ├── functionpointer.exe ├── intro.cpp └── functionpointer.cpp ├── Arrays ├── nestedloops.exe ├── BinarySearch.exe ├── LinearSearch.exe ├── drawingpattern1.exe ├── drawingpattern2.exe ├── drawingpattern3.exe ├── drawingpattern4.exe ├── tempCodeRunnerFile.exe ├── nestedloops.cpp ├── Beautiful_matrix(Codeforces).cpp ├── drawingpattern1.cpp ├── LinearSearch.cpp ├── drawingpattern2.cpp ├── tempCodeRunnerFile.cpp ├── drawingpattern3.cpp ├── numpy.cpp ├── BinarySearch.cpp ├── ReverseArray ├── drawingpattern4.cpp ├── same_tree.cpp ├── next_permutation.cpp ├── Ocuurence_Odd_no_Of_times.cpp ├── array.cpp ├── chef_and_array.cpp └── height of tree in c++ ├── Increase_String_font.exe ├── Linked List ├── DoublyLL.exe ├── SingleLL.exe ├── CircularLL.exe ├── Reverse_Linked_List.cpp └── insert-at-beginning-of-singlylinkedlist.cpp ├── Namespace ├── namespace.exe └── namespace.cpp ├── Recursion ├── factorial.exe ├── fibonacci.exe ├── print1ToN.exe ├── printNTo1.exe ├── countSubseq.exe ├── reverseArray.exe ├── .vscode │ └── settings.json ├── printNameNTimes.exe ├── PalindromeString.exe ├── printSubsequence.exe ├── sumOfFirstNNumber.exe ├── print1ToNBacktracking.exe ├── printNTo1BackTracking.exe ├── printSubseqOfGivenSum.exe ├── printNTo1.cpp ├── factorial.cpp ├── print1ToN.cpp ├── print1ToNBacktracking.cpp ├── printNTo1BackTracking.cpp ├── fibonacci.cpp ├── printNameNTimes.cpp ├── Palindrome_check.cpp ├── reverseArray.cpp ├── sumOfFirstNNumber.cpp ├── PalindromeString.cpp ├── printSubsequence.cpp ├── countSubseq.cpp └── printSubseqOfGivenSum.cpp ├── Destructor ├── Destructor.exe └── Destructor.cpp ├── Exception Handling ├── try.exe ├── Student_excercise.exe ├── TandCBEtweenFunctions.exe ├── try.cpp ├── TandCBEtweenFunctions.cpp └── Student_excercise.cpp ├── Inheritance ├── excercise.exe ├── Constructors.exe ├── Constructors.cpp └── excercise.cpp ├── pattern ├── C++_invert_V-shape.exe ├── C++_invert_pyramid.exe ├── C++_pyramid_triangle.exe ├── C++_lower_full_pyramid.exe ├── C++_upper_half_triangle.exe ├── C++_upper_half_triangle.cpp ├── C++_invert_pyramid.cpp ├── C++_pyramid_triangle.cpp ├── C++_lower_full_pyramid.cpp ├── C++_invert_V-shape.cpp ├── pattern.cpp └── jayampattern.cpp ├── Hello world ├── hellothere.cpp ├── firstcode.Cpp ├── hello.cpp └── hello_world.cpp ├── Ram Kaminwar └── Ram.cpp ├── Intro to OOPs ├── Objects_using_pointers.exe └── Objects_using_pointers.cpp ├── Operator Overloading ├── insertion_operatr.exe ├── addition_of_img_nos.exe ├── friend_function_op_overloading.exe ├── addition_of_img_nos.cpp ├── friend_function_op_overloading.cpp └── insertion_operatr.cpp ├── Friend_Function and Static_Members ├── Static.exe └── Static.cpp ├── sum.cpp ├── Auti29.cpp ├── EvenOrOdd.cpp ├── pattern.cpp ├── practice └── Reeverse_integer.cpp ├── factorial ├── factorial.cpp ├── palindrome.cpp ├── factorial3.cpp ├── factorial2.cpp └── factorial4.cpp ├── c6 ├── divyansh44.cpp ├── Leetcode ├── 1920BuildArrayfromPermutation.cpp ├── 2095DeleteMiddleNodeLL.cpp ├── 2181MergeNodesBetweenZeros.cpp └── 35SearchInseartPos.cpp ├── Function overloading ├── DSA in CPP ├── Recursion │ ├── factorial.cpp │ ├── tree_recrursion.cpp │ ├── Static_Global.cpp │ ├── combination_using_pascal_triangle.cpp │ ├── Toer_Of_HAnoi.cpp │ └── fibonacci.cpp ├── Array Adt │ ├── delete.cpp │ ├── LinearSearch.cpp │ ├── Insert_and_Append.cpp │ ├── Array_ADT.cpp │ ├── Reversing_an_array.cpp │ ├── BinarySearch.cpp │ └── All_together_in_CPP.cpp └── Linked List │ └── display.cpp ├── swap └── swap.cpp ├── buy & sell └── 122BestTimeBuyandSell2.cpp ├── decimal_to_binary.cpp ├── Cellpadding And Cellspacing Attributes.txt ├── Concatenate String Objects ├── Pattern ├── Cpp_Boolean ├── Pattern.cpp ├── Pattern2.cpp ├── triangle.cpp ├── Pyramid └── Pyramid.cpp ├── garvit128729.cpp ├── Matrix ├── Krishnangshu_Paul.cpp ├── Multiplication_of_Natrix.cpp ├── Matrix.cpp └── Matrix Multiplication.cpp ├── binarytodecimal └── binarytodecimal.cpp ├── Kunal └── Simple C++ program ├── Swap_two_numbers ├── RealPyramid.cpp ├── Array_sum.cpp ├── armstrong_no.cpp ├── codejava237.java ├── multiplication.cpp ├── Shivam_Mishra ├── MultipleRecursion.cpp └── Find_Subsequence.cpp ├── practical7.txt ├── fibonacci_sequence.cpp ├── jayantchaudhari18.cpp ├── pascaltriangle.cpp ├── Binary_to_decimal └── binaryToDecimal.cpp ├── java code 1 ├── Ak6.cpp ├── Invert_pyramid.cpp ├── function_overwiting.cpp ├── year └── leap_year.cpp ├── Any 2.cpp ├── FibonacciRecursion.cpp ├── prime ├── CheckPrime.cpp └── prime.cpp ├── GCD └── GCD.cpp ├── Prefix └── Reverse_prefix.cpp ├── factorial.cpp ├── ifelse.cpp ├── Hcf.cpp ├── array.cpp ├── linearsearch.CPP ├── mustafa.cpp ├── linear & binary search ├── linear_search.cpp └── BinarySearch.cpp ├── Hacktoberfest2022.cpp ├── Check Palindrome String ├── Dynamic Programming ├── fibonacii number using dp.cpp ├── coin_change_dpsolution.cpp ├── 01knapsack.cpp └── EditDistance.cpp ├── attendance.txt ├── digital_watch └── clock.cpp ├── b.java ├── c.java ├── Vivek Kumar ├── TestDictionary.java ├── Apoorva └── RecursiveCombinationFormula.cpp ├── Bubble sort ├── bubble-sort.cpp ├── bubblesort.cpp ├── Bubble_sort.cpp └── bubble_sort.cpp ├── Binary Seach ├── binary_search_with _recursion.cpp ├── binary_search_using_while_loop(iteration).cpp ├── Binary_Seach.cpp └── Binary_search.cpp ├── vm.cpp ├── dav └── operator-overloading.cpp ├── linearsearchjayam.cpp ├── roots └── roots.cpp ├── ASHISH ├── code32 ├── fibonacci series └── fibonacci_series.cpp ├── Krish └── calculatePower.cpp ├── binarysearch.CPP ├── athul └── functionoverload.cpp ├── Heartpattern.cpp ├── transpose.cpp ├── kadane's algorithm.cpp ├── Vijay └── findkCLosetElements.cpp ├── Matrix-Transpose ├── Matrix_Transpose.cpp ├── Transposeofmatrix.cpp └── matrix_tranpose.cpp ├── code2 ├── star pattern └── star_pattern.cpp ├── c++ ├── Cpp_Recursion ├── constructor & destructor └── constroctor_and_destructor.cpp ├── merge sort └── merge_sort.cpp ├── simple calculator.cpp ├── code243 ├── function.cpp ├── shruti ├── .vscode └── tasks.json ├── functions ├── friend-func.cpp └── warshall.cpp ├── Varad Chandrawar └── class.c++ ├── sortArray └── sortArray.cpp ├── Arushi_Agarwal └── Nth node from end of linked list ├── ArrayList 9 ├── Google.cpp ├── Butterfly.cpp ├── palindrome.cpp ├── add_distance.cpp ├── Siddharth └── RodCuttingEfficient.cpp ├── Structure └── structure.cpp ├── binary_search.cpp ├── del_last_note.py ├── pythagoras_triplet.cpp ├── Clock.cpp ├── ArrayList to LinkedList43 ├── oddevensort └── oddevensort.cpp ├── Rohan └── Find-K-Closest-Element.cpp ├── Sorting └── selectionsort.cpp ├── Matrix Multiplication.cpp ├── binary tree └── binary-tree.cpp ├── sahc++.cpp ├── magicsquare.CPP ├── LICENSE.md ├── Nandhika.cpp ├── mycode5 ├── Varun Kotgire └── Adult or not.cpp ├── binarysearch.cpp ├── dnf_sort.cpp ├── sort └── dnf-sort.cpp ├── Cycle Sort.cpp ├── LCS_Program_for_Longest_Common_Subsequence_DP.cpp ├── Juggling_Algorithm └── Juggling.cpp ├── mergesort.cpp ├── Sort.cpp ├── Csorting.cpp ├── Sorting.cpp ├── structure-python └── structure.py ├── lcs └── lcs.cpp ├── transpose_matrix.cpp ├── Guess the Number └── guess_the_number.cpp ├── Hashing └── linearprobing.cpp ├── travelling salesman prblm └── tsp.cpp ├── bintree.cpp ├── rock_paper_scissors.c ├── calculator └── calculator.cpp └── quicksort └── quicksort.cpp /Loops/tempCodeRunnerFile.cpp: -------------------------------------------------------------------------------- 1 | sum -------------------------------------------------------------------------------- /some basic data structures in cpp/temp.cpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /iostreams/My.txt: -------------------------------------------------------------------------------- 1 | Swaraj 2 | 52 3 | CS 4 | -------------------------------------------------------------------------------- /Base Class Pointer/tempCodeRunnerFile.cpp: -------------------------------------------------------------------------------- 1 | cout<<"chal chaL ave "<< endl; -------------------------------------------------------------------------------- /Polymorphism/tempCodeRunnerFile.cpp: -------------------------------------------------------------------------------- 1 | 2 | return 2*M_PI*radius; -------------------------------------------------------------------------------- /Loops/1.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Loops/1.exe -------------------------------------------------------------------------------- /Dipankar/a.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Dipankar/a.exe -------------------------------------------------------------------------------- /Array_operation.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Array_operation.exe -------------------------------------------------------------------------------- /Pointers/intro.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Pointers/intro.exe -------------------------------------------------------------------------------- /Arrays/nestedloops.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Arrays/nestedloops.exe -------------------------------------------------------------------------------- /Arrays/BinarySearch.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Arrays/BinarySearch.exe -------------------------------------------------------------------------------- /Arrays/LinearSearch.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Arrays/LinearSearch.exe -------------------------------------------------------------------------------- /Increase_String_font.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Increase_String_font.exe -------------------------------------------------------------------------------- /Linked List/DoublyLL.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Linked List/DoublyLL.exe -------------------------------------------------------------------------------- /Linked List/SingleLL.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Linked List/SingleLL.exe -------------------------------------------------------------------------------- /Namespace/namespace.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Namespace/namespace.exe -------------------------------------------------------------------------------- /Recursion/factorial.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Recursion/factorial.exe -------------------------------------------------------------------------------- /Recursion/fibonacci.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Recursion/fibonacci.exe -------------------------------------------------------------------------------- /Recursion/print1ToN.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Recursion/print1ToN.exe -------------------------------------------------------------------------------- /Recursion/printNTo1.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Recursion/printNTo1.exe -------------------------------------------------------------------------------- /Arrays/drawingpattern1.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Arrays/drawingpattern1.exe -------------------------------------------------------------------------------- /Arrays/drawingpattern2.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Arrays/drawingpattern2.exe -------------------------------------------------------------------------------- /Arrays/drawingpattern3.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Arrays/drawingpattern3.exe -------------------------------------------------------------------------------- /Arrays/drawingpattern4.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Arrays/drawingpattern4.exe -------------------------------------------------------------------------------- /Base Class Pointer/try.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Base Class Pointer/try.exe -------------------------------------------------------------------------------- /Destructor/Destructor.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Destructor/Destructor.exe -------------------------------------------------------------------------------- /Exception Handling/try.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Exception Handling/try.exe -------------------------------------------------------------------------------- /Inheritance/excercise.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Inheritance/excercise.exe -------------------------------------------------------------------------------- /Linked List/CircularLL.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Linked List/CircularLL.exe -------------------------------------------------------------------------------- /Pointers/StudentClass.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Pointers/StudentClass.exe -------------------------------------------------------------------------------- /Recursion/countSubseq.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Recursion/countSubseq.exe -------------------------------------------------------------------------------- /Recursion/reverseArray.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Recursion/reverseArray.exe -------------------------------------------------------------------------------- /iostreams/Serialization.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/iostreams/Serialization.exe -------------------------------------------------------------------------------- /iostreams/file_reading.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/iostreams/file_reading.exe -------------------------------------------------------------------------------- /iostreams/file_writing.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/iostreams/file_writing.exe -------------------------------------------------------------------------------- /iostreams/manipulators.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/iostreams/manipulators.exe -------------------------------------------------------------------------------- /Arrays/tempCodeRunnerFile.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Arrays/tempCodeRunnerFile.exe -------------------------------------------------------------------------------- /Inheritance/Constructors.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Inheritance/Constructors.exe -------------------------------------------------------------------------------- /Pointers/functionpointer.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Pointers/functionpointer.exe -------------------------------------------------------------------------------- /Recursion/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "iostream": "cpp" 4 | } 5 | } -------------------------------------------------------------------------------- /Recursion/printNameNTimes.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Recursion/printNameNTimes.exe -------------------------------------------------------------------------------- /Recursion/PalindromeString.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Recursion/PalindromeString.exe -------------------------------------------------------------------------------- /Recursion/printSubsequence.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Recursion/printSubsequence.exe -------------------------------------------------------------------------------- /Recursion/sumOfFirstNNumber.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Recursion/sumOfFirstNNumber.exe -------------------------------------------------------------------------------- /pattern/C++_invert_V-shape.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/pattern/C++_invert_V-shape.exe -------------------------------------------------------------------------------- /pattern/C++_invert_pyramid.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/pattern/C++_invert_pyramid.exe -------------------------------------------------------------------------------- /pattern/C++_pyramid_triangle.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/pattern/C++_pyramid_triangle.exe -------------------------------------------------------------------------------- /Polymorphism/Virtual_Functions.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Polymorphism/Virtual_Functions.exe -------------------------------------------------------------------------------- /pattern/C++_lower_full_pyramid.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/pattern/C++_lower_full_pyramid.exe -------------------------------------------------------------------------------- /Polymorphism/function_overriding.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Polymorphism/function_overriding.exe -------------------------------------------------------------------------------- /Polymorphism/strudent_excercise.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Polymorphism/strudent_excercise.exe -------------------------------------------------------------------------------- /Recursion/print1ToNBacktracking.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Recursion/print1ToNBacktracking.exe -------------------------------------------------------------------------------- /Recursion/printNTo1BackTracking.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Recursion/printNTo1BackTracking.exe -------------------------------------------------------------------------------- /Recursion/printSubseqOfGivenSum.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Recursion/printSubseqOfGivenSum.exe -------------------------------------------------------------------------------- /pattern/C++_upper_half_triangle.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/pattern/C++_upper_half_triangle.exe -------------------------------------------------------------------------------- /Hello world/hellothere.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | cout << "Hello there"; 6 | } -------------------------------------------------------------------------------- /Ram Kaminwar/Ram.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void main() 5 | { 6 | cout<<"Hello Here"; 7 | } -------------------------------------------------------------------------------- /Exception Handling/Student_excercise.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Exception Handling/Student_excercise.exe -------------------------------------------------------------------------------- /Intro to OOPs/Objects_using_pointers.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Intro to OOPs/Objects_using_pointers.exe -------------------------------------------------------------------------------- /Operator Overloading/insertion_operatr.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Operator Overloading/insertion_operatr.exe -------------------------------------------------------------------------------- /Exception Handling/TandCBEtweenFunctions.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Exception Handling/TandCBEtweenFunctions.exe -------------------------------------------------------------------------------- /Operator Overloading/addition_of_img_nos.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Operator Overloading/addition_of_img_nos.exe -------------------------------------------------------------------------------- /Friend_Function and Static_Members/Static.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Friend_Function and Static_Members/Static.exe -------------------------------------------------------------------------------- /Hello world/firstcode.Cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | cout << "Hello World!"; 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /Hello world/hello.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | 7 | cout << "HI"; 8 | 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /Operator Overloading/friend_function_op_overloading.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberpvn7/Cpp_Lang/HEAD/Operator Overloading/friend_function_op_overloading.exe -------------------------------------------------------------------------------- /Exception Handling/try.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int top = 1; 6 | cout << top--< 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | cout<<"hello World!"; 7 | getch(); 8 | return (); 9 | } 10 | -------------------------------------------------------------------------------- /sum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int sum = 0; 6 | int a,b; 7 | cin>>a>>b; 8 | sum = a+b; 9 | cout< 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | cout << hex << right<< showbase << nouppercase; 7 | cout << (long long)245454.5454 << endl; 8 | return 0; 9 | } -------------------------------------------------------------------------------- /Auti29.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int number; 6 | 7 | cout << "Enter an integer: "; 8 | cin >> number; 9 | 10 | cout << "You entered " << number; 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /Arrays/nestedloops.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | for(int i=0;i<3;i++){ 6 | for(int j=0; j<3; j++){ 7 | cout<< i << " "<< j<< endl; 8 | } 9 | } 10 | return 0; 11 | } -------------------------------------------------------------------------------- /Pointers/intro.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int ptr(){ 4 | return 10; 5 | } 6 | int main(){ 7 | int *p; 8 | p = new int[20]; 9 | int *q = &p[2]; 10 | int d = q -p; 11 | cout << p -2; 12 | return 0; 13 | } -------------------------------------------------------------------------------- /Recursion/printNTo1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void print(int n){ 5 | 6 | if(n < 1) 7 | return; 8 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | int n; 6 | 7 | cout << "Enter an integer: "; 8 | cin >> n; 9 | 10 | (n % 2 == 0) ? cout << n << " is even." : cout << n << " is odd."; 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /Recursion/factorial.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int factorial(int n){ 5 | 6 | if(n == 0 || n == 1) 7 | return 1; 8 | return n * factorial(n-1); 9 | } 10 | 11 | int main(){ 12 | 13 | cout< 2 | using namespace std; 3 | 4 | void print(int s , int n){ 5 | 6 | if(s > n) 7 | return; 8 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int arr[4][4],k=1; 6 | for(int i=0; i<4; i++){ 7 | for(int j=0; j<=i; j++){ 8 | cout< "; 5 | cin >> x; 6 | int ans = 0; 7 | while(x!=0){ 8 | ans = ans*10+x%10; 9 | x = x/10; 10 | } 11 | cout << "Revese integer is---> " << ans << endl; 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /factorial/factorial.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int n = 5, fact = 1, i; 8 | 9 | for(i=1; i<=n; i++) 10 | 11 | fact = fact * i; 12 | 13 | cout<<"Factorial of "< 2 | using namespace std; 3 | 4 | void print(int s , int n){ 5 | 6 | if(s < 1) 7 | return; 8 | print(s-1 , n); 9 | cout< 2 | using namespace std; 3 | 4 | void print(int s , int n){ 5 | 6 | if(s > n) 7 | return; 8 | print(s+1 , n); 9 | cout<> n; 9 | 10 | if ( n % 2 == 0) 11 | cout << n << " is even."; 12 | else 13 | cout << n << " is odd."; 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Loops/1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int A[8] = {7,8,4,6,45,10,15,70}, max; 6 | max = A[0]; 7 | for(auto x:A){ 8 | if(max <= x){ 9 | max =x; 10 | } 11 | } 12 | cout<< max; 13 | return 0; 14 | } -------------------------------------------------------------------------------- /Leetcode/1920BuildArrayfromPermutation.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector buildArray(vector& nums) { 4 | vector ans; 5 | for(int i=0; i 2 | using namespace std; 3 | void add(int a, int b) 4 | { 5 | cout << "sum = " << (a + b); 6 | } 7 | void add(double a, double b) 8 | { 9 | cout << endl << "sum = " << (a + b); 10 | } 11 | int main() 12 | { 13 | add(4, 2); 14 | add(2.3, 9.2); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /iostreams/file_writing.cpp: -------------------------------------------------------------------------------- 1 | // #include 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | ofstream outfile("My.txt"); 7 | outfile<< "Swaraj"<< endl; 8 | outfile<< "Mhatre"<< endl; 9 | outfile.clear(); 10 | outfile.close(); 11 | return 0; 12 | } -------------------------------------------------------------------------------- /DSA in CPP/Recursion/factorial.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int fun (int n){ 4 | if(n == 0){ 5 | return 1; 6 | } 7 | else{ 8 | return fun(n-1) *n; 9 | } 10 | } 11 | int main(){ 12 | int p= fun(5); 13 | cout << p; 14 | return 0; 15 | } -------------------------------------------------------------------------------- /DSA in CPP/Recursion/tree_recrursion.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | void fun(int n) 4 | { 5 | if (n > 0) 6 | { 7 | cout << n; 8 | fun(n - 1); 9 | fun(n - 1); 10 | } 11 | } 12 | int main() 13 | { 14 | int a =3; 15 | fun(a); 16 | return 0; 17 | } -------------------------------------------------------------------------------- /DSA in CPP/Recursion/Static_Global.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int x =0; 5 | int fun(int n){ 6 | 7 | if(n>0){ 8 | x++; 9 | return fun(n-1) +x; 10 | 11 | } 12 | return 0; 13 | } 14 | int main(){ 15 | int d =fun(5); 16 | cout < 2 | using namespace std; 3 | 4 | int fibonacci(int num){ 5 | 6 | if(num == 0) 7 | return 0; 8 | if(num == 1) 9 | return 1; 10 | return fibonacci(num-1) + fibonacci(num-2); 11 | } 12 | 13 | int main(){ 14 | 15 | cout< 4 | using namespace std; 5 | int main() 6 | { 7 | int a,b; 8 | a=15; 9 | b=40; 10 | cout< 2 | using namespace std; 3 | int Comb(int n, int r){ 4 | if(n==r || r== 0){ 5 | return 1; 6 | } 7 | else{ 8 | return Comb(n-1, r-1) + Comb(n-1, r); 9 | } 10 | } 11 | int main(){ 12 | cout<< Comb(5,2); 13 | return 0; 14 | } -------------------------------------------------------------------------------- /DSA in CPP/Recursion/Toer_Of_HAnoi.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | void Hanoi(int n, int A, int B, int C){ 4 | if(n>0){ 5 | Hanoi(n-1, A, C, B); 6 | cout << A << " to " << C << endl; 7 | Hanoi(n-1, B,A, C); 8 | } 9 | } 10 | int main(){ 11 | Hanoi(3, 1,2,3); 12 | return 0; 13 | } -------------------------------------------------------------------------------- /buy & sell/122BestTimeBuyandSell2.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxProfit(vector& prices) { 4 | 5 | int profit = 0; 6 | for(int i= prices.size()-1; i>0; i--) 7 | if(prices[i] > prices[i-1]) 8 | profit += prices[i] - prices[i-1]; 9 | return profit; 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /decimal_to_binary.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | 7 | int n; 8 | cin>>n; 9 | int ans=0; 10 | int i=0; 11 | while(n!=0){ 12 | 13 | int bit =n&1; 14 | ans=(bit*pow(10,i)) + ans; 15 | 16 | n=n>>1; 17 | i++; 18 | } 19 | 20 | cout<<"the binary form are:"< 2 | using namespace std; 3 | int main(){ 4 | int a[5][5]; 5 | for(int i=0;i<5;i++){ 6 | for(int j=0;j<5;j++){ 7 | cin>>a[i][j]; 8 | if(a[i][j]==1){ 9 | cout< 2 | using namespace std; 3 | 4 | void printName(string name , int cnt){ 5 | 6 | if(cnt == 5) 7 | return; 8 | cout< 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | ifstream infile("My.txt"); 7 | if(infile){cout << "file is open"<< endl;} 8 | string name; 9 | int no; 10 | infile >> name >> no; 11 | infile.close(); 12 | cout << name << " " << no; 13 | return 0; 14 | } -------------------------------------------------------------------------------- /Arrays/drawingpattern1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int count =1, i, j; 6 | for ( i = 0; i < 4; i++) 7 | { 8 | for ( j = 0; j < 4; j++) 9 | { 10 | cout << count << " "; 11 | count++; 12 | } 13 | cout<< endl; 14 | } 15 | 16 | return 0; 17 | } -------------------------------------------------------------------------------- /Cellpadding And Cellspacing Attributes.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | HTML TABLE 4 | 5 | 6 | 7 | 8 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |
Name 9 | Age 10 |
ANKUSH25
Raman35
20 | 21 | -------------------------------------------------------------------------------- /Concatenate String Objects: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | string s1, s2, result; 7 | 8 | cout << "Enter string s1: "; 9 | getline (cin, s1); 10 | 11 | cout << "Enter string s2: "; 12 | getline (cin, s2); 13 | 14 | result = s1 + s2; 15 | 16 | cout << "Resultant String = "<< result; 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Destructor/Destructor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Demo{ 4 | public: 5 | Demo(){ 6 | cout << "Demo created"; 7 | } 8 | ~Demo(){ 9 | cout << "Demo Destructed"; 10 | } 11 | }; 12 | void fun(){ 13 | Demo *p = new Demo(); 14 | delete p; 15 | } 16 | int main(){ 17 | fun(); 18 | return 0; 19 | } -------------------------------------------------------------------------------- /Pattern: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int rows; 7 | 8 | cout << "Enter number of rows: "; 9 | cin >> rows; 10 | 11 | for(int i = 1; i <= rows; ++i) 12 | { 13 | for(int j = 1; j <= i; ++j) 14 | { 15 | cout << "* "; 16 | } 17 | cout << "\n"; 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Cpp_Boolean: -------------------------------------------------------------------------------- 1 | Boolean Values 2 | A boolean variable is declared with the bool keyword and can only take the values true or false: 3 | 4 | Example 5 | bool isCodingFun = true; 6 | bool isFishTasty = false; 7 | cout << isCodingFun; // Outputs 1 (true) 8 | cout << isFishTasty; // Outputs 0 (false) 9 | 10 | From the example above, you can read that a true value returns 1, and false returns 0. 11 | -------------------------------------------------------------------------------- /Pattern.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int rows; 7 | 8 | cout << "Enter number of rows: "; 9 | cin >> rows; 10 | 11 | for(int i = 1; i <= rows; ++i) 12 | { 13 | for(int j = 1; j <= i; ++j) 14 | { 15 | cout << "* "; 16 | } 17 | cout << "\n"; 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Pattern2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int rows; 7 | 8 | cout << "Enter number of rows: "; 9 | cin >> rows; 10 | 11 | for(int i = 1; i <= rows; ++i) 12 | { 13 | for(int j = 1; j <= i; ++j) 14 | { 15 | cout << "* "; 16 | } 17 | cout << "\n"; 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /triangle.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int rows; 7 | 8 | cout << "Enter number of rows: "; 9 | cin >> rows; 10 | 11 | for(int i = 1; i <= rows; ++i) 12 | { 13 | for(int j = 1; j <= i; ++j) 14 | { 15 | cout << "* "; 16 | } 17 | cout << "\n"; 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Arrays/LinearSearch.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | int A[10] = {10,512,8,82,8,55,44,55,45,45}, key; 5 | cout << "Enter Key: "; 6 | cin >> key; 7 | for(int i =0; i< 10 ; i++){ 8 | 9 | if (key == A[i]){ 10 | cout << "Found at " << i << endl; 11 | return 0; 12 | } 13 | } 14 | cout << "Jane de n vro!"; 15 | } -------------------------------------------------------------------------------- /Pyramid/Pyramid.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int rows; 7 | 8 | cout << "Enter number of rows: "; 9 | cin >> rows; 10 | 11 | for(int i = 1; i <= rows; ++i) 12 | { 13 | for(int j = 1; j <= i; ++j) 14 | { 15 | cout << "* "; 16 | } 17 | cout << "\n"; 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /garvit128729.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | 6 | int first_number, second_number, sum; 7 | 8 | cout << "Enter two integers: "; 9 | cin >> first_number >> second_number; 10 | 11 | 12 | sum = first_number + second_number; 13 | 14 | 15 | cout << first_number << " + " << second_number << " = " << sum; 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Matrix/Krishnangshu_Paul.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int rows; 7 | 8 | cout << "Enter number of rows: "; 9 | cin >> rows; 10 | 11 | for(int i = 1; i <= rows; ++i) 12 | { 13 | for(int j = 1; j <= i; ++j) 14 | { 15 | cout << j << " "; 16 | } 17 | cout << "\n"; 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Namespace/namespace.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | namespace first 4 | { 5 | void fun(){ 6 | cout << "first"; 7 | 8 | } 9 | } // namespace fist 10 | 11 | namespace second 12 | { 13 | 14 | void fun(){ 15 | cout << "second"; 16 | } 17 | } // namespace second 18 | using namespace second; 19 | 20 | 21 | int main(){ 22 | fun(); 23 | return 0; 24 | } -------------------------------------------------------------------------------- /binarytodecimal/binarytodecimal.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int BinaryToDecimal(int n) 3 | { 4 | if(n==0) 5 | return 0; 6 | else 7 | return (n% 10 + 2* BinaryToDecimal(n / 10)); 8 | } 9 | int main() 10 | { 11 | int n; 12 | printf("Enter the Binary Value:"); 13 | scanf("%d",&n); 14 | printf("Decimal Value of Binary number is: %d",BinaryToDecimal(n)); 15 | return(0) 16 | } 17 | -------------------------------------------------------------------------------- /pattern/C++_upper_half_triangle.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | /* 5 | --> 5 6 | Output: 7 | * 8 | * * 9 | * * * 10 | * * * * 11 | * * * * * 12 | */ 13 | 14 | int main(){ 15 | cout << "-->"; 16 | int a; 17 | cin >> a; 18 | for(int i = 0; i 4 | using namespace std; 5 | 6 | int main(){ 7 | int n; 8 | int a[10]; 9 | int i=0; 10 | cout<<"Enter the integer number"<>n; 12 | while(n!=0){ 13 | int x = n%2; 14 | a[i++] = x; 15 | n=n/2; 16 | } 17 | for(int j=i-1;j>=0;j--){ 18 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int a = 5, b = 10, temp; 7 | 8 | cout << "Before swapping." << endl; 9 | cout << "a = " << a << ", b = " << b << endl; 10 | 11 | temp = a; 12 | a = b; 13 | b = temp; 14 | 15 | cout << "\nAfter swapping." << endl; 16 | cout << "a = " << a << ", b = " << b << endl; 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Arrays/drawingpattern2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int count =1, i, j; 6 | for ( i = 0; i < 4; i++) 7 | { 8 | for ( j = 0; j < 4 -i; j++) 9 | { 10 | 11 | { 12 | cout << "* "; 13 | } 14 | } 15 | 16 | cout << endl; 17 | } 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /Exception Handling/TandCBEtweenFunctions.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int Divide(int a, int b){ 4 | if(b == 0){ 5 | throw 404; 6 | } 7 | else{ 8 | return a/b; 9 | } 10 | } 11 | int main(){ 12 | try{ 13 | cout < 2 | using namespace std; 3 | int main() 4 | { 5 | int i,j,r,k; 6 | cout<<"Enter no. of rows u want to print: "; 7 | cin>>r; 8 | for(i=1;i<=r;i++) 9 | { 10 | for(j=1;j<=(r-i);j++) 11 | 12 | cout<<" "; 13 | for(k=1;k<=i;k++) 14 | cout<<" * "; 15 | cout<<"\n"; 16 | 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Array_sum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int sumof(int num[],int n){ 5 | int sum=0; 6 | for(int i=0; i>n; 15 | int num[100]; 16 | for(int i=0; i>num[i]; 18 | } 19 | 20 | cout<<"the sum of all value of array:"< 2 | using namespace std; 3 | 4 | int main(){ 5 | int count =1, i, j; 6 | for ( i = 0; i < 4; i++) 7 | { 8 | for ( j = 0; j < 4 -i; j++) 9 | { 10 | 11 | { 12 | cout << "* "; 13 | } 14 | } 15 | 16 | cout << endl; 17 | } 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /Polymorphism/function_overriding.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Base{ 4 | public: 5 | void display(){ 6 | cout << "Base class"<< endl; 7 | } 8 | }; 9 | class Derived : Base{ 10 | public: 11 | void display(int x){ 12 | cout << "Derived class"<< endl; 13 | } 14 | }; 15 | 16 | int main(){ 17 | Derived d; 18 | d.display(10); 19 | return 0; 20 | } -------------------------------------------------------------------------------- /armstrong_no.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int n,r,sum=0,temp; 6 | cout<<"Enter the Number= "; 7 | cin>>n; 8 | temp=n; 9 | while(n>0) 10 | { 11 | r=n%10; 12 | sum=sum+(r*r*r); 13 | n=n/10; 14 | } 15 | if(temp==sum) 16 | cout<<"Armstrong Number."< 2 | using namespace std; 3 | int main() 4 | { 5 | int n,r,sum=0,temp; 6 | cout<<"Enter the Number="; 7 | cin>>n; 8 | temp=n; 9 | while(n>0) 10 | { 11 | r=n%10; 12 | sum=(sum*10)+r; 13 | n=n/10; 14 | } 15 | if(temp==sum) 16 | cout<<"Number is Palindrome."; 17 | else 18 | cout<<"Number is not Palindrome."; 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Polymorphism/Virtual_Functions.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Base 4 | { 5 | public: 6 | virtual void fun()=0; 7 | }; 8 | class Derived : public Base 9 | { 10 | public: 11 | void fun() 12 | { 13 | cout << "Derived class" << endl; 14 | } 15 | }; 16 | 17 | int main() 18 | { 19 | Base b; 20 | Derived d; 21 | Base *ptr = &d; 22 | ptr->fun(); 23 | return 0; 24 | } -------------------------------------------------------------------------------- /factorial/palindrome.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int n,r,sum=0,temp; 6 | cout<<"Enter the Number="; 7 | cin>>n; 8 | temp=n; 9 | while(n>0) 10 | { 11 | r=n%10; 12 | sum=(sum*10)+r; 13 | n=n/10; 14 | } 15 | if(temp==sum) 16 | cout<<"Number is Palindrome."; 17 | else 18 | cout<<"Number is not Palindrome."; 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Recursion/Palindrome_check.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | bool isPalindrome(string str, int start, int end) 5 | { 6 | if(start >= end) 7 | return true; 8 | 9 | return ((str[start]==str[end]) && 10 | isPalindrome(str, start + 1, end - 1)); 11 | } 12 | 13 | int main() { 14 | 15 | string s = "GeekskeeG"; 16 | 17 | printf("%s", isPalindrome(s, 0, s.length() -1) ? "true" : "false"); 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /codejava237.java: -------------------------------------------------------------------------------- 1 | class Fibonacci { 2 | public static void main(String[] args) { 3 | 4 | int n = 100, firstTerm = 0, secondTerm = 1; 5 | 6 | System.out.println("Fibonacci Series Upto " + n + ": "); 7 | 8 | while (firstTerm <= n) { 9 | System.out.print(firstTerm + ", "); 10 | 11 | int nextTerm = firstTerm + secondTerm; 12 | firstTerm = secondTerm; 13 | secondTerm = nextTerm; 14 | 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /multiplication.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | double num1, num2, product; 6 | cout << "Enter two numbers: "; 7 | 8 | // stores two floating point numbers in num1 and num2 respectively 9 | cin >> num1 >> num2; 10 | 11 | // performs multiplication and stores the result in product variable 12 | product = num1 * num2; 13 | 14 | cout << "Product = " << product; 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Shivam_Mishra/MultipleRecursion.cpp: -------------------------------------------------------------------------------- 1 | // Fibonacci series by multiple recursion example 2 | 3 | #include 4 | using namespace std; 5 | 6 | int Fibbo(int n) 7 | { 8 | if(n<1) 9 | return 0; 10 | if(n==1) 11 | return 1; 12 | int flast = Fibbo(n-1); 13 | int slast = Fibbo(n-2); 14 | return flast+slast; 15 | } 16 | int main() 17 | { 18 | int n; 19 | cout << "Enter no for fibbonacci term : "; 20 | cin >> n; 21 | cout << Fibbo(n-1); 22 | return 0; 23 | } -------------------------------------------------------------------------------- /practical7.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | frmatting text Example 5 | 6 |

The following words uses an bold 7 | typeforce

8 |

The following words uses an italicized 9 | typeforce 10 |

The following words uses an underline 11 | typeforce

12 |

The following words user a strikethroughtypeforce 13 | 14 | -------------------------------------------------------------------------------- /fibonacci_sequence.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | int n1=0,n2=1,n3,i,number; 5 | cout<<"Enter the number of elements: "; 6 | cin>>number; 7 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | 6 | int first_number, second_number, sum; 7 | 8 | cout << "Enter two integers: "; 9 | cin >> first_number >> second_number; 10 | 11 | // sum of two numbers in stored in variable sumOfTwoNumbers 12 | sum = first_number + second_number; 13 | 14 | // prints sum 15 | cout << first_number << " + " << second_number << " = " << sum; 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /pascaltriangle.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int rows,coef=1,space,i,j; 6 | cout<<"Enter number of rows: "; 7 | cin>>rows; 8 | for(i=0;i 2 | using namespace std; 3 | 4 | void reverse(int arr[] , int left , int right){ 5 | if(left >= right) 6 | return; 7 | 8 | swap(arr[left] , arr[right]); 9 | reverse(arr , left+1 , right-1); 10 | } 11 | 12 | int main(){ 13 | 14 | int arr[] = {1,2,3,4,5}; 15 | int n = sizeof(arr)/sizeof(arr[0]); 16 | reverse(arr,0,n-1); 17 | for(int i = 0 ; i 2 | using namespace std; 3 | 4 | //parametarized recursion 5 | // void add(int i , int sum){ 6 | 7 | // if(i < 1){ 8 | // cout< 2 | #include 3 | using namespace std; 4 | void bintodec(int n) 5 | { 6 | int rem, dec = 0; 7 | rem = n % 10; 8 | n = n / 10; 9 | dec = rem; 10 | for (int i = 1; n != 0; i++) 11 | { 12 | rem = n % 10; 13 | dec = pow(2, i) * rem + dec; 14 | n = n / 10; 15 | } 16 | cout << dec << endl; 17 | } 18 | int main() 19 | { 20 | int bin; 21 | cin >> bin; 22 | bintodec(bin); 23 | } 24 | -------------------------------------------------------------------------------- /java code 1: -------------------------------------------------------------------------------- 1 | public class Main { 2 | 3 | public static void main(String[] args) { 4 | 5 | int num = 29; 6 | boolean flag = false; 7 | for (int i = 2; i <= num / 2; ++i) { 8 | // condition for nonprime number 9 | if (num % i == 0) { 10 | flag = true; 11 | break; 12 | } 13 | } 14 | 15 | if (!flag) 16 | System.out.println(num + " is a prime number."); 17 | else 18 | System.out.println(num + " is not a prime number."); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Ak6.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int n; 6 | long factorial = 1.0; 7 | 8 | cout << "Enter a positive integer: "; 9 | cin >> n; 10 | 11 | if (n < 0) 12 | cout << "Error! Factorial of a negative number doesn't exist."; 13 | else { 14 | for(int i = 1; i <= n; ++i) { 15 | factorial *= i; 16 | } 17 | cout << "Factorial of " << n << " = " << factorial; 18 | } 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Invert_pyramid.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | /* 4 | * * * * * * * * * 5 | * * * * * * * 6 | * * * * * 7 | * * * 8 | * 9 | */ 10 | main(){ 11 | cout << "--->"; 12 | int a; 13 | cin >> a; 14 | for(int i=0;i 3 | using namespace std; 4 | class base{ 5 | public: 6 | int x; 7 | int y; 8 | void data(){ 9 | x=10; 10 | y=20; 11 | cout< 2 | using namespace std; 3 | /* 4 | * * * * * * * * * 5 | * * * * * * * 6 | * * * * * 7 | * * * 8 | * 9 | */ 10 | main(){ 11 | cout << "--->"; 12 | int a; 13 | cin >> a; 14 | for(int i=0;i 2 | using namespace std; 3 | 4 | int main() { 5 | 6 | int year; 7 | cout << "Enter a year: "; 8 | cin >> year; 9 | if (year % 400 == 0) { 10 | cout << year << " is a leap year."; 11 | } 12 | else if (year % 100 == 0) { 13 | cout << year << " is not a leap year."; 14 | } 15 | else if (year % 4 == 0) { 16 | cout << year << " is a leap year."; 17 | } 18 | else { 19 | cout << year << " is not a leap year."; 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Any 2.cpp: -------------------------------------------------------------------------------- 1 | // Factorial of n = 1*2*3*...*n 2 | 3 | #include 4 | using namespace std; 5 | 6 | int factorial(int); 7 | 8 | int main() { 9 | int n, result; 10 | 11 | cout << "Enter a non-negative number: "; 12 | cin >> n; 13 | 14 | result = factorial(n); 15 | cout << "Factorial of " << n << " = " << result; 16 | return 0; 17 | } 18 | 19 | int factorial(int n) { 20 | if (n > 1) { 21 | return n * factorial(n - 1); 22 | } else { 23 | return 1; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /FibonacciRecursion.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int fib(int n) 4 | { 5 | if(n==0) 6 | return 0; 7 | else if(n==1) 8 | return 1; 9 | else 10 | return fib(n-1)+fib(n-2); 11 | } 12 | int main() 13 | { 14 | int n,i,sum=0; 15 | cout<<"Enter no. of terms until which u want to print and sum: "; 16 | cin>>n; 17 | for(i=0;i 2 | using namespace std; 3 | int main() 4 | { 5 | int n, i, m=0, flag=0; 6 | cout << "Enter the Number to check Prime: "; 7 | cin >> n; 8 | m=n/2; 9 | for(i = 2; i <= m; i++) 10 | { 11 | if(n % i == 0) 12 | { 13 | cout<<"Number is not Prime."< 2 | using namespace std; 3 | 4 | int main() { 5 | int n1, n2, hcf; 6 | cout << "Enter two numbers: "; 7 | cin >> n1 >> n2; 8 | 9 | // swapping variables n1 and n2 if n2 is greater than n1. 10 | if ( n2 > n1) { 11 | int temp = n2; 12 | n2 = n1; 13 | n1 = temp; 14 | } 15 | 16 | for (int i = 1; i <= n2; ++i) { 17 | if (n1 % i == 0 && n2 % i ==0) { 18 | hcf = i; 19 | } 20 | } 21 | 22 | cout << "HCF = " << hcf; 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Prefix/Reverse_prefix.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string reversePrefix(string word, char ch) { 4 | string r=""; 5 | int i,j; 6 | size_t found = word.find(ch); 7 | if(found==string::npos){ 8 | return word; 9 | } 10 | for(i=0;i<=found;i++){ 11 | r+=word[i]; 12 | } 13 | reverse(r.begin(),r.end()); 14 | for(j=i;j 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | long factorial = 1.0; 8 | 9 | cout << "Enter a positive integer: "; 10 | cin >> n; 11 | 12 | if (n < 0) 13 | cout << "Error! Factorial of a negative number doesn't exist."; 14 | else { 15 | for(int i = 1; i <= n; ++i) { 16 | factorial *= i; 17 | } 18 | cout << "Factorial of " << n << " = " << factorial; 19 | } 20 | 21 | return 0; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /factorial/factorial3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int n; 6 | long factorial = 1.0; 7 | 8 | cout << "Enter a positive integer: "; 9 | cin >> n; 10 | 11 | if (n < 0) 12 | cout << "Error! Factorial of a negative number doesn't exist."; 13 | else { 14 | for(int i = 1; i <= n; ++i) { 15 | factorial *= i; 16 | } 17 | cout << "Factorial of " << n << " = " << factorial; 18 | } 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /ifelse.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main () { 5 | // local variable declaration: 6 | int a = 100; 7 | 8 | // check the boolean condition 9 | if( a < 20 ) { 10 | // if condition is true then print the following 11 | cout << "a is less than 20;" << endl; 12 | } else { 13 | // if condition is false then print the following 14 | cout << "a is not less than 20;" << endl; 15 | } 16 | cout << "value of a is : " << a << endl; 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Hcf.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int hcf(int n1, int n2); 6 | 7 | int main() 8 | 9 | { 10 | 11 | int n1, n2; 12 | 13 | cout << "Enter two positive integers: "; 14 | 15 | cin >> n1 >> n2; 16 | 17 | cout << "H.C.F of " << n1 << " & " << n2 << " is: " << hcf(n1, n2); 18 | 19 | return 0; 20 | 21 | } 22 | 23 | int hcf(int n1, int n2) 24 | 25 | { 26 | 27 | if (n2 != 0) 28 | 29 | return hcf(n2, n1 % n2); 30 | 31 | else 32 | 33 | return n1; 34 | 35 | } 36 | -------------------------------------------------------------------------------- /factorial/factorial2.cpp: -------------------------------------------------------------------------------- 1 | // Factorial of n = 1*2*3*...*n 2 | 3 | #include 4 | using namespace std; 5 | 6 | int factorial(int); 7 | 8 | int main() { 9 | int n, result; 10 | 11 | cout << "Enter a non-negative number: "; 12 | cin >> n; 13 | 14 | result = factorial(n); 15 | cout << "Factorial of " << n << " = " << result; 16 | return 0; 17 | } 18 | 19 | int factorial(int n) { 20 | if (n > 1) { 21 | return n * factorial(n - 1); 22 | } else { 23 | return 1; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /pattern/C++_pyramid_triangle.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | /* 4 | --->5 5 | * 6 | * * * 7 | * * * * * 8 | * * * * * * * 9 | * * * * * * * * * 10 | */ 11 | int main(){ 12 | cout << "--->"; 13 | int a; 14 | cin >> a; 15 | for(int i =0;i 2 | using namespace std; 3 | int max(int a, int b){ 4 | return a > b? a:b; 5 | 6 | } 7 | 8 | int min(int *a, int *b ){ 9 | cout << *a; 10 | cout << *b; 11 | // return a < b? a:b; 12 | } 13 | int main(){ 14 | int x = 10, y =20; 15 | int *q = &x; 16 | int *r = &y; 17 | 18 | int (*p)(int *,int *); 19 | // p = max; 20 | // cout << "Max is "<< p(5,10)<< endl; 21 | p = min; 22 | cout <<"Min is "<< p(q,r); 23 | return 0; 24 | } -------------------------------------------------------------------------------- /Recursion/PalindromeString.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | bool palindrome(string name , int i , int n){ 5 | 6 | if(i >= n/2) 7 | return true; 8 | if(name[i] != name[n-i-1]) 9 | return false; 10 | return palindrome(name, i+1 , n); 11 | } 12 | 13 | int main(){ 14 | 15 | string name = "MadaM"; 16 | int n = name.size(); 17 | if(palindrome(name , 0 , n)) 18 | cout<<"String is palindrome"; 19 | else 20 | cout<<"String is not palindrome"; 21 | return 0; 22 | } -------------------------------------------------------------------------------- /array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int largest(int arr[], int n) 5 | { 6 | int i; 7 | 8 | 9 | int max = arr[0]; 10 | 11 | 12 | for (i = 1; i < n; i++) 13 | if (arr[i] > max) 14 | max = arr[i]; 15 | 16 | return max; 17 | } 18 | 19 | 20 | int main() 21 | { 22 | int arr[] = {10, 324, 45, 90, 9808}; 23 | int n = sizeof(arr) / sizeof(arr[0]); 24 | cout << "Largest in given array is " 25 | << largest(arr, n); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /linearsearch.CPP: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int search(int arr[], int N, int x) 5 | { 6 | int i; 7 | for (i = 0; i < N; i++) 8 | if (arr[i] == x) 9 | return i; 10 | return -1; 11 | } 12 | 13 | int main(void) 14 | { 15 | int arr[] = { 2, 3, 4, 10, 40 }; 16 | int x = 10; 17 | int N = sizeof(arr) / sizeof(arr[0]); 18 | 19 | int result = search(arr, N, x); 20 | (result == -1) 21 | ? cout << "Element is not present in array" 22 | : cout << "Element is present at index " << result; 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /mustafa.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | char s1[100] = "programming ", s2[] = "is awesome"; 4 | int length, j; 5 | 6 | // store length of s1 in the length variable 7 | length = 0; 8 | while (s1[length] != '\0') { 9 | ++length; 10 | } 11 | 12 | // concatenate s2 to s1 13 | for (j = 0; s2[j] != '\0'; ++j, ++length) { 14 | s1[length] = s2[j]; 15 | } 16 | 17 | // terminating the s1 string 18 | s1[length] = '\0'; 19 | 20 | printf("After concatenation: "); 21 | puts(s1); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /factorial/factorial4.cpp: -------------------------------------------------------------------------------- 1 | // Factorial of n = 1*2*3*...*n 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int factorial(int); 8 | 9 | int main() { 10 | int n, result; 11 | 12 | cout << "Please enter a non-negative number: "; 13 | cin >> n; 14 | 15 | result = factorial(n); 16 | cout << "Factorial of " << n << " = " << result; 17 | return 0; 18 | } 19 | 20 | int factorial(int n) { 21 | if (n > 1) { 22 | return n * factorial(n - 1); 23 | } else { 24 | return 1; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /linear & binary search/linear_search.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int arr[10], i, num, index; 6 | cout<<"Enter 10 Numbers: "; 7 | for(i=0; i<10; i++) 8 | cin>>arr[i]; 9 | cout<<"\nEnter a Number to Search: "; 10 | cin>>num; 11 | for(i=0; i<10; i++) 12 | { 13 | if(arr[i]==num) 14 | { 15 | index = i; 16 | break; 17 | } 18 | } 19 | cout<<"\nFound at Index No."< 2 | using namespace std; 3 | /* 4 | * * * * * * * * * 5 | * * * * * * * 6 | * * * * * 7 | * * * 8 | * 9 | */ 10 | int main(){ 11 | cout << "--->"; 12 | int a; 13 | cin >> a; 14 | for(int i =0;i 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | float n1, n2, n3; 8 | 9 | cout << "Enter three numbers: "; 10 | 11 | cin >> n1 >> n2 >> n3; 12 | 13 | if(n1 >= n2 && n1 >= n3) 14 | 15 | cout << "Largest number: " << n1; 16 | 17 | if(n2 >= n1 && n2 >= n3) 18 | 19 | cout << "Largest number: " << n2; 20 | 21 | 22 | 23 | if(n3 >= n1 && n3 >= n2) 24 | 25 | cout << "Largest number: " << n3; 26 | 27 | 28 | 29 | return 0; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Check Palindrome String: -------------------------------------------------------------------------------- 1 | class Main { 2 | public static void main(String[] args) { 3 | 4 | String str = "Radar", reverseStr = ""; 5 | 6 | int strLength = str.length(); 7 | 8 | for (int i = (strLength - 1); i >=0; --i) { 9 | reverseStr = reverseStr + str.charAt(i); 10 | } 11 | 12 | if (str.toLowerCase().equals(reverseStr.toLowerCase())) { 13 | System.out.println(str + " is a Palindrome String."); 14 | } 15 | else { 16 | System.out.println(str + " is not a Palindrome String."); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Dynamic Programming/fibonacii number using dp.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define ll long long int 4 | ll FunctionEntered=0; 5 | ll dp[100]={0}; 6 | ll f(ll a) 7 | { 8 | FunctionEntered++; 9 | if(a==1||a==2) 10 | return 1; 11 | if(dp[a]!=0) 12 | return dp[a]; 13 | dp[a]=f(a-1)+f(a-2); 14 | return dp[a]; 15 | } 16 | int main() 17 | { 18 | ll n; 19 | cin>>n; 20 | cout< 2 | 3 | Login form Design 4 | 5 |

6 | 7 | Login Here 8 |
9 |

Username

10 | 11 |

Password

12 | 13 | 14 | Lost your password?
15 | Don't have an account?
16 |
17 |
18 | 19 | 20 | -------------------------------------------------------------------------------- /Base Class Pointer/try.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Base{ 4 | public: 5 | void f1(){ 6 | cout<< "Function of base class"<< endl; 7 | } 8 | }; 9 | class Derived: public Base{ 10 | public: 11 | void f2(){ 12 | cout<< "Function of Derived class"<< endl; 13 | } 14 | }; 15 | void demo(){ 16 | cout<<"chal chaL ave "<< endl; 17 | demo(); 18 | } 19 | int main(){ 20 | Derived b; 21 | Base *p = &b; 22 | // p->f1(); 23 | // p->f2(); 24 | demo(); 25 | return 0; 26 | } -------------------------------------------------------------------------------- /pattern/C++_invert_V-shape.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | /* 4 | * 5 | * * 6 | * * 7 | * * 8 | * * 9 | */ 10 | int main(){ 11 | cout << "--->"; 12 | int a; 13 | cin >> a; 14 | for(int i =0;i 2 | using namespace std; 3 | int main () 4 | { 5 | int num, i, count = 0; 6 | cout <<"Enter the number: "; 7 | cin >> num; 8 | if (num == 0) 9 | { 10 | cout <<"\n"< 1) 20 | cout <<"\n"< 2 | #include 3 | #include 4 | using namespace std; 5 | int main() 6 | { 7 | while (true) 8 | { 9 | system("cls"); 10 | //getting local time 11 | time_t t = time(NULL); 12 | //printing time 13 | cout << "\n\nProgrammopedia Clock Local time\n"; 14 | cout << "_______________________________\n\n"; 15 | cout << " " << ctime(&t) << endl; 16 | cout << "_______________________________\n\n"; 17 | Sleep(1000); 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Leetcode/2095DeleteMiddleNodeLL.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | ListNode* deleteMiddle(ListNode* head) { 4 | ListNode* temp = head; 5 | int cnt = 0; 6 | while(temp!=NULL){ 7 | temp = temp->next; 8 | cnt++; 9 | } 10 | if(cnt==1){ 11 | return NULL; 12 | } 13 | cnt = cnt/2; 14 | temp = head; 15 | for(int i=1; inext; 17 | } 18 | temp->next = temp->next->next; 19 | return head; 20 | } 21 | }; -------------------------------------------------------------------------------- /b.java: -------------------------------------------------------------------------------- 1 | // reverse the given string 2 | public class reverse_string { 3 | public static void main(String args[]){ 4 | String s="MADAM"; 5 | String temp=s; 6 | int n=s.length(); 7 | String ans=""; 8 | for(int i=n-1;i>=0;i--){ 9 | ans+=s.charAt(i); 10 | } 11 | System.out.println(ans); 12 | if(ans.equals(ans)){ 13 | System.out.println("given string is plindrome"); 14 | } 15 | else{ 16 | System.out.println("given string is not plindrome"); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /c.java: -------------------------------------------------------------------------------- 1 | // reverse the given string 2 | public class reverse_string { 3 | public static void main(String args[]){ 4 | String s="MADAM"; 5 | String temp=s; 6 | int n=s.length(); 7 | String ans=""; 8 | for(int i=n-1;i>=0;i--){ 9 | ans+=s.charAt(i); 10 | } 11 | System.out.println(ans); 12 | if(ans.equals(ans)){ 13 | System.out.println("given string is plindrome"); 14 | } 15 | else{ 16 | System.out.println("given string is not plindrome"); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Vivek Kumar: -------------------------------------------------------------------------------- 1 | // convert binary to decimal 2 | 3 | #include 4 | #include 5 | 6 | // function prototype 7 | int convert(long long); 8 | 9 | int main() { 10 | long long n; 11 | printf("Enter a binary number: "); 12 | scanf("%lld", &n); 13 | printf("%lld in binary = %d in decimal", n, convert(n)); 14 | return 0; 15 | } 16 | 17 | // function definition 18 | int convert(long long n) { 19 | int dec = 0, i = 0, rem; 20 | 21 | while (n!=0) { 22 | rem = n % 10; 23 | n /= 10; 24 | dec += rem * pow(2, i); 25 | ++i; 26 | } 27 | 28 | return dec; 29 | } 30 | -------------------------------------------------------------------------------- /Loops/nested_loop_in_cpp: -------------------------------------------------------------------------------- 1 | // C program to illustrate nested-if statement 2 | 3 | #include 4 | 5 | int main() 6 | { 7 | int i = 10; 8 | 9 | if (i == 10) { 10 | // First if statement 11 | if (i < 15) 12 | printf("i is smaller than 15\n"); 13 | 14 | // Nested - if statement 15 | // Will only be executed if statement above 16 | // is true 17 | if (i < 12) 18 | printf("i is smaller than 12 too\n"); 19 | else 20 | printf("i is greater than 15"); 21 | } 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Leetcode/2181MergeNodesBetweenZeros.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | ListNode* mergeNodes(ListNode* head) { 4 | head = head->next; 5 | ListNode* temp = head; 6 | ListNode* temp2 = head; 7 | while(temp!=NULL){ 8 | temp = temp->next; 9 | while(temp->val!=0){ 10 | temp2->val += temp->val; 11 | temp = temp->next; 12 | } 13 | temp = temp->next; 14 | temp2->next = temp; 15 | temp2 = temp2->next; 16 | } 17 | return head; 18 | } 19 | }; -------------------------------------------------------------------------------- /TestDictionary.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | class TestDictionary 3 | { 4 | public static void main(String[] args) 5 | { 6 | Dictionary d=new Hashtable(); 7 | d.put(101,"Java"); 8 | d.put(102,"HTML"); 9 | d.put(103,"C++"); 10 | d.put(103,"OS"); 11 | d.put(104,"C++"); 12 | System.out.println(d); 13 | System.out.println("Size of dictionary :"+d.size()); 14 | System.out.println("at index 102 key value :"+d.get(102)); 15 | System.out.println("Dictionary is Empty or not :"+d.isEmpty()); 16 | System.out.println("103 index key removed :"+d.remove(103)); 17 | System.out.println("Updated Dictionary:"+d); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Apoorva/RecursiveCombinationFormula.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // Function to calculate Combination 5 | float combination(float n, float r) 6 | { 7 | int i, res; 8 | if(r > 0) 9 | return (n / r) * combination(n - 1, r - 1); 10 | else 11 | return 1; 12 | } 13 | 14 | int main() 15 | { 16 | float n, r; 17 | int result; 18 | cout<<"\nProgram for calculating Combination ( nCr formula )"; 19 | cout<<"\n\nEnter the value of n = "; 20 | cin>>n; 21 | cout<<"\nEnter the value of r = "; 22 | cin>>r; 23 | 24 | cout<<"\n\nNumber of possible Combinations = "< 2 | using namespace std; 3 | class Rectangle 4 | { 5 | public: 6 | int length, breadth; 7 | int area() 8 | { 9 | return length * breadth; 10 | } 11 | int Perimeter(); 12 | }; 13 | int Rectangle::Perimeter() 14 | { 15 | return 2 * (length + breadth); 16 | } 17 | 18 | int main() 19 | { 20 | Rectangle r; 21 | 22 | Rectangle *p = new Rectangle(); 23 | // r.length = 10; 24 | p->length = 10; 25 | p->breadth = 5; 26 | cout << p->area(); 27 | cout << p->Perimeter(); 28 | return 0; 29 | } -------------------------------------------------------------------------------- /Bubble sort/bubble-sort.cpp: -------------------------------------------------------------------------------- 1 | //recursive implementation 2 | #include 3 | using namespace std; 4 | void bubblesort(int arr[], int n) 5 | { 6 | if (n == 0 || n == 1) 7 | { 8 | return; 9 | } 10 | for (int i = 0; i < n - 1; i++) 11 | { 12 | if (arr[i] > arr[i + 1]) 13 | { 14 | swap(arr[i], arr[i + 1]); 15 | } 16 | } 17 | bubblesort(arr, n - 1); 18 | } 19 | int main() 20 | { 21 | int arr[5] = {4, 6, 9, 10, 2}; 22 | bubblesort(arr, 5); 23 | for (int i = 0; i < 5; i++) 24 | { 25 | cout << arr[i] << " "; 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Arrays/drawingpattern3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int count =1, i, j; 6 | for ( i = 0; i < 4; i++) 7 | { 8 | for ( j = 0; j < 4; j++) 9 | { 10 | 11 | if (i > j) 12 | { 13 | cout << " "; 14 | } 15 | else{ 16 | cout << "*"; 17 | } 18 | 19 | } 20 | for (int k = 0; k < 3 -i; k++) 21 | { 22 | cout << "*"; 23 | } 24 | 25 | cout << endl; 26 | } 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /Binary Seach/binary_search_with _recursion.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int binary_search(int a[],int data,int l,int r) 4 | { if(l>r) return -1; 5 | int m=(l+r)/2; 6 | if(a[m]>data) 7 | return binary_search(a,data,l,m-1); 8 | else if(a[m]>n; 17 | int a[n]; 18 | int data; 19 | for(int i=0;i>a[i]; 21 | cin>>data; 22 | sort(a,a+n); 23 | cout< 2 | using namespace std; 3 | class Base{ 4 | public: 5 | Base(){ 6 | cout<< "Default of Base" << endl; 7 | } 8 | Base(int a){ 9 | cout<< "Parameterised of Base " << a<< endl; 10 | } 11 | }; 12 | class Derived : public Base{ 13 | public: 14 | Derived(){ 15 | cout << "Default of Derived"<< endl; 16 | } 17 | Derived(int a, int b): Base(a){ 18 | cout<< "Parameterised of Derived " << b << endl; 19 | } 20 | 21 | }; 22 | int main(){ 23 | int a =10 ,b =20; 24 | Derived d(a, b); 25 | 26 | return 0; 27 | } -------------------------------------------------------------------------------- /vm.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | double first, second, temp; 4 | printf("Enter first number: "); 5 | scanf("%lf", &first); 6 | printf("Enter second number: "); 7 | scanf("%lf", &second); 8 | 9 | // value of first is assigned to temp 10 | temp = first; 11 | 12 | // value of second is assigned to first 13 | first = second; 14 | 15 | // value of temp (initial value of first) is assigned to second 16 | second = temp; 17 | 18 | // %.2lf displays number up to 2 decimal points 19 | printf("\nAfter swapping, first number = %.2lf\n", first); 20 | printf("After swapping, second number = %.2lf", second); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Arrays/numpy.cpp: -------------------------------------------------------------------------------- 1 | # Python program to demonstrate 2 | # basic array characteristics 3 | import numpy as np 4 | 5 | # Creating array object 6 | arr = np.array( [[ 1, 2, 3], 7 | [ 4, 2, 5]] ) 8 | 9 | # Printing type of arr object 10 | print("Array is of type: ", type(arr)) 11 | 12 | # Printing array dimensions (axes) 13 | print("No. of dimensions: ", arr.ndim) 14 | 15 | # Printing shape of array 16 | print("Shape of array: ", arr.shape) 17 | 18 | # Printing size (total number of elements) of array 19 | print("Size of array: ", arr.size) 20 | 21 | # Printing type of elements in array 22 | print("Array stores elements of type: ", arr.dtype) 23 | -------------------------------------------------------------------------------- /Arrays/BinarySearch.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int A[10] = {1, 5, 8, 9, 12, 16, 18, 24, 28, 36}, key, l = 0, h = 9, mid; 7 | cout << "Enter Key: "; 8 | cin >> key; 9 | while (l < h) 10 | { 11 | mid = (l + h) / 2; 12 | if (A[mid] == key) 13 | { 14 | cout << "Found at " << mid << endl; 15 | return 0; 16 | } 17 | else if(A[mid] < key) 18 | { 19 | l = mid + 1; 20 | } 21 | else 22 | { 23 | h = mid - 1; 24 | } 25 | } 26 | cout << "Not found"; 27 | } -------------------------------------------------------------------------------- /DSA in CPP/Array Adt/delete.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | struct Array 4 | { 5 | /* data */ 6 | int A[10]; 7 | int size; 8 | int length; 9 | 10 | }; 11 | 12 | int Delete(struct Array *arr, int index){ 13 | int x=0, i=0; 14 | if(index>=0 && index < arr->length){ 15 | x = arr->A[index]; 16 | for(i = index; i < arr->length-1 ; i++){ 17 | arr->A[i]= arr->A[i+1]; 18 | arr->length--; 19 | return x; 20 | } 21 | return 0; 22 | } 23 | return 0; 24 | } 25 | int main(){ 26 | struct Array arr1 = {{1,2,3,4,5,6,7,8},10,8}; 27 | cout << Delete(&arr1, 4); 28 | return 0; 29 | } -------------------------------------------------------------------------------- /dav/operator-overloading.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class ComplexNumber{ 5 | private: 6 | int real; 7 | int imaginary; 8 | public: 9 | ComplexNumber(int real, int imaginary){ 10 | this->real = real; 11 | this->imaginary = imaginary; 12 | } 13 | void print(){ 14 | cout<real+c2.real; 19 | c3.imaginary = this->imaginary + c2.imaginary; 20 | return c3; 21 | } 22 | }; 23 | int main() { 24 | ComplexNumber c1(3,5); 25 | ComplexNumber c2(2,4); 26 | ComplexNumber c3 = c1 + c2; 27 | c3.print(); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Bubble sort/bubblesort.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | using namespace std; 4 | 5 | 6 | void bubbleSort(int arr[], int n) 7 | { 8 | int i, j; 9 | for (i = 0; i < n - 1; i++) 10 | 11 | 12 | for (j = 0; j < n - i - 1; j++) 13 | if (arr[j] > arr[j + 1]) 14 | swap(arr[j], arr[j + 1]); 15 | } 16 | 17 | 18 | void printArray(int arr[], int size) 19 | { 20 | int i; 21 | for (i = 0; i < size; i++) 22 | cout << arr[i] << " "; 23 | cout << endl; 24 | } 25 | 26 | 27 | int main() 28 | { 29 | int arr[] = { 5, 1, 4, 2, 8}; 30 | int N = sizeof(arr) / sizeof(arr[0]); 31 | bubbleSort(arr, N); 32 | cout << "Sorted array: \n"; 33 | printArray(arr, N); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Binary Seach/binary_search_using_while_loop(iteration).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int binary_search(int a[],int n,int data) 4 | { 5 | int l=0; 6 | int r=n-1; 7 | int m; 8 | while(l<=r) 9 | { 10 | m=(l+r)/2; 11 | if(a[m]>data) 12 | r=m-1; 13 | if(a[m]>n; 26 | int a[n]; 27 | int data; 28 | for(int i=0;i>a[i]; 30 | cin>>data; 31 | cout< 6 | 7 | int search(int arr[], int N, int x) 8 | { 9 | int i; 10 | for (i = 0; i < N; i++) 11 | if (arr[i] == x) 12 | return i; 13 | return -1; 14 | } 15 | 16 | // Driver's code 17 | int main(void) 18 | { 19 | int arr[] = { 2, 3, 4, 10, 40 }; 20 | int x = 10; 21 | int N = sizeof(arr) / sizeof(arr[0]); 22 | 23 | // Function call 24 | int result = search(arr, N, x); 25 | (result == -1) 26 | ? printf("Element is not present in array") 27 | : printf("Element is present at index %d", result); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /roots/roots.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main(){ 4 | int a,b,c; 5 | float d,root1,root2,rroot,iroot; 6 | printf("enter a,b,c:-"); 7 | scanf("%d%d%d",&a,&b,&c); 8 | d=pow(b,2)-(4*a*c); 9 | if (d>0) 10 | { 11 | printf("real roots\n"); 12 | root1=-b+sqrt(d)/(2*a); 13 | root2=-b-sqrt(d)/(2*a); 14 | printf("the roots are: %.2f and %.2f",root1,root2); 15 | 16 | } 17 | else{ 18 | printf("imaginary roots\n"); 19 | rroot=-b/(2*a); 20 | iroot=sqrt(d)/(2*a); 21 | printf("the roots are: %.2f + %.2fi\n and %.2f - %.2fi",rroot,iroot,rroot,iroot); 22 | 23 | 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Bubble sort/Bubble_sort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main () 4 | { 5 | int i, j,temp,pass=0; 6 | int a[10] = {10,2,0,14,43,25,18,1,5,45}; 7 | cout <<"Input list ...\n"; 8 | for(i = 0; i<10; i++) { 9 | cout < 2 | using namespace std; 3 | int main () 4 | { 5 | int i, j,temp,pass=0; 6 | int a[10] = {10,2,0,14,43,25,18,1,5,45}; 7 | cout <<"Input list ...\n"; 8 | for(i = 0; i<10; i++) { 9 | cout < 2 | using namespace std; 3 | 4 | { 5 | while (start < end) 6 | { 7 | int temp = arr[start]; 8 | arr[start] = arr[end]; 9 | arr[end] = temp; 10 | start++; 11 | end--; 12 | } 13 | } 14 | void printArray(int arr[], int size) 15 | { 16 | for (int i = 0; i < size; i++) 17 | cout << arr[i] << " "; 18 | 19 | cout << endl; 20 | } 21 | int main() 22 | { 23 | int arr[] = {0, 1, 2, 3, 4, 5}; 24 | 25 | int n = sizeof(arr) / sizeof(arr[0]); 26 | printArray(arr, n); 27 | rvereseArray(arr, 0, n-1); 28 | cout << "Reversed array is" << endl; 29 | printArray(arr, n); 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Recursion/printSubsequence.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void printSubseq(int arr[] , vector &ans , int index , int size){ 5 | 6 | if(index >= size){ 7 | for(auto it : ans) 8 | cout< ans; 27 | printSubseq(arr,ans,0,3); 28 | return 0; 29 | } -------------------------------------------------------------------------------- /ASHISH: -------------------------------------------------------------------------------- 1 | public class DecimalToBinaryExample2{ 2 | public static void toBinary(int decimal){ 3 | int binary[] = new int[40]; 4 | int index = 0; 5 | while(decimal > 0){ 6 | binary[index++] = decimal%2; 7 | decimal = decimal/2; 8 | } 9 | for(int i = index-1;i >= 0;i--){ 10 | System.out.print(binary[i]); 11 | } 12 | System.out.println();//new line 13 | } 14 | public static void main(String args[]){ 15 | System.out.println("Decimal of 10 is: "); 16 | toBinary(10); 17 | System.out.println("Decimal of 21 is: "); 18 | toBinary(21); 19 | System.out.println("Decimal of 31 is: "); 20 | toBinary(31); 21 | }} 22 | -------------------------------------------------------------------------------- /Binary Seach/Binary_Seach.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int binarysearch(int arr[], int n, int k) // k is key, n is arr size 5 | { 6 | int lo = 0, hi = n - 1; 7 | 8 | while (lo <= hi) 9 | { 10 | int mid = lo + (hi-lo) / 2; 11 | 12 | if (arr[mid] == k) 13 | return mid; 14 | else if (arr[mid] < k) 15 | lo = mid + 1; 16 | else 17 | hi = mid - 1; 18 | } 19 | return -1; 20 | } 21 | 22 | int main() 23 | { 24 | int arr[]{2, 5, 8, 12, 17, 24, 36, 56, 78}; 25 | int size = sizeof(arr) / sizeof(arr[0]); 26 | 27 | int k = 24; 28 | 29 | cout << binarysearch(arr, size, k); 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Dynamic Programming/coin_change_dpsolution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int getRes(int coins[], int n, int sum){ 5 | int dp[sum+1][n+1]; 6 | for(int i=0;i<=n;i++) 7 | dp[0][i]=1; 8 | for(int i=1;i<=sum;i++) 9 | dp[i][0]=0; 10 | for(int i=1;i<=sum;i++){ 11 | for(int j=1;j<=n;j++){ 12 | dp[i][j]=dp[i][j-1]; 13 | if(coins[j-1]<=i) 14 | dp[i][j]+=dp[i-coins[j-1]][j]; 15 | } 16 | } 17 | return dp[sum][n]; 18 | } 19 | 20 | int main(){ 21 | int coins[]={2,5,3,6}; 22 | int n=sizeof(coins)/sizeof(coins[0]); 23 | int sum=10; 24 | cout<<"Result is :"< 2 | using namespace std; 3 | class Student 4 | { 5 | public: 6 | int RollNo; 7 | string name; 8 | static int AdmissionNo; 9 | Student(string n) 10 | { 11 | AdmissionNo++; 12 | RollNo = AdmissionNo; 13 | name = n; 14 | } 15 | static int display() 16 | { 17 | return AdmissionNo; 18 | } 19 | void output(){ 20 | cout << "Name is " << name << " and RollNo is " << RollNo << endl; 21 | } 22 | }; 23 | int Student::AdmissionNo = 0; 24 | int main() 25 | { 26 | Student s1("Swaraj"), s2("Mhatre"); 27 | s1.output(); 28 | s2.output(); 29 | return 0; 30 | } -------------------------------------------------------------------------------- /Leetcode/35SearchInseartPos.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int binarySearch(vector& nums, int low, int high, int target){ 4 | if(low<=high){ 5 | int mid = (high+low)/2; 6 | if(nums[mid]==target){ 7 | return mid; 8 | } 9 | if(nums[mid]>target){ 10 | return binarySearch(nums, low, mid-1, target); 11 | } 12 | else{ 13 | return binarySearch(nums, mid+1, high, target); 14 | } 15 | } 16 | return low; 17 | } 18 | int searchInsert(vector& nums, int target) { 19 | return binarySearch(nums, 0, nums.size()-1, target); 20 | } 21 | }; -------------------------------------------------------------------------------- /Recursion/countSubseq.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int printSubseq(int arr[] , int sum , int val ,vector &ans , int index , int size){ 5 | 6 | if(index >= size){ 7 | if(val == sum){ 8 | return 1; 9 | } 10 | return 0; 11 | } 12 | 13 | //including 14 | ans.push_back(arr[index]); 15 | int l = printSubseq(arr, sum+arr[index], val ,ans, index+1, size); 16 | 17 | //not including 18 | ans.pop_back(); 19 | int r = printSubseq(arr, sum, val , ans, index+1, size); 20 | return l + r; 21 | } 22 | 23 | int main(){ 24 | int arr[] = {1,2,1}; 25 | vector ans; 26 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int count =1, i, j; 6 | for ( i = 0; i < 4; i++) 7 | { 8 | for ( j = 0; j < 4; j++) 9 | { 10 | 11 | if (i+j < 4-1) 12 | { 13 | cout << " "; 14 | } 15 | else{ 16 | cout << "*"; 17 | } 18 | } 19 | for (int k = 0; k < i; k++) 20 | { 21 | { 22 | /* code */ 23 | cout << "*"; 24 | } 25 | 26 | } 27 | 28 | 29 | cout << endl; 30 | } 31 | 32 | return 0; 33 | } -------------------------------------------------------------------------------- /Operator Overloading/addition_of_img_nos.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Complex 4 | { 5 | public: 6 | int real, img; 7 | Complex(int real = 0, int img = 0) 8 | { 9 | this->real = real; 10 | this->img = img; 11 | } 12 | void display() 13 | { 14 | cout << "The no. is" << real << " + " << img << "i" << endl; 15 | } 16 | Complex operator+(Complex x) 17 | { 18 | Complex temp; 19 | temp.real = real + x.real; 20 | temp.img = img + x.img; 21 | return temp; 22 | } 23 | }; 24 | int main() 25 | { 26 | Complex C1(10,20), C2(10,40), C3; 27 | C3 = C1 + C2; 28 | C3.display(); 29 | return 0; 30 | } -------------------------------------------------------------------------------- /code32: -------------------------------------------------------------------------------- 1 | public class Alphabet { 2 | 3 | public static void main(String[] args) { 4 | 5 | char c = 'A'; 6 | 7 | String output = (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') 8 | ? c + " is an alphabet." 9 | : c + " is not an alphabet."; 10 | 11 | System.out.println(output); 12 | } 13 | } 14 | class Main { 15 | public static void main(String[] args) { 16 | 17 | // declare a variable 18 | char c = 'a'; 19 | 20 | // checks if c is an alphabet 21 | if (Character.isAlphabetic(c)) { 22 | System.out.println(c + " is an alphabet."); 23 | } 24 | else { 25 | System.out.println(c + " is not an alphabet."); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /fibonacci series/fibonacci_series.cpp: -------------------------------------------------------------------------------- 1 | // Fibonacci Series in c++ 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | int n, first = 0, second = 1, sum = 0; 7 | cout << "enter the number of terms:"; 8 | cin >> n; 9 | cout << "fibonacci series:"; 10 | for (int i = 0; i < n; i++) 11 | { 12 | if (i <= 1) 13 | { 14 | sum = i; // to print 0 and 1 15 | } 16 | else 17 | { 18 | sum = first + second; // to calculate the remaining terms. 19 | first = second; // value of first and second changes as new term is printed. 20 | second = sum; 21 | } 22 | cout << sum << " "; 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Krish/calculatePower.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define ll long long int 4 | 5 | ll binpow(ll base, ll n) 6 | { 7 | ll res = 1; 8 | while (n) 9 | { 10 | if (n % 2) 11 | { 12 | n--; 13 | res = res * base; 14 | } 15 | else 16 | { 17 | n = n / 2; 18 | base = base * base; 19 | } 20 | } 21 | return res; 22 | } 23 | void solve() 24 | { 25 | ll n, x; 26 | cin >> n >> x; 27 | cout << binpow(x, n) << endl; 28 | } 29 | int main() 30 | { 31 | ios_base::sync_with_stdio(false); 32 | cin.tie(NULL); 33 | int t; 34 | cin >> t; 35 | while (t--) 36 | { 37 | solve(); 38 | } 39 | return 0; 40 | } -------------------------------------------------------------------------------- /binarysearch.CPP: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | using namespace std; 4 | 5 | 6 | int binarySearch(int arr[], int l, int r, int x) 7 | { 8 | if (r >= l) { 9 | int mid = l + (r - l) / 2; 10 | 11 | if (arr[mid] == x) 12 | return mid; 13 | 14 | 15 | if (arr[mid] > x) 16 | return binarySearch(arr, l, mid - 1, x); 17 | 18 | 19 | return binarySearch(arr, mid + 1, r, x); 20 | } 21 | 22 | 23 | return -1; 24 | } 25 | 26 | int main(void) 27 | { 28 | int arr[] = { 2, 3, 4, 10, 40 }; 29 | int x = 10; 30 | int n = sizeof(arr) / sizeof(arr[0]); 31 | int result = binarySearch(arr, 0, n - 1, x); 32 | (result == -1) 33 | ? cout << "Element is not present in array" 34 | : cout << "Element is present at index " << result; 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /athul/functionoverload.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | 6 | int add(int, int); 7 | float add(float, float); 8 | 9 | int main() 10 | { 11 | int a, b, x; 12 | float c, d, y; 13 | 14 | cout << "Enter two integers\n"; 15 | cin >> a >> b; 16 | 17 | x = add(a, b); 18 | 19 | cout << "Sum of integers: " << x << endl; 20 | 21 | cout << "Enter two floating point numbers\n"; 22 | cin >> c >> d; 23 | 24 | y = add(c, d); 25 | 26 | cout << "Sum of floats: " << y << endl; 27 | 28 | return 0; 29 | } 30 | 31 | int add(int x, int y) 32 | { 33 | int sum; 34 | 35 | sum = x + y; 36 | 37 | return sum; 38 | } 39 | 40 | float add(float x, float y) 41 | { 42 | float sum; 43 | 44 | sum = x + y; 45 | 46 | return sum; 47 | } 48 | -------------------------------------------------------------------------------- /Heartpattern.cpp: -------------------------------------------------------------------------------- 1 | //WAP to print heart like pattern 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | {int i,j,s; 7 | cout<<"Enter any number: "; 8 | cin>>s; 9 | 10 | for(i=s/2; i0;i--) 31 | { 32 | for(j=0;j 2 | using namespace std; 3 | #define N 4 4 | 5 | void transpose(int A[][N], int B[][N]) 6 | { 7 | int i, j; 8 | for (i = 0; i < N; i++) 9 | for (j = 0; j < N; j++) 10 | B[i][j] = A[j][i]; 11 | } 12 | 13 | 14 | int main() 15 | { 16 | int A[N][N] = { { 1, 1, 1, 1 }, 17 | { 2, 2, 2, 2 }, 18 | { 3, 3, 3, 3 }, 19 | { 4, 4, 4, 4 } }; 20 | 21 | 22 | int B[N][N], i, j; 23 | 24 | 25 | transpose(A, B); 26 | 27 | cout << "Result matrix is \n"; 28 | for (i = 0; i < N; i++) { 29 | for (j = 0; j < N; j++) 30 | cout << " " << B[i][j]; 31 | 32 | cout << "\n"; 33 | } 34 | return 0; 35 | } 36 | 37 | -------------------------------------------------------------------------------- /kadane's algorithm.cpp: -------------------------------------------------------------------------------- 1 | // kadane's algorithm is used to print largest contiguous array sum 2 | #include 3 | using namespace std; 4 | 5 | int maxSubArraySum(int a[], int size) 6 | { 7 | int max_so_far = INT_MIN, max_ending_here = 0; 8 | 9 | for (int i = 0; i < size; i++) { 10 | max_ending_here = max_ending_here + a[i]; 11 | if (max_so_far < max_ending_here) 12 | max_so_far = max_ending_here; 13 | 14 | if (max_ending_here < 0) 15 | max_ending_here = 0; 16 | } 17 | return max_so_far; 18 | } 19 | 20 | int main(){ 21 | int n; 22 | cout<<"Enter the size of array: "; 23 | cin>>n; 24 | int a[n]; 25 | for(int i=0; i>a[i]; 27 | } 28 | 29 | int max_sum = maxSubArraySum(a, n); 30 | cout < 2 | using namespace std; 3 | 4 | void swap1() 5 | { 6 | int a, b; 7 | cin >> a >> b; 8 | // let's swap without using third variable 9 | a = a + b; 10 | b = a - b; 11 | a = a - b; 12 | cout << a << " " << b << endl; 13 | } 14 | void swap2() 15 | { 16 | int c, d; 17 | cin >> c >> d; 18 | c = c ^ d; 19 | d = c ^ d; 20 | c = c ^ d; 21 | cout << c << " " << d << endl; 22 | } 23 | int main() 24 | { 25 | // First swap may not work for large numbers 26 | // as addition might face integer overflow 27 | swap1(); 28 | 29 | // Second swap works for all numbers 30 | // as we are doing Bitwise XOR which will not 31 | // face integer overflow 32 | swap2(); 33 | 34 | return 0; 35 | } -------------------------------------------------------------------------------- /Vijay/findkCLosetElements.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Solution 4 | { 5 | public: 6 | vector findClosestElements(vector &arr, int k, int x) 7 | { 8 | 9 | priority_queue> maxheap; 10 | pair p; 11 | for (int i = 0; i < arr.size(); i++) 12 | { 13 | 14 | maxheap.push({abs(arr[i] - x), arr[i]}); 15 | if (maxheap.size() > k) 16 | { 17 | maxheap.pop(); 18 | } 19 | } 20 | 21 | vector ans; 22 | while (maxheap.size() > 0) 23 | { 24 | ans.push_back(maxheap.top().second); 25 | maxheap.pop(); 26 | } 27 | sort(ans.begin(), ans.end()); 28 | return ans; 29 | } 30 | }; -------------------------------------------------------------------------------- /Matrix-Transpose/Matrix_Transpose.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | const int n = 4; 7 | void transpose(int mat[n][n]) 8 | { 9 | int temp[n][n]; 10 | 11 | for(int i = 0; i < n; i++) 12 | for(int j = 0; j < n; j++) 13 | temp[i][j] = mat[j][i]; 14 | 15 | for(int i = 0; i < n; i++) 16 | for(int j = 0; j < n; j++) 17 | mat[i][j] = temp[i][j]; 18 | 19 | } 20 | 21 | int main() 22 | { 23 | int arr[n][n] = {{1, 2, 3, 4}, 24 | {5, 6, 7, 8}, 25 | {9, 10, 11, 12}, 26 | {13, 14, 15, 16}}; 27 | 28 | transpose(arr); 29 | 30 | for(int i = 0; i < n; i++) 31 | { 32 | for(int j = 0; j < n; j++) 33 | { 34 | cout << arr[i][j] << " "; 35 | } 36 | 37 | cout << endl; 38 | } 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /code2: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int n; 6 | double *data; 7 | printf("Enter the total number of elements: "); 8 | scanf("%d", &n); 9 | 10 | // Allocating memory for n elements 11 | data = (double *)calloc(n, sizeof(double)); 12 | if (data == NULL) { 13 | printf("Error!!! memory not allocated."); 14 | exit(0); 15 | } 16 | 17 | // Storing numbers entered by the user. 18 | for (int i = 0; i < n; ++i) { 19 | printf("Enter number%d: ", i + 1); 20 | scanf("%lf", data + i); 21 | } 22 | 23 | // Finding the largest number 24 | for (int i = 1; i < n; ++i) { 25 | if (*data < *(data + i)) { 26 | *data = *(data + i); 27 |   } 28 | } 29 | printf("Largest number = %.2lf", *data); 30 | 31 | free(data); 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /pattern/pattern.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int i,j,n; 6 | cout<<"Enter any number."; 7 | cin>>n; 8 | for(i=1;i<=n/2;i++) 9 | { 10 | for(j=1;j<=i;j++) 11 | { 12 | cout<<"* "; 13 | } 14 | for(j=i*2-1;j<=n-2;j++) 15 | cout<<" "; 16 | for(j=1;j<=i;j++) 17 | { 18 | cout<<"* "; 19 | } 20 | cout< 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | const int n = 4; 7 | void transpose(int mat[n][n]) 8 | { 9 | int temp[n][n]; 10 | 11 | for(int i = 0; i < n; i++) 12 | for(int j = 0; j < n; j++) 13 | temp[i][j] = mat[j][i]; 14 | 15 | for(int i = 0; i < n; i++) 16 | for(int j = 0; j < n; j++) 17 | mat[i][j] = temp[i][j]; 18 | 19 | } 20 | 21 | int main() 22 | { 23 | int arr[n][n] = {{1, 2, 3, 4}, 24 | {5, 6, 7, 8}, 25 | {9, 10, 11, 12}, 26 | {13, 14, 15, 16}}; 27 | 28 | transpose(arr); 29 | 30 | for(int i = 0; i < n; i++) 31 | { 32 | for(int j = 0; j < n; j++) 33 | { 34 | cout << arr[i][j] << " "; 35 | } 36 | 37 | cout << endl; 38 | } 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /star pattern/star_pattern.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int i,j,n; 6 | cout<<"Enter any number."; 7 | cin>>n; 8 | for(i=1;i<=n/2;i++) 9 | { 10 | for(j=1;j<=i;j++) 11 | { 12 | cout<<"* "; 13 | } 14 | for(j=i*2-1;j<=n-2;j++) 15 | cout<<" "; 16 | for(j=1;j<=i;j++) 17 | { 18 | cout<<"* "; 19 | } 20 | cout< 2 | using namespace std; 3 | 4 | int binarySearch(int arr[], int l, int r, int x) 5 | { 6 | if (r >= l) { 7 | int mid = l + (r - l) / 2; 8 | if (arr[mid] == x) 9 | return mid; 10 | 11 | if (arr[mid] > x) 12 | return binarySearch(arr, l, mid - 1, x); 13 | 14 | return binarySearch(arr, mid + 1, r, x); 15 | } 16 | 17 | return -1; 18 | } 19 | 20 | int main(void) 21 | { 22 | int arr[] = { 4, 5, 2, 10, 11 }; 23 | int x = 10; 24 | int n = sizeof(arr) / sizeof(arr[0]); 25 | int result = binarySearch(arr, 0, n - 1, x); 26 | (result == -1) 27 | ? cout << "Element not present" 28 | : cout << "Element present at index " << result; 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /c++: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | char c; 6 | bool isLowercaseVowel, isUppercaseVowel; 7 | 8 | cout << "Enter an alphabet: "; 9 | cin >> c; 10 | 11 | // evaluates to 1 (true) if c is a lowercase vowel 12 | isLowercaseVowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'); 13 | 14 | // evaluates to 1 (true) if c is an uppercase vowel 15 | isUppercaseVowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U'); 16 | 17 | // show error message if c is not an alphabet 18 | if (!isalpha(c)) 19 | printf("Error! Non-alphabetic character."); 20 | else if (isLowercaseVowel || isUppercaseVowel) 21 | cout << c << " is a vowel."; 22 | else 23 | cout << c << " is a consonant."; 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Cpp_Recursion: -------------------------------------------------------------------------------- 1 | C++ Recursion 2 | 3 | Recursion is the technique of making a function call itself. This technique provides a way to break complicated problems down into simple problems which are easier to solve. 4 | Recursion may be a bit difficult to understand. The best way to figure out how it works is to experiment with it. 5 | Recursion Example 6 | Adding two numbers together is easy to do, but adding a range of numbers is more complicated. In the following example, recursion is used to add a range of numbers together by breaking it down into the simple task of adding two numbers: 7 | 8 | Example: 9 | 10 | int sum(int k) { 11 | if (k > 0) { 12 | return k + sum(k - 1); 13 | } else { 14 | return 0; 15 | } 16 | } 17 | 18 | int main() { 19 | int result = sum(10); 20 | cout << result; 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Operator Overloading/friend_function_op_overloading.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Complex 4 | { 5 | public: 6 | int real, img; 7 | Complex(int real = 0, int img = 0) 8 | { 9 | this->real = real; 10 | this->img = img; 11 | } 12 | void display() 13 | { 14 | cout << "The no. is " << real << " + " << img << "i" << endl; 15 | } 16 | friend Complex operator+(Complex c1, Complex c2); 17 | }; 18 | Complex operator+(Complex c1, Complex c2) 19 | { 20 | Complex temp; 21 | temp.real = c1.real + c2.real; 22 | temp.img = c2.img + c1.img; 23 | return temp; 24 | } 25 | int main() 26 | { 27 | Complex C1(10,20), C2(10,40), C3; 28 | C3 = C1 + C2; 29 | C3.display(); 30 | return 0; 31 | } -------------------------------------------------------------------------------- /constructor & destructor/constroctor_and_destructor.cpp: -------------------------------------------------------------------------------- 1 | // How Constructor and Destructor are called when the object is Created and Destroyed. 2 | #include 3 | using namespace std; 4 | class class_name 5 | { 6 | private: 7 | int a, b; 8 | 9 | public: 10 | class_name(int aa, int bb) 11 | { 12 | cout << "Constructor is called" << endl; 13 | a = aa; 14 | b = bb; 15 | cout << "Value of a : " << a << endl; 16 | cout << "Value of b : " << b << endl; 17 | cout << endl; 18 | } 19 | ~class_name() 20 | { 21 | cout << "Destructor is called " << endl; 22 | cout << "Value of a : " << a << endl; 23 | cout << "Value of b : " << b << endl; 24 | } 25 | }; 26 | int main() 27 | { 28 | class_name obj(5, 6); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /merge sort/merge_sort.cpp: -------------------------------------------------------------------------------- 1 | // merge sort 2 | #include 3 | 4 | using namespace std; 5 | 6 | void merge(int a[],int b[],int x,int y,int c[]) 7 | { 8 | int z=0,i=0,j=0,k=0; 9 | while(i>x>>y; 26 | cout<<"ENter array 1:"; 27 | for(int i=0;i>a[i]; 29 | cout<<"Enter Array 2:"; 30 | for(int i=0;i>b[i]; 32 | merge(a,b,x,y,c); 33 | for(int i=0;i 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 | cout << "Error! operator is not correct"; 35 | break; 36 | } 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /code243: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class Main { 4 | public static void main(String[] args) { 5 | 6 | // create an object of Scanner class 7 | Scanner input = new Scanner(System.in); 8 | 9 | // take input from users 10 | System.out.print("Enter the principal: "); 11 | double principal = input.nextDouble(); 12 | 13 | System.out.print("Enter the rate: "); 14 | double rate = input.nextDouble(); 15 | 16 | System.out.print("Enter the time: "); 17 | double time = input.nextDouble(); 18 | 19 | double interest = (principal * time * rate) / 100; 20 | 21 | System.out.println("Principal: " + principal); 22 | System.out.println("Interest Rate: " + rate); 23 | System.out.println("Time Duration: " + time); 24 | System.out.println("Simple Interest: " + interest); 25 | 26 | input.close(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Recursion/printSubseqOfGivenSum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | bool printSubseq(int arr[] , int sum , int val ,vector &ans , int index , int size){ 5 | 6 | if(index >= size){ 7 | if(val == sum){ 8 | for(auto it : ans) 9 | cout< ans; 30 | printSubseq(arr,0,2,ans,0,3); 31 | return 0; 32 | } -------------------------------------------------------------------------------- /function.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | class Complex{ 8 | int a, b; 9 | friend Complex sumComplex(Complex o1, Complex o2); 10 | public: 11 | void setNumber(int n1, int n2){ 12 | a = n1; 13 | b = n2; 14 | } 15 | 16 | 17 | void printNumber(){ 18 | cout<<"Your number is "< 2 | using namespace std; 3 | void find_greatest(int a, int b, int c, int d) 4 | { 5 | int x = max(a, max(b, max(c, d))); 6 | if (x == a) 7 | cout << "a is greatest"; 8 | if (x == b) 9 | cout << "b is greatest"; 10 | if (x == c) 11 | cout << "c is greatest"; 12 | if (x == d) 13 | cout << "d is greatest"; 14 | } 15 | 16 | int main() 17 | { 18 | int a = 10, b = 50, c = 20, d = 25; 19 | cout << "a=" << a << " b=" << b << " c=" << c << " d=" << d; 20 | cout << "\n"; 21 | find_greatest(a, b, c, d); 22 | a = 35, b = 50, c = 99, d = 2; 23 | cout << "\n"; 24 | cout << "a=" << a << " b=" << b << " c=" << c << " d=" << d; 25 | cout << "\n"; 26 | find_greatest(a, b, c, d); 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Matrix/Multiplication_of_Natrix.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int a1[2][3]={1,2,3, 4 | 4,5,6}; 5 | int a2[3][2]={7,8, 6 | 9,10, 7 | 11,12}; 8 | int a3[2][2],sum=0; 9 | for (int i = 0; i < 3; i++) 10 | { 11 | for (int j = 0; j < 3; j++) 12 | { 13 | for (int k = 0; k < 3; k++) 14 | { 15 | sum=sum+(a1[i][k]*a2[k][j]); 16 | a3[i][j]=sum; 17 | 18 | } 19 | 20 | } 21 | 22 | } 23 | 24 | 25 | for (int i = 0; i < 2; i++) 26 | { 27 | for (int j = 0; j < 2; j++) 28 | { 29 | 30 | printf("%d ",a3[i][j]); 31 | } 32 | printf("\n"); 33 | 34 | } 35 | 36 | 37 | 38 | 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "tasks": [ 3 | { 4 | "type": "cppbuild", 5 | "label": "C/C++: g++.exe build active file", 6 | "command": "C:\\Users\\shiva\\MinGw\\MinGW\\bin\\g++.exe", 7 | "args": [ 8 | "-fdiagnostics-color=always", 9 | "-g", 10 | "${file}", 11 | "-o", 12 | "${fileDirname}\\${fileBasenameNoExtension}.exe" 13 | ], 14 | "options": { 15 | "cwd": "${fileDirname}" 16 | }, 17 | "problemMatcher": [ 18 | "$gcc" 19 | ], 20 | "group": { 21 | "kind": "build", 22 | "isDefault": true 23 | }, 24 | "detail": "Task generated by Debugger." 25 | } 26 | ], 27 | "version": "2.0.0" 28 | } -------------------------------------------------------------------------------- /Arrays/same_tree.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a binary tree node. 3 | * struct TreeNode { 4 | * int val; 5 | * TreeNode *left; 6 | * TreeNode *right; 7 | * TreeNode() : val(0), left(nullptr), right(nullptr) {} 8 | * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} 9 | * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} 10 | * }; 11 | */ 12 | class Solution { 13 | public: 14 | 15 | bool isSameTree(TreeNode* p, TreeNode* q) { 16 | if(p==NULL && q==NULL) 17 | return true; 18 | if(p==NULL || q==NULL) 19 | return false; 20 | 21 | 22 | if(p->val!=q->val) 23 | return false; 24 | 25 | 26 | return (isSameTree(p->left,q->left)&&isSameTree(p->right,q->right)); 27 | 28 | 29 | } 30 | }; 31 | -------------------------------------------------------------------------------- /functions/friend-func.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | class Complex{ 8 | int a, b; 9 | friend Complex sumComplex(Complex o1, Complex o2); 10 | public: 11 | void setNumber(int n1, int n2){ 12 | a = n1; 13 | b = n2; 14 | } 15 | 16 | 17 | void printNumber(){ 18 | cout<<"Your number is "< 2 | using namespace std; 3 | //int main() 4 | { 5 | class person 6 | { 7 | int Pid; 8 | string Pname; 9 | int Page; 10 | string Pcity; 11 | public: 12 | void setperson (int Pid, string Pname, int Page, string Pcity) 13 | { 14 | this -> Pid=Pid; 15 | this -> Pname=Pname; 16 | this -> Page=Page; 17 | this -> Pcity=Pcity; 18 | } 19 | void show() 20 | { 21 | cout<<"Person Info"<<< 2 | 3 | void swap(int* xp, int* yp) 4 | { 5 | int temp = *xp; 6 | *xp = *yp; 7 | *yp = temp; 8 | } 9 | 10 | void selectionSort(int arr[], int n) 11 | { 12 | int i, j, min_idx; 13 | for (i = 0; i < n - 1; i++) { 14 | min_idx = i; 15 | for (j = i + 1; j < n; j++) 16 | if (arr[j] < arr[min_idx]) 17 | min_idx = j; 18 | swap(&arr[min_idx], &arr[i]); 19 | } 20 | } 21 | 22 | void printArray(int arr[], int size) 23 | { 24 | int i; 25 | for (i = 0; i < size; i++) 26 | printf("%d ", arr[i]); 27 | printf("\n"); 28 | } 29 | 30 | 31 | int main() 32 | { 33 | int arr[] = { 0, 23, 14, 12, 9 }; 34 | int n = sizeof(arr) / sizeof(arr[0]); 35 | printArray(arr, n); 36 | selectionSort(arr, n); 37 | printArray(arr, n); 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /Arushi_Agarwal/Nth node from end of linked list: -------------------------------------------------------------------------------- 1 | /* struct Node { 2 | int data; 3 | struct Node *next; 4 | Node(int x) { 5 | data = x; 6 | next = NULL; 7 | } 8 | }; 9 | */ 10 | 11 | //Function to find the data of nth node from the end of a linked list. 12 | int getNthFromLast(Node *head, int n) 13 | { 14 | Node* temp=head; 15 | Node* fast=head; 16 | Node* slow=head; 17 | int c=1; 18 | if(head==NULL) 19 | return -1; 20 | while(temp->next!=NULL) 21 | { 22 | temp=temp->next; 23 | c++; 24 | } 25 | if(cdata; 29 | for(int i=0;inext; 31 | while(fast->next!=NULL) 32 | { 33 | slow=slow->next; 34 | fast=fast->next; 35 | } 36 | return slow->next->data; 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /Exception Handling/Student_excercise.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class StackOverflow: exception{}; 4 | class StackUnderflow: exception{}; 5 | class Stack{ 6 | int *stk; 7 | int top = -1; 8 | int size; 9 | public: 10 | Stack(int sz){ 11 | size = sz; 12 | stk = new int[sz]; 13 | } 14 | void push(int x){ 15 | if (top == size-1){ 16 | throw StackOverflow(); 17 | } 18 | else{ 19 | top++; 20 | stk[top] = x; 21 | } 22 | } 23 | int pop(){ 24 | if(top == -1){ 25 | throw StackUnderflow(); 26 | } 27 | else{ 28 | return stk[top--]; 29 | } 30 | } 31 | 32 | }; 33 | int main(){ 34 | Stack s(5); 35 | s.push(1); 36 | s.push(5); 37 | s.push(65); 38 | s.push(45); 39 | 40 | 41 | s.push(55); 42 | s.push(5); 43 | cout << s.pop(); 44 | return 0; 45 | } -------------------------------------------------------------------------------- /Arrays/next_permutation.cpp: -------------------------------------------------------------------------------- 1 | // { Driver Code Starts 2 | // Initial Template for C++ 3 | 4 | #include 5 | using namespace std; 6 | 7 | // } Driver Code Ends 8 | // User function Template for C++ 9 | 10 | class Solution{ 11 | public: 12 | vector nextPermutation(int N, vector arr){ 13 | // code here 14 | next_permutation(arr.begin(),arr.end()); 15 | return arr; 16 | } 17 | }; 18 | 19 | // { Driver Code Starts. 20 | 21 | int main(){ 22 | int t; 23 | cin>>t; 24 | while(t--){ 25 | int N; 26 | cin>>N; 27 | vector arr(N); 28 | for(int i = 0;i < N;i++) 29 | cin>>arr[i]; 30 | 31 | Solution ob; 32 | vector ans = ob.nextPermutation(N, arr); 33 | for(int u: ans) 34 | cout< al = new ArrayList(); 16 | 17 | // Populating the ArrayList by custom elements 18 | al.add("Anshul Aggarwal"); 19 | al.add("Mayank Solanki"); 20 | al.add("Abhishek Kelenia"); 21 | al.add("Vivek Gupta"); 22 | 23 | // Converting above List to array using toArray() 24 | // method and storing it in an string array 25 | String k[] = al.toArray(new String[al.size()]); 26 | 27 | // Iterating over above string array 28 | for (String str : k) { 29 | 30 | // Printing the elements in above array 31 | System.out.println(str); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Google.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | void main() 6 | {clrscr(); 7 | int g=0,a; 8 | initgraph(&g,&d,""); 9 | setbkcolor(14); 10 | setcolor(6); 11 | settextstyle(2,0,4); 12 | outtextxy(180,130,"G"); 13 | setcolor(5); 14 | settextstyle(2,0,4); 15 | outtextxy(120,120,"O"); 16 | setcolor(6); 17 | settextstyle(2,0,4); 18 | outtextxy(300,120,"O"); 19 | setcolor(5); 20 | settextstyle(2,0,4); 21 | outtextxy(250,130,"G"); 22 | setcolor(2); 23 | settextstyle(2,0,4); 24 | outtextxy(360,160,"L"); 25 | setcolor(3); 26 | settextstyle(2,0,4); 27 | outtextxy(310,130,"E"); 28 | setcolor(9); 29 | settextstyle(2,0,4); 30 | setcolor(8); 31 | settextstyle(2,0,4); 32 | outtextxy(110,250,"surf"); 33 | settextstyle(2,0,4); 34 | outtextxy(350,320,"Go AHEAD"); 35 | setcolor(6); 36 | rectangle(130,210,450,210); 37 | rectangle(90,310,170,340); 38 | rectangle(360,320,510,320); 39 | getch(); 40 | } 41 | -------------------------------------------------------------------------------- /Binary Seach/Binary_search.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int i, arr[10], num, first, last, middle; 6 | cout<<"Enter 10 Elements (in ascending order): "; 7 | for(i=0; i<10; i++) 8 | cin>>arr[i]; 9 | cout<<"\nEnter Element to be Search: "; 10 | cin>>num; 11 | first = 0; 12 | last = 9; 13 | middle = first+(last-first)/2; 14 | while(first <= last) 15 | { 16 | if(arr[middle]last) 28 | cout<<"\nThe number, "< 2 | using namespace std; 3 | struct Array 4 | { 5 | /* data */ 6 | int A[10]; 7 | int size; 8 | int length; 9 | 10 | }; 11 | void swap(int *x, int*y){ 12 | int temp =*x; 13 | *x =*y; 14 | *y = temp; 15 | } 16 | int LinearSearch(struct Array *arr, int key){ 17 | for(int i =0; i < arr->length; i++){ 18 | 19 | if(key == arr->A[i] ){ 20 | swap(&arr->A[i], &arr->A[i-1]); 21 | return i; 22 | } 23 | } 24 | 25 | return -1; 26 | } 27 | int main(){ 28 | struct Array arr1 = {{1,2,3,4,5,6,7,8},10,8}; 29 | cout << LinearSearch(&arr1, 5); 30 | cout << LinearSearch(&arr1, 5); 31 | cout << LinearSearch(&arr1, 5); 32 | cout << LinearSearch(&arr1, 5); 33 | cout << LinearSearch(&arr1, 5); 34 | cout << LinearSearch(&arr1, 5); 35 | cout << LinearSearch(&arr1, 5); 36 | return 0; 37 | } -------------------------------------------------------------------------------- /Butterfly.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int a,j,n; 5 | printf("Enter number of rows/size: "); 6 | scanf("%d",&n); 7 | for (a=1; a<=n; a++) 8 | { 9 | for (j=1; j<=(2*n); j++) 10 | { 11 | 12 | if (a(n-a+1)) 30 | printf(" "); 31 | else 32 | printf("*"); 33 | 34 | 35 | if ((a+n)>j) 36 | printf(" "); 37 | else 38 | printf("*"); 39 | } 40 | printf("\n"); 41 | } 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /DSA in CPP/Linked List/display.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | struct Node{ 4 | int data; 5 | struct Node *next; 6 | }*first = NULL; 7 | void Create(int A[], int n){ 8 | int i; 9 | struct Node *t, *last; 10 | first = new Node(); 11 | first->data = A[0]; 12 | first->next = NULL; 13 | last = first; 14 | for(i =1; idata = A[i]; 17 | t->next = NULL; 18 | last->next = t; 19 | last =t; 20 | } 21 | } 22 | void Display(struct Node *p) 23 | { 24 | while(p!=NULL) 25 | { 26 | printf("%d ",p->data); 27 | p=p->next; 28 | } 29 | } 30 | void RDisplay(struct Node *p) 31 | { 32 | if(p!=NULL) 33 | { 34 | RDisplay(p->next); 35 | printf("%d ",p->data); 36 | 37 | } 38 | } 39 | int main(){ 40 | int A[] = {0,1,2,3,4,5,6,7,8,9}; 41 | Create(A, 10); 42 | RDisplay(first); 43 | return 0; 44 | } -------------------------------------------------------------------------------- /Shivam_Mishra/Find_Subsequence.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #include 5 | using namespace std; 6 | void printS(int ind,vector &ds,int sum,int givenSum,int arr[],int n) 7 | { 8 | // Base Condition 9 | if(ind==n){ 10 | if(sum==givenSum){ 11 | for(auto it : ds) cout<< it <<" "; 12 | cout << endl; 13 | } 14 | return; 15 | } 16 | 17 | ds.push_back(arr[ind]); // push into vector 18 | 19 | sum+=arr[ind]; // Add to sum 20 | 21 | printS(ind+1,ds,sum,givenSum,arr,n); // call again 22 | // When return from previous recursion below execute 23 | sum-=arr[ind]; // Subtract prevoius added value 24 | ds.pop_back(); // and also pop back from vector 25 | 26 | printS(ind+1,ds,sum,givenSum,arr,n); // Again call recursion 27 | } 28 | 29 | int main() 30 | { 31 | int arr[] ={1,2,1}; 32 | int n=3; 33 | int givenSum = 2; 34 | vector ds; 35 | printS(0,ds,0,givenSum,arr,n); 36 | return 0; 37 | } -------------------------------------------------------------------------------- /palindrome.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int oneDigit(int num) 5 | { 6 | return (num >= 0 && num < 10); 7 | } 8 | 9 | bool isPalUtil(int num, int* dupNum) 10 | { 11 | if (oneDigit(num)) 12 | return (num == (*dupNum) % 10); 13 | if (!isPalUtil(num / 10, dupNum)) 14 | return false; 15 | *dupNum /= 10; 16 | return (num % 10 == (*dupNum) % 10); 17 | } 18 | 19 | int isPal(int num) 20 | { 21 | if (num < 0) 22 | num = -num; 23 | 24 | int* dupNum = new int(num); 25 | 26 | return isPalUtil(num, dupNum); 27 | } 28 | 29 | 30 | int main() 31 | { 32 | int n = 12321; 33 | isPal(n) ? cout <<"Yes\n": cout <<"No" << endl; 34 | 35 | n = 12; 36 | isPal(n) ? cout <<"Yes\n": cout <<"No" << endl; 37 | 38 | n = 88; 39 | isPal(n) ? cout <<"Yes\n": cout <<"No" << endl; 40 | 41 | n = 8999; 42 | isPal(n) ? cout <<"Yes\n": cout <<"No"; 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /add_distance.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | struct Distance { 5 | int feet; 6 | float inch; 7 | }d1 , d2, sum; 8 | 9 | int main() { 10 | cout << "Enter 1st distance," << endl; 11 | cout << "Enter feet: "; 12 | cin >> d1.feet; 13 | cout << "Enter inch: "; 14 | cin >> d1.inch; 15 | 16 | cout << "\nEnter information for 2nd distance" << endl; 17 | cout << "Enter feet: "; 18 | cin >> d2.feet; 19 | cout << "Enter inch: "; 20 | cin >> d2.inch; 21 | 22 | sum.feet = d1.feet+d2.feet; 23 | sum.inch = d1.inch+d2.inch; 24 | 25 | // changing to feet if inch is greater than 12 26 | if(sum.inch > 12) { 27 | // extra feet 28 | int extra = sum.inch / 12; 29 | 30 | sum.feet += extra; 31 | sum.inch -= (extra * 12); 32 | } 33 | 34 | cout << endl << "Sum of distances = " << sum.feet << " feet " << sum.inch << " inches"; 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /Siddharth/RodCuttingEfficient.cpp: -------------------------------------------------------------------------------- 1 | // 10 1 5 8 9 10 17 17 20 24 30 2 | //20 1 5 8 9 10 17 17 20 24 30 1 5 8 9 10 17 17 20 24 30 20 1 5 8 9 10 17 17 20 24 30 1 5 8 9 10 17 17 20 24 30 3 | #include 4 | using namespace std; 5 | #include 6 | #include 7 | #include 8 | int maximum(int a, int b) 9 | { 10 | 11 | if(a>b) 12 | return a; 13 | return b; 14 | } 15 | int cut_rod(vector p, int length) 16 | { 17 | int i; 18 | int q=INT_MIN; 19 | if(length==0) 20 | return 0; 21 | for(i=1;i<=length;i++) 22 | { 23 | q = maximum(q,p[i-1]+cut_rod(p,length-i)); 24 | } 25 | return q; 26 | } 27 | int main() 28 | { 29 | vector p; 30 | int i,n,price,max_profit; 31 | cin>>n; 32 | for(i=0;i>price; 35 | p.push_back(price); 36 | } 37 | max_profit = cut_rod(p,n); 38 | cout< 3 | using namespace std; 4 | 5 | // Function 6 | int getOddOccurrence(int arr[], int arr_size) 7 | { 8 | for (int i = 0; i < arr_size; i++) { 9 | 10 | int count = 0; 11 | 12 | for (int j = 0; j < arr_size; j++) 13 | { 14 | if (arr[i] == arr[j]) 15 | count++; 16 | } 17 | if (count % 2 != 0) 18 | return arr[i]; 19 | } 20 | return -1; 21 | } 22 | int main() 23 | { 24 | int arr[] = { 2, 3, 5, 4, 5, 2, 25 | 4, 3, 5, 2, 4, 4, 2 }; 26 | int n = sizeof(arr) / sizeof(arr[0]); 27 | 28 | // Function calling 29 | cout << getOddOccurrence(arr, n); 30 | 31 | return 0; 32 | } 33 | /* 34 | Output : 35 | 5 36 | 37 | Time Complexity: O(n^2) 38 | Auxiliary Space: O(1) 39 | 40 | */ 41 | -------------------------------------------------------------------------------- /DSA in CPP/Array Adt/Insert_and_Append.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | struct Array{ 4 | int A[10]; 5 | int size; 6 | int length; 7 | }; 8 | void Display(struct Array arr){ 9 | for(int i=0; ilength< arr->size){ 15 | arr->A[arr->length++] = x; 16 | } 17 | } 18 | void Insert(struct Array *arr,int index, int x){ 19 | if(index >= 0 && index <= arr->length){ 20 | for(int i = arr-> length; i> index;i--){ 21 | arr->A[i] = arr->A[i-1]; 22 | 23 | } 24 | arr->A[index] = x; 25 | arr->length++; 26 | } 27 | } 28 | int main(){ 29 | struct Array arr{{1,2,3,4,5,6,7,8},10,8}; 30 | Append(&arr, 9); 31 | Insert(&arr, 5,10); 32 | Display(arr); 33 | return 0; 34 | } -------------------------------------------------------------------------------- /Structure/structure.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | struct student 5 | { 6 | char name[50]; 7 | int roll; 8 | float marks; 9 | } s[10]; 10 | 11 | int main() 12 | { 13 | cout << "Enter information of students: " << endl; 14 | 15 | // storing information 16 | for(int i = 0; i < 10; ++i) 17 | { 18 | s[i].roll = i+1; 19 | cout << "For roll number" << s[i].roll << "," << endl; 20 | 21 | cout << "Enter name: "; 22 | cin >> s[i].name; 23 | 24 | cout << "Enter marks: "; 25 | cin >> s[i].marks; 26 | 27 | cout << endl; 28 | } 29 | 30 | cout << "Displaying Information: " << endl; 31 | 32 | // Displaying information 33 | for(int i = 0; i < 10; ++i) 34 | { 35 | cout << "\nRoll number: " << i+1 << endl; 36 | cout << "Name: " << s[i].name << endl; 37 | cout << "Marks: " << s[i].marks << endl; 38 | } 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /DSA in CPP/Recursion/fibonacci.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int fibo(int n) 4 | { 5 | int arr[50]; 6 | for (int i = 0; i < n; i++) 7 | { 8 | arr[i] = -1; 9 | } 10 | if (n <= 1) 11 | { 12 | arr[n] = n; 13 | return n; 14 | } 15 | else 16 | { 17 | if (arr[n-2] == -1) 18 | { 19 | arr[n - 2] = fibo(n - 2); 20 | } 21 | if (arr[n-1] == -1) 22 | { 23 | arr[n - 1] = fibo(n - 1); 24 | } 25 | return arr[n - 2] + arr[n - 1]; 26 | } 27 | } 28 | int fibofor(int n) 29 | { 30 | int s, t0 = 0, t1 = 1; 31 | if (n <= 1) 32 | return n; 33 | for (int i = 2; i <= n; i++) 34 | { 35 | s = t0 + t1; 36 | t0 = t1; 37 | t1 = s; 38 | } 39 | return s; 40 | } 41 | int main() 42 | { 43 | int a = 4; 44 | cout << fibo(45); 45 | return 0; 46 | } -------------------------------------------------------------------------------- /Operator Overloading/insertion_operatr.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Rational 4 | { 5 | public: 6 | int p, q; 7 | Rational(int p = 0, int q = 0) 8 | { 9 | this->p = p; 10 | this->q = q; 11 | } 12 | void display() 13 | { 14 | cout << "The no. is " << p << " + " << q << "i" << endl; 15 | } 16 | Rational operator+(Rational r){ 17 | Rational r3; 18 | r3.p = this->p * r.q + this->q * r.p; 19 | r3.q = r.q * this->q; 20 | return r3; 21 | } 22 | 23 | friend ostream & operator<<(ostream & out, Rational & c); 24 | }; 25 | ostream & operator<<(ostream &out, Rational &c) 26 | { 27 | out << c.p << "/" << c.q << " "; 28 | // return out; 29 | } 30 | int main() 31 | { 32 | Rational C1(1,2), C2(3,4), C3; 33 | C3 = C1 + C2; 34 | cout<< "The sum of " << C1 << " and " << C2 << " is " << C3; 35 | 36 | return 0; 37 | } -------------------------------------------------------------------------------- /Arrays/array.cpp: -------------------------------------------------------------------------------- 1 | // C++ program for the above approach 2 | 3 | #include 4 | using namespace std; 5 | 6 | // Function to find the last remaining 7 | // array element after repeatedly removing 8 | // the smallest from pairs having absolute 9 | // difference 2 or 0 10 | void findLastElement(int arr[], int N) 11 | { 12 | // Sort the given array in 13 | // ascending order 14 | sort(arr, arr + N); 15 | int i = 0; 16 | 17 | // Traverse the array 18 | for (i = 1; i < N; i++) { 19 | 20 | // If difference between 21 | // adjacent elements is 22 | // not equal to 0 or 2 23 | if (arr[i] - arr[i - 1] != 0 24 | && arr[i] - arr[i - 1] != 2) { 25 | 26 | cout << "-1" << endl; 27 | return; 28 | } 29 | } 30 | 31 | // If operations can be performed 32 | cout << arr[N - 1] << endl; 33 | } 34 | 35 | // Driver Code 36 | int main() 37 | { 38 | int arr[] = { 2, 4, 6, 8, 0, 8 }; 39 | int N = sizeof(arr) / sizeof(arr[0]); 40 | findLastElement(arr, N); 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /binary_search.cpp: -------------------------------------------------------------------------------- 1 | //binary search recursive 2 | #include 3 | using namespace std; 4 | 5 | int bs(int arr[], int low, int high, int key){ 6 | if(high>=low){ 7 | 8 | int mid=(low+high)/2; 9 | if(key==arr[mid]){ 10 | return mid; 11 | } 12 | else if(key>arr[mid]){ 13 | return bs(arr, mid+1, high, key); 14 | } 15 | else{ 16 | return bs(arr,low, mid-1, key); 17 | } 18 | } 19 | return -1; 20 | } 21 | 22 | int main(){ 23 | int n; 24 | cout<<"Enter the size of array: "; 25 | cin>>n; 26 | int arr[n]; 27 | cout<<"Enter the elements of array: "<>arr[i]; 30 | } 31 | cout<<"Enter the element you want to search: "; 32 | int key; 33 | cin>>key; 34 | int ans =bs(arr,0,n-1,key); 35 | if(ans==-1){ 36 | cout<<"Element not found"; 37 | } 38 | else{ 39 | cout<<"Element found at index: "< 2 | using namespace std; 3 | class Array{ 4 | int *A; 5 | int size; 6 | int length; 7 | public: 8 | Array(int size){ 9 | this->size = size; 10 | A = new int [size]; 11 | } 12 | 13 | void Create(){ 14 | cout << "Ente rthe lenght of the Array: "<< flush; 15 | cin >> length; 16 | cout << "Enter the elements in the Array: "<< endl; 17 | for(int i =0; i< length ;i++){ 18 | cout << "Enter the element at index "<< i<< " "<< flush; 19 | cin>> A[i]; 20 | } 21 | } 22 | void Display(){ 23 | for(int i = 0; i< length ; i++){ 24 | cout << "Element at index "<< i << " is "<< A[i] << endl; 25 | } 26 | } 27 | ~Array(){ 28 | delete []A; 29 | cout << "Array Destroyed!"<< endl; 30 | } 31 | }; 32 | int main(){ 33 | Array Arr(10); 34 | Arr.Create(); 35 | Arr.Display(); 36 | return 0; 37 | } -------------------------------------------------------------------------------- /some basic data structures in cpp/binary_search.cpp: -------------------------------------------------------------------------------- 1 | //binary search recursive 2 | #include 3 | using namespace std; 4 | 5 | int bs(int arr[], int low, int high, int key){ 6 | if(high>=low){ 7 | 8 | int mid=(low+high)/2; 9 | if(key==arr[mid]){ 10 | return mid; 11 | } 12 | else if(key>arr[mid]){ 13 | return bs(arr, mid+1, high, key); 14 | } 15 | else{ 16 | return bs(arr,low, mid-1, key); 17 | } 18 | } 19 | return -1; 20 | } 21 | 22 | int main(){ 23 | int n; 24 | cout<<"Enter the size of array: "; 25 | cin>>n; 26 | int arr[n]; 27 | cout<<"Enter the elements of array: "<>arr[i]; 30 | } 31 | cout<<"Enter the element you want to search: "; 32 | int key; 33 | cin>>key; 34 | int ans =bs(arr,0,n-1,key); 35 | if(ans==-1){ 36 | cout<<"Element not found"; 37 | } 38 | else{ 39 | cout<<"Element found at index: "< 2 | using namespace std; 3 | int main() 4 | { 5 | int a[10][10],b[10][10],mul[10][10],r,c,i,j,k; 6 | cout<<"enter the number of row="; 7 | cin>>r; 8 | cout<<"enter the number of column="; 9 | cin>>c; 10 | cout<<"enter the first matrix element=\n"; 11 | for(i=0;i>a[i][j]; 16 | } 17 | } 18 | cout<<"enter the second matrix element=\n"; 19 | for(i=0;i>b[i][j]; 24 | } 25 | } 26 | cout<<"multiply of the matrix=\n"; 27 | for(i=0;i 2 | using namespace std; 3 | struct gret{ 4 | 5 | int a,b,c; 6 | }; 7 | 8 | gret greatest(int a, int b, int c){ 9 | gret num; 10 | if(b>a&&b>c){ 11 | num.a=b; 12 | num.b=a; 13 | num.c=c; 14 | return num; 15 | } 16 | else if(c>a&&c>b){ 17 | num.a=c; 18 | num.b=b; 19 | num.c=a; 20 | 21 | return num; 22 | } 23 | else 24 | return {a,b,c}; 25 | 26 | 27 | } 28 | 29 | bool pythagoras(int num1,int num2,int num3){ 30 | gret s; 31 | s=greatest(num1,num2,num3); 32 | if (((s.a) * (s.a))==((s.b) * (s.b) + (s.c) * (s.c))){ 33 | cout<>a>>b>>c; 42 | if(pythagoras(a,b,c)){ 43 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | cin >> t; 7 | while (t--){ 8 | int n, m; 9 | cin >> n; 10 | int a[n]; 11 | for (int i = 0; i < n; i++) 12 | { 13 | cin >> a[i]; 14 | } 15 | cin >> m; 16 | int b[m]; 17 | for (int i = 0; i < m; i++) 18 | { 19 | cin >> b[i]; 20 | } 21 | 22 | int num1; 23 | for (int i = 0; i < n; i++) 24 | { 25 | if (a[i] > b[i]) 26 | { 27 | num1 = (a[i] * 10) + b[i]; 28 | cout << num1 << endl; 29 | } 30 | else if (a[i] == b[i]) 31 | { 32 | num1 = (a[i] * 10) + b[i]; 33 | cout << num1 << endl; 34 | } 35 | else 36 | { 37 | num1 = (b[i] * 10) + a[i]; 38 | cout << num1 << endl; 39 | } 40 | } 41 | cout< 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int sec_prev=0; 10 | while(1) 11 | { 12 | int seconds, minutes, hours; 13 | string str; 14 | 15 | //storing total seconds 16 | time_t total_seconds=time(0); 17 | 18 | //getting values of seconds, minutes and hours 19 | struct tm* ct=localtime(&total_seconds); 20 | 21 | seconds=ct->tm_sec; 22 | minutes=ct->tm_min; 23 | hours=ct->tm_hour; 24 | 25 | //converting it into 12 hour format 26 | if(hours>=12) 27 | str="PM"; 28 | else 29 | str="AM"; 30 | hours=hours>12?hours-12:hours; 31 | 32 | 33 | //printing the result 34 | if(seconds==sec_prev+1 || (sec_prev==59 && seconds==0)) 35 | { 36 | system("CLS"); 37 | cout<< (hours<10?"0":"") << hours <<":" << (minutes<10?"0":"") << minutes << ":" << (seconds<10?"0":"") << seconds << " " << str < List convertALtoLL(List aL) 12 | { 13 | 14 | // Create an empty LinkedList 15 | List lL = new LinkedList<>(); 16 | 17 | // Iterate through the aL 18 | for (T t : aL) { 19 | 20 | // Add each element into the lL 21 | lL.add(t); 22 | } 23 | 24 | // Return the converted LinkedList 25 | return lL; 26 | } 27 | 28 | public static void main(String args[]) 29 | { 30 | // Create an ArrayList 31 | List aL = Arrays.asList("Geeks", 32 | "forGeeks", 33 | "A computer Portal"); 34 | 35 | // Print the ArrayList 36 | System.out.println("ArrayList: " + aL); 37 | 38 | // convert the ArrayList to LinkedList 39 | List 40 | lL = convertALtoLL(aL); 41 | 42 | // Print the LinkedList 43 | System.out.println("LinkedList: " + lL); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /oddevensort/oddevensort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | void oddEvenSort(int arr[], int n) 4 | { 5 | bool isSorted = false; 6 | while (!isSorted) 7 | { 8 | isSorted = true; 9 | for (int i=1; i<=n-2; i=i+2) 10 | { 11 | if (arr[i] > arr[i+1]) 12 | { 13 | swap(arr[i], arr[i+1]); 14 | isSorted = false; 15 | } 16 | } 17 | for (int i=0; i<=n-2; i=i+2) 18 | { 19 | if (arr[i] > arr[i+1]) 20 | { 21 | swap(arr[i], arr[i+1]); 22 | isSorted = false; 23 | } 24 | } 25 | } 26 | return; 27 | } 28 | 29 | void printArray(int arr[], int n) 30 | { 31 | for (int i=0; i < n; i++) 32 | cout << arr[i] << " "; 33 | cout << "\n"; 34 | } 35 | 36 | 37 | int main() 38 | { 39 | int arr[] = {9,7,3,8,5,6,4,1}; 40 | int n = sizeof(arr)/sizeof(arr[0]); 41 | oddEvenSort(arr, n); 42 | printArray(arr, n); 43 | return (0); 44 | } 45 | -------------------------------------------------------------------------------- /Rohan/Find-K-Closest-Element.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | vector findKClosestElements(vector const &input, int target, int k) 7 | { 8 | int i = lower_bound(input.begin(), input.end(), target) - input.begin(); 9 | 10 | int left = i - 1; 11 | int right = i; 12 | 13 | // run `k` times 14 | while (k-- > 0) 15 | { 16 | 17 | 18 | if (left < 0 || (right < input.size() && 19 | abs(input[left] - target) > abs(input[right] - target))) { 20 | right++; 21 | } 22 | else { 23 | left--; 24 | } 25 | } 26 | 27 | // return `k` closest elements 28 | return vector(input.begin() + left + 1, input.begin() + right); 29 | } 30 | 31 | int main() 32 | { 33 | vector input = { 10, 12, 15, 17, 18, 20, 25 }; 34 | int target = 16, k = 4; 35 | 36 | vector result = findKClosestElements(input, target, k); 37 | for (int i: result) { 38 | cout << i << " "; 39 | } 40 | 41 | return 0; 42 | } -------------------------------------------------------------------------------- /Sorting/selectionsort.cpp: -------------------------------------------------------------------------------- 1 | //SELECTION SORT 2 | //TIME COMPLEXITY - O(N^2) 3 | //SPACE COMPLEXITY - O(1) 4 | #include 5 | using namespace std; 6 | //function to swap the elements 7 | void swap(int *p,int *q){ 8 | int temp=*p; 9 | *p=*q; 10 | *q=temp; 11 | } 12 | //SELECTION SORT 13 | void selectionSort(vector &v,int n){ 14 | for(int i=0;i>n; 28 | vector v(n,0); 29 | cout<<"Enter Elements:"<>a; 33 | v[i]=a; 34 | } 35 | selectionSort(v,n); 36 | cout<<"After Sorting:"< 2 | 3 | using namespace std; 4 | 5 | int knapsackUtil(vector& wt, vector& val, int ind, int W, vector>& dp){ 6 | 7 | if(ind == 0){ 8 | if(wt[0] <=W) return val[0]; 9 | else return 0; 10 | } 11 | 12 | if(dp[ind][W]!=-1) 13 | return dp[ind][W]; 14 | 15 | int notTaken = 0 + knapsackUtil(wt,val,ind-1,W,dp); 16 | 17 | int taken = INT_MIN; 18 | if(wt[ind] <= W) 19 | taken = val[ind] + knapsackUtil(wt,val,ind-1,W-wt[ind],dp); 20 | 21 | return dp[ind][W] = max(notTaken,taken); 22 | } 23 | 24 | 25 | int knapsack(vector& wt, vector& val, int n, int W){ 26 | 27 | vector> dp(n,vector(W+1,-1)); 28 | return knapsackUtil(wt, val, n-1, W, dp); 29 | } 30 | 31 | int main() { 32 | 33 | vector wt = {1,2,4,5}; 34 | vector val = {5,4,8,6}; 35 | int W=5; 36 | 37 | int n = wt.size(); 38 | 39 | cout<<"The Maximum value of items, thief can steal is " < 2 | using namespace std; 3 | float arr[3][3],arr2[3][3],arr3[3][3]={0},arr4[3][3]; 4 | int l=0; 5 | bool orthogonal_array(float arr[3][3]) 6 | {for(int i=0;i<3;i++) 7 | {for(int j=0;j<3;j++) 8 | arr2[i][j]=arr[j][i]; 9 | } 10 | for(int i=0;i<3;i++) 11 | {for(int j=0;j<3;j++) 12 | {for(int k=0;k<3;k++) 13 | arr3[i][j]+=arr[i][k]*arr2[k][j];} 14 | } 15 | for(int i=0;i<3;i++) 16 | {for(int j=0;j<3;j++) 17 | { if(i==j) 18 | arr4[i][j]=1; 19 | else 20 | arr4[i][j]=0; 21 | } 22 | } 23 | for(int i=0;i<3;i++) 24 | {for(int j=0;j<3;j++) 25 | { if(arr3[i][j]==arr4[i][j]) 26 | l++; 27 | } 28 | } 29 | if(l==9) 30 | return true; 31 | else 32 | return false; 33 | } 34 | int main() 35 | { 36 | cout<<"Enter the elements of 3x3 matrix"< 2 | #include 3 | using namespace std; 4 | 5 | class BinaryTreeNode { 6 | public: 7 | BinaryTreeNode(int d, BinaryTreeNode* L, BinaryTreeNode* R) : data(d), left(L), right(R){} 8 | int data; 9 | BinaryTreeNode *left, *right; 10 | }; 11 | 12 | void visit(BinaryTreeNode node){ 13 | cout << node.data << endl; 14 | } 15 | 16 | void print_BFT(BinaryTreeNode* T){ 17 | queue q; 18 | q.push(T); 19 | while(q.size()){ 20 | BinaryTreeNode* cur = q.front(); 21 | visit(*cur); 22 | if(cur->left) q.push(cur->left); 23 | if(cur->right) q.push(cur->right); 24 | q.pop(); 25 | } 26 | } 27 | 28 | void test1(){ 29 | BinaryTreeNode* T = new BinaryTreeNode(50, 30 | new BinaryTreeNode(25, 31 | new BinaryTreeNode(10,nullptr,nullptr), new BinaryTreeNode(30,nullptr, nullptr) 32 | ), 33 | new BinaryTreeNode(75, 34 | new BinaryTreeNode(60,nullptr,nullptr), new BinaryTreeNode(85,nullptr, nullptr) 35 | ) 36 | ); 37 | 38 | print_BFT(T); 39 | } 40 | 41 | int main() 42 | { 43 | test1(); 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /sahc++.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int xsize, ysize, * swap; 6 | int row1, row2; 7 | 8 | cout << "Enter the size of matrix : "; 9 | cin >> ysize >> xsize; 10 | int ** matrix = new int*[ysize]; 11 | // initialising columns for each row 12 | for(int i = 0; i < ysize; i++) { 13 | matrix[i] = new int[xsize]; 14 | } 15 | // taking value corresponding to each cell from input 16 | cout << "Enter the matrix\n"; 17 | for(int i = 0; i < ysize; i++) { 18 | for(int j = 0; j < xsize; j++) { 19 | cin >> matrix[i][j]; 20 | } 21 | } 22 | cout << "Enter the rows to be interchanged : "; 23 | cin >> row1 >> row2; 24 | // interchanging the rows 25 | swap = matrix[row1 - 1]; 26 | matrix[row1 - 1] = matrix[row2 - 1]; 27 | matrix[row2 - 1] = swap; 28 | // printing the values 29 | cout << "New Matrix\n"; 30 | for(int i = 0; i < ysize; i++) { 31 | for(int j = 0; j < xsize; j++) { 32 | cout << matrix[i][j] << " "; 33 | } 34 | cout << "\n"; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /magicsquare.CPP: -------------------------------------------------------------------------------- 1 | // C++ program to generate odd sized magic squares 2 | #include 3 | using namespace std; 4 | 5 | 6 | void generateSquare(int n) 7 | { 8 | int magicSquare[n][n]; 9 | 10 | 11 | memset(magicSquare, 0, sizeof(magicSquare)); 12 | 13 | 14 | int i = n / 2; 15 | int j = n - 1; 16 | 17 | 18 | for (int num = 1; num <= n * n;) { 19 | if (i == -1 && j == n) 20 | { 21 | j = n - 2; 22 | i = 0; 23 | } 24 | else { 25 | 26 | if (j == n) 27 | j = 0; 28 | 29 | if (i < 0) 30 | i = n - 1; 31 | } 32 | if (magicSquare[i][j]) 33 | { 34 | j -= 2; 35 | i++; 36 | continue; 37 | } 38 | else 39 | magicSquare[i][j] = num++; 40 | 41 | j++; 42 | i--; 43 | } 44 | 45 | cout << "The Magic Square for n=" << n 46 | << ":\nSum of " 47 | "each row or column " 48 | << n * (n * n + 1) / 2 << ":\n\n"; 49 | for (i = 0; i < n; i++) { 50 | for (j = 0; j < n; j++) 51 | 52 | cout << setw(4) << magicSquare[i][j] << " "; 53 | cout << endl; 54 | } 55 | } 56 | 57 | int main() 58 | { 59 | 60 | int n = 7; 61 | generateSquare(n); 62 | return 0; 63 | } 64 | 65 | 66 | -------------------------------------------------------------------------------- /pattern/jayampattern.cpp: -------------------------------------------------------------------------------- 1 | // C++ program to print 2 | // the given pattern 3 | #include 4 | using namespace std; 5 | 6 | void pattern(int n) 7 | { 8 | int i, j; 9 | 10 | // This is upper half of pattern 11 | for(i = 1; i <= n; i++) 12 | { 13 | for(j = 1; j <= (2 * n); j++) 14 | { 15 | 16 | // Left part of pattern 17 | if (i > (n - j + 1)) 18 | cout << " "; 19 | else 20 | cout << "*"; 21 | 22 | // Right part of pattern 23 | if ((i + n) > j) 24 | cout << " "; 25 | else 26 | cout << "*"; 27 | } 28 | cout << endl ; 29 | } 30 | 31 | // This is lower half of pattern 32 | for(i = 1; i <= n; i++) 33 | { 34 | for(j = 1; j <= (2 * n); j++) 35 | { 36 | 37 | // Right Part of pattern 38 | if (i < j) 39 | cout << " "; 40 | else 41 | cout << "*"; 42 | 43 | // Left Part of pattern 44 | if (i <= ((2 * n) - j)) 45 | cout << " "; 46 | else 47 | cout << "*"; 48 | } 49 | cout << endl; 50 | } 51 | } 52 | 53 | // Driver Code 54 | int main() 55 | { 56 | pattern(7); 57 | 58 | return 0; 59 | } 60 | 61 | // This code is contributed by bunnyram19 62 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 -2023 DEC Pavan Kamthane 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Polymorphism/strudent_excercise.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | class Shape{ 5 | public: 6 | virtual float area()=0; 7 | virtual float perimeter() =0; 8 | }; 9 | class Rectangle : public Shape{ 10 | private: 11 | float length, breadth; 12 | public: 13 | Rectangle(float l, float b){ 14 | length =l; 15 | breadth =b; 16 | } 17 | float area(){ 18 | return length*breadth; 19 | } 20 | float perimeter(){ 21 | return 2*(length+breadth); 22 | } 23 | }; 24 | class Circle : public Shape{ 25 | private: 26 | float radius; 27 | public: 28 | Circle(float r){ 29 | radius =r; 30 | } 31 | float area(){ 32 | return M_PI*pow(radius,2); 33 | } 34 | float perimeter(){ 35 | return M_PI*radius*2; 36 | } 37 | }; 38 | int main(){ 39 | Shape *s = new Rectangle(10,5); 40 | cout << s->area()<< endl; 41 | cout<< s->perimeter() << endl; 42 | s= new Circle(10); 43 | cout << s->area() << endl; 44 | cout<< s->perimeter() << endl; 45 | 46 | return 0; 47 | } -------------------------------------------------------------------------------- /Matrix/Matrix Multiplication.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | float arr[3][3],arr2[3][3],arr3[3][3]={0},arr4[3][3]; 4 | int l=0; 5 | bool orthogonal_array(float arr[3][3]) 6 | {for(int i=0;i<3;i++) 7 | {for(int j=0;j<3;j++) 8 | arr2[i][j]=arr[j][i]; 9 | } 10 | for(int i=0;i<3;i++) 11 | {for(int j=0;j<3;j++) 12 | {for(int k=0;k<3;k++) 13 | arr3[i][j]+=arr[i][k]*arr2[k][j];} 14 | } 15 | for(int i=0;i<3;i++) 16 | {for(int j=0;j<3;j++) 17 | { if(i==j) 18 | arr4[i][j]=1; 19 | else 20 | arr4[i][j]=0; 21 | } 22 | } 23 | for(int i=0;i<3;i++) 24 | {for(int j=0;j<3;j++) 25 | { if(arr3[i][j]==arr4[i][j]) 26 | l++; 27 | } 28 | } 29 | if(l==9) 30 | return true; 31 | else 32 | return false; 33 | } 34 | int main() 35 | { 36 | cout<<"Enter the elements of 3x3 matrix"< 2 | using namespace std; 3 | 4 | int Partition(int *arr, int s, int e){ 5 | 6 | int pivot = arr[s]; 7 | 8 | int count = 0; 9 | 10 | for(int i=s+1;i<=e;i++){ 11 | if(arr[i] <= pivot){ 12 | count++; 13 | } 14 | } 15 | 16 | int pivotindex = s + count; 17 | swap(arr[s],arr[pivotindex]); 18 | 19 | int i=s,j=e; 20 | 21 | while(ipivotindex){ 22 | while(arr[i] <= pivot) 23 | i++; 24 | 25 | while(arr[j] > pivot) 26 | j--; 27 | 28 | if(ipivotindex) 29 | swap(arr[i++],arr[j--]); 30 | } 31 | 32 | return pivotindex; 33 | } 34 | 35 | void QuickSort(int *arr, int s, int e){ 36 | 37 | if(s>=e) 38 | return; 39 | 40 | int p = Partition(arr,s,e); 41 | 42 | QuickSort(arr,s,p-1); 43 | QuickSort(arr,p+1,e); 44 | 45 | } 46 | 47 | int main(){ 48 | int arr[6] = {15,6,13,5,12,9}; 49 | int n = 6; 50 | 51 | QuickSort(arr, 0 ,n-1); 52 | 53 | for(int i=0; i lrs.length()) lrs=x; 24 | } 25 | } 26 | System.out.println("Longest repeating sequence: "+lrs); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Varun Kotgire/Adult or not.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | // cout<<"This is tutorial 9" 7 | int age; 8 | cout<<"Tell me your age"; 9 | cin>>age; 10 | 11 | // 1. Selection control structure: If else-if else ladder 12 | // if((age<18) && (age>0)) { 13 | // cout<<"You can not come to my party"< 2 | using namespace std; 3 | // practice --> https://practice.geeksforgeeks.org/problems/reverse-a-linked-list/1 4 | 5 | struct ListNode 6 | { 7 | int val; 8 | ListNode *next; 9 | ListNode(int x) : val(x), next(NULL) {} 10 | }; 11 | 12 | ListNode *reverseList(ListNode *head) 13 | { 14 | if (head == NULL || head->next == NULL) 15 | return head; 16 | ListNode *prev = NULL, *nxt = NULL; 17 | while (head != NULL) 18 | { 19 | nxt = head->next; 20 | head->next = prev; 21 | prev = head; 22 | head = nxt; 23 | } 24 | 25 | return prev; 26 | } 27 | 28 | int main() 29 | { 30 | //demo list 31 | ListNode *t1, *t2, *t3, *t4, *t5; 32 | t1 = new ListNode(1); 33 | t2 = new ListNode(2); 34 | t3 = new ListNode(3); 35 | t4 = new ListNode(4); 36 | t5 = new ListNode(5); 37 | t1->next = t2; 38 | t2->next = t3; 39 | t3->next = t4; 40 | t4->next = t5; 41 | t5->next = NULL; 42 | 43 | ListNode *h = reverseList(t1); 44 | while (h != NULL) 45 | { 46 | cout << h->val << " "; 47 | h = h->next; 48 | } 49 | 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /DSA in CPP/Array Adt/Reversing_an_array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | struct Array 4 | { 5 | int A[20]; 6 | int size; 7 | int length; 8 | }; 9 | void Swap(int *a, int *b) 10 | { 11 | int temp; 12 | temp = *a; 13 | *a = *b; 14 | *b = temp; 15 | } 16 | void Display(struct Array arr) 17 | { 18 | for (int i = 0; i < arr.length; i++) 19 | { 20 | cout << arr.A[i] << " "; 21 | } 22 | } 23 | void Reverse(struct Array *arr) 24 | { 25 | 26 | int *B; 27 | int i; 28 | int j; 29 | B = (int *)malloc(arr->length * sizeof(int)); 30 | 31 | for (j = arr->length - 1, i = 0; j >= 0; i++, j--) 32 | { 33 | B[j] = arr->A[i]; 34 | } 35 | for (i = 0; i < arr->length; i++) 36 | { 37 | arr->A[i] = B[i]; 38 | } 39 | } 40 | void Reverse2(struct Array *arr) 41 | { 42 | int i, j; 43 | for (i = arr->length - 1, j = 0; j < i; j++, i--) 44 | { 45 | Swap(&arr->A[i], &arr->A[j]); 46 | } 47 | } 48 | int main() 49 | { 50 | struct Array arr = {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 20, 10}; 51 | Reverse2(&arr); 52 | Display(arr); 53 | return 0; 54 | } -------------------------------------------------------------------------------- /binarysearch.cpp: -------------------------------------------------------------------------------- 1 | // C++ program to implement recursive Binary Search 2 | #include 3 | using namespace std; 4 | 5 | // A recursive binary search function. It returns 6 | // location of x in given array arr[l..r] is present, 7 | // otherwise -1 8 | int binarySearch(int arr[], int l, int r, int x) 9 | { 10 | if (r >= l) { 11 | int mid = l + (r - l) / 2; 12 | 13 | // If the element is present at the middle 14 | // itself 15 | if (arr[mid] == x) 16 | return mid; 17 | 18 | // If element is smaller than mid, then 19 | // it can only be present in left subarray 20 | if (arr[mid] > x) 21 | return binarySearch(arr, l, mid - 1, x); 22 | 23 | // Else the element can only be present 24 | // in right subarray 25 | return binarySearch(arr, mid + 1, r, x); 26 | } 27 | 28 | // We reach here when element is not 29 | // present in array 30 | return -1; 31 | } 32 | 33 | int main(void) 34 | { 35 | int arr[] = { 2, 3, 4, 10, 40 }; 36 | int x = 10; 37 | int n = sizeof(arr) / sizeof(arr[0]); 38 | int result = binarySearch(arr, 0, n - 1, x); 39 | (result == -1) 40 | ? cout << "Element is not present in array" 41 | : cout << "Element is present at index " << result; 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /dnf_sort.cpp: -------------------------------------------------------------------------------- 1 | // C++ program to sort an array 2 | // with 0, 1 and 2 in a single pass 3 | #include 4 | using namespace std; 5 | 6 | // Function to sort the input array, 7 | // the array is assumed 8 | // to have values in {0, 1, 2} 9 | void sort012(int a[], int arr_size) 10 | { 11 | int lo = 0; 12 | int hi = arr_size - 1; 13 | int mid = 0; 14 | 15 | // Iterate till all the elements 16 | // are sorted 17 | while (mid <= hi) { 18 | switch (a[mid]) { 19 | 20 | // If the element is 0 21 | case 0: 22 | swap(a[lo++], a[mid++]); 23 | break; 24 | 25 | // If the element is 1 . 26 | case 1: 27 | mid++; 28 | break; 29 | 30 | // If the element is 2 31 | case 2: 32 | swap(a[mid], a[hi--]); 33 | break; 34 | } 35 | } 36 | } 37 | 38 | // Function to print array arr[] 39 | void printArray(int arr[], int arr_size) 40 | { 41 | // Iterate and print every element 42 | for (int i = 0; i < arr_size; i++) 43 | cout << arr[i] << " "; 44 | } 45 | 46 | // Driver Code 47 | int main() 48 | { 49 | int arr[] = { 0, 1, 1, 0, 1, 2, 1, 2, 0, 0, 0, 1 }; 50 | int n = sizeof(arr) / sizeof(arr[0]); 51 | 52 | sort012(arr, n); 53 | 54 | printArray(arr, n); 55 | 56 | return 0; 57 | } 58 | 59 | 60 | -------------------------------------------------------------------------------- /sort/dnf-sort.cpp: -------------------------------------------------------------------------------- 1 | // C++ program to sort an array 2 | // with 0, 1 and 2 in a single pass 3 | #include 4 | using namespace std; 5 | 6 | // Function to sort the input array, 7 | // the array is assumed 8 | // to have values in {0, 1, 2} 9 | void sort012(int a[], int arr_size) 10 | { 11 | int lo = 0; 12 | int hi = arr_size - 1; 13 | int mid = 0; 14 | 15 | // Iterate till all the elements 16 | // are sorted 17 | while (mid <= hi) { 18 | switch (a[mid]) { 19 | 20 | // If the element is 0 21 | case 0: 22 | swap(a[lo++], a[mid++]); 23 | break; 24 | 25 | // If the element is 1 . 26 | case 1: 27 | mid++; 28 | break; 29 | 30 | // If the element is 2 31 | case 2: 32 | swap(a[mid], a[hi--]); 33 | break; 34 | } 35 | } 36 | } 37 | 38 | // Function to print array arr[] 39 | void printArray(int arr[], int arr_size) 40 | { 41 | // Iterate and print every element 42 | for (int i = 0; i < arr_size; i++) 43 | cout << arr[i] << " "; 44 | } 45 | 46 | // Driver Code 47 | int main() 48 | { 49 | int arr[] = { 0, 1, 1, 0, 1, 2, 1, 2, 0, 0, 0, 1 }; 50 | int n = sizeof(arr) / sizeof(arr[0]); 51 | 52 | sort012(arr, n); 53 | 54 | printArray(arr, n); 55 | 56 | return 0; 57 | } 58 | 59 | 60 | -------------------------------------------------------------------------------- /Cycle Sort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void cyclicSort(int arr[], int n){ 5 | int i = 0; 6 | while(i < n) 7 | { 8 | // as array is of 1 based indexing so the 9 | // correct position or index number of each 10 | // element is element-1 i.e. 1 will be at 0th 11 | // index similarly 2 correct index will 1 so 12 | // on... 13 | int correct = arr[i] - 1 ; 14 | if(arr[i] != arr[correct]){ 15 | 16 | // if array element should be lesser than 17 | // size and array element should not be at 18 | // its correct position then only swap with 19 | // its correct position or index value 20 | swap(arr[i], arr[correct]) ; 21 | }else{ 22 | 23 | // if element is at its correct position 24 | // just increment i and check for remaining 25 | // array elements 26 | i++ ; 27 | } 28 | } 29 | 30 | } 31 | 32 | void printArray(int arr[], int size) 33 | { 34 | int i; 35 | for (i = 0; i < size; i++) 36 | cout << arr[i] << " "; 37 | cout << endl; 38 | } 39 | 40 | int main() { 41 | 42 | int arr[] = { 3, 2, 4, 5, 1}; 43 | int n = sizeof(arr) / sizeof(arr[0]); 44 | cout << "Before sorting array: \n"; 45 | printArray(arr, n); 46 | cyclicSort(arr, n); 47 | cout << "Sorted array: \n"; 48 | printArray(arr, n); 49 | return 0; 50 | 51 | } 52 | -------------------------------------------------------------------------------- /LCS_Program_for_Longest_Common_Subsequence_DP.cpp: -------------------------------------------------------------------------------- 1 | /* Dynamic Programming C/C++ implementation of LCS problem */ 2 | #include 3 | 4 | int max(int a, int b); 5 | 6 | /* Returns length of LCS for X[0..m-1], Y[0..n-1] */ 7 | int lcs(char* X, char* Y, int m, int n) 8 | { 9 | int L[m + 1][n + 1]; 10 | int i, j; 11 | 12 | /* Following steps build L[m+1][n+1] in bottom up fashion. Note 13 | that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */ 14 | for (i = 0; i <= m; i++) { 15 | for (j = 0; j <= n; j++) { 16 | if (i == 0 || j == 0) 17 | L[i][j] = 0; 18 | 19 | else if (X[i - 1] == Y[j - 1]) 20 | L[i][j] = L[i - 1][j - 1] + 1; 21 | 22 | else 23 | L[i][j] = max(L[i - 1][j], L[i][j - 1]); 24 | } 25 | } 26 | 27 | /* L[m][n] contains length of LCS for X[0..n-1] and Y[0..m-1] */ 28 | return L[m][n]; 29 | } 30 | 31 | /* Utility function to get max of 2 integers */ 32 | int max(int a, int b) 33 | { 34 | return (a > b) ? a : b; 35 | } 36 | 37 | /* Driver program to test above function */ 38 | int main() 39 | { 40 | char X[] = "AGGTAB"; 41 | char Y[] = "GXTXAYB"; 42 | 43 | int m = strlen(X); 44 | int n = strlen(Y); 45 | 46 | printf("Length of LCS is %d\n", lcs(X, Y, m, n)); 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /Juggling_Algorithm/Juggling.cpp: -------------------------------------------------------------------------------- 1 | // C++ program to rotate an array by 2 | // d elements 3 | #include 4 | using namespace std; 5 | 6 | /*Function to get gcd of a and b*/ 7 | int gcd(int a, int b) 8 | { 9 | if (b == 0) 10 | return a; 11 | 12 | else 13 | return gcd(b, a % b); 14 | } 15 | 16 | /*Function to left rotate arr[] of size n by d*/ 17 | void leftRotate(int arr[], int d, int n) 18 | { 19 | /* To handle if d >= n */ 20 | d = d % n; 21 | int g_c_d = gcd(d, n); 22 | for (int i = 0; i < g_c_d; i++) { 23 | /* move i-th values of blocks */ 24 | int temp = arr[i]; 25 | int j = i; 26 | 27 | while (1) { 28 | int k = j + d; 29 | if (k >= n) 30 | k = k - n; 31 | 32 | if (k == i) 33 | break; 34 | 35 | arr[j] = arr[k]; 36 | j = k; 37 | } 38 | arr[j] = temp; 39 | } 40 | } 41 | 42 | // Function to print an array 43 | void printArray(int arr[], int size) 44 | { 45 | for (int i = 0; i < size; i++) 46 | cout << arr[i] << " "; 47 | } 48 | 49 | /* Driver program to test above functions */ 50 | int main() 51 | { 52 | int arr[] = { 1, 2, 3, 4, 5, 6, 7 }; 53 | int n = sizeof(arr) / sizeof(arr[0]); 54 | 55 | // Function calling 56 | leftRotate(arr, 2, n); 57 | printArray(arr, n); 58 | 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /mergesort.cpp: -------------------------------------------------------------------------------- 1 | // C++ program to merge two sorted arrays with O(1) extra 2 | // space. 3 | #include 4 | using namespace std; 5 | 6 | // Merge ar1[] and ar2[] with O(1) extra space 7 | void merge(int ar1[], int ar2[], int m, int n) 8 | { 9 | // Iterate through all elements 10 | // of ar2[] starting from the last element 11 | for (int i = n - 1; i >= 0; i--) { 12 | // Find the smallest element greater than ar2[i]. 13 | // Move all elements one position ahead till the 14 | // smallest greater element is not found */ 15 | int j, last = ar1[m - 1]; 16 | for (j = m - 2; j >= 0 && ar1[j] > ar2[i]; j--) 17 | ar1[j + 1] = ar1[j]; 18 | 19 | // If there was a greater element 20 | if (last > ar2[i]) { 21 | ar1[j + 1] = ar2[i]; 22 | ar2[i] = last; 23 | } 24 | } 25 | } 26 | 27 | // Driver program 28 | int main() 29 | { 30 | int ar1[] = { 1, 5, 9, 10, 15, 20 }; 31 | int ar2[] = { 2, 3, 8, 13 }; 32 | int m = sizeof(ar1) / sizeof(ar1[0]); 33 | int n = sizeof(ar2) / sizeof(ar2[0]); 34 | merge(ar1, ar2, m, n); 35 | 36 | cout << "After Merging \nFirst Array: "; 37 | for (int i = 0; i < m; i++) 38 | cout << ar1[i] << " "; 39 | cout << "\nSecond Array: "; 40 | for (int i = 0; i < n; i++) 41 | cout << ar2[i] << " "; 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /Sort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | 5 | void insert(int a[], int n) /* function to sort an aay with insertion sort */ 6 | 7 | { 8 | 9 | int i, j, temp; 10 | 11 | for (i = 1; i < n; i++) { 12 | 13 | temp = a[i]; 14 | 15 | j = i - 1; 16 | 17 | 18 | 19 | while(j>=0 && temp <= a[j]) /* Move the elements greater than temp to one position ahead from their current position*/ 20 | 21 | { 22 | 23 | a[j+1] = a[j]; 24 | 25 | j = j-1; 26 | 27 | } 28 | 29 | a[j+1] = temp; 30 | 31 | } 32 | 33 | } 34 | 35 | 36 | 37 | void printArr(int a[], int n) /* function to print the array */ 38 | 39 | { 40 | 41 | int i; 42 | 43 | for (i = 0; i < n; i++) 44 | 45 | printf("%d ", a[i]); 46 | 47 | } 48 | 49 | 50 | 51 | int main() 52 | 53 | { 54 | 55 | int a[] = { 12, 31, 25, 8, 32, 17 }; 56 | 57 | int n = sizeof(a) / sizeof(a[0]); 58 | 59 | printf("Before sorting array elements are - \n"); 60 | 61 | printArr(a, n); 62 | 63 | insert(a, n); 64 | 65 | printf("\nAfter sorting array elements are - \n"); 66 | 67 | printArr(a, n); 68 | 69 | 70 | 71 | return 0; 72 | 73 | } 74 | -------------------------------------------------------------------------------- /Csorting.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | 5 | void insert(int a[], int n) /* function to sort an aay with insertion sort */ 6 | 7 | { 8 | 9 | int i, j, temp; 10 | 11 | for (i = 1; i < n; i++) { 12 | 13 | temp = a[i]; 14 | 15 | j = i - 1; 16 | 17 | 18 | 19 | while(j>=0 && temp <= a[j]) /* Move the elements greater than temp to one position ahead from their current position*/ 20 | 21 | { 22 | 23 | a[j+1] = a[j]; 24 | 25 | j = j-1; 26 | 27 | } 28 | 29 | a[j+1] = temp; 30 | 31 | } 32 | 33 | } 34 | 35 | 36 | 37 | void printArr(int a[], int n) /* function to print the array */ 38 | 39 | { 40 | 41 | int i; 42 | 43 | for (i = 0; i < n; i++) 44 | 45 | printf("%d ", a[i]); 46 | 47 | } 48 | 49 | 50 | 51 | int main() 52 | 53 | { 54 | 55 | int a[] = { 12, 31, 25, 8, 32, 17 }; 56 | 57 | int n = sizeof(a) / sizeof(a[0]); 58 | 59 | printf("Before sorting array elements are - \n"); 60 | 61 | printArr(a, n); 62 | 63 | insert(a, n); 64 | 65 | printf("\nAfter sorting array elements are - \n"); 66 | 67 | printArr(a, n); 68 | 69 | 70 | 71 | return 0; 72 | 73 | } 74 | -------------------------------------------------------------------------------- /Sorting.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | 5 | void insert(int a[], int n) /* function to sort an aay with insertion sort */ 6 | 7 | { 8 | 9 | int i, j, temp; 10 | 11 | for (i = 1; i < n; i++) { 12 | 13 | temp = a[i]; 14 | 15 | j = i - 1; 16 | 17 | 18 | 19 | while(j>=0 && temp <= a[j]) /* Move the elements greater than temp to one position ahead from their current position*/ 20 | 21 | { 22 | 23 | a[j+1] = a[j]; 24 | 25 | j = j-1; 26 | 27 | } 28 | 29 | a[j+1] = temp; 30 | 31 | } 32 | 33 | } 34 | 35 | 36 | 37 | void printArr(int a[], int n) /* function to print the array */ 38 | 39 | { 40 | 41 | int i; 42 | 43 | for (i = 0; i < n; i++) 44 | 45 | printf("%d ", a[i]); 46 | 47 | } 48 | 49 | 50 | 51 | int main() 52 | 53 | { 54 | 55 | int a[] = { 12, 31, 25, 8, 32, 17 }; 56 | 57 | int n = sizeof(a) / sizeof(a[0]); 58 | 59 | printf("Before sorting array elements are - \n"); 60 | 61 | printArr(a, n); 62 | 63 | insert(a, n); 64 | 65 | printf("\nAfter sorting array elements are - \n"); 66 | 67 | printArr(a, n); 68 | 69 | 70 | 71 | return 0; 72 | 73 | } 74 | -------------------------------------------------------------------------------- /iostreams/Serialization.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | class Student{ 5 | private: 6 | string Name; 7 | int Roll; 8 | string Branch; 9 | public: 10 | Student(){}; 11 | Student(string n, int r, string b){ 12 | Name = n; 13 | Roll = r; 14 | Branch = b; 15 | } 16 | friend ofstream & operator<<(ofstream &ofs, Student s); 17 | friend ifstream & operator>>(ifstream &ifs, Student &s); 18 | friend ostream & operator<<(ostream &os, Student &s); 19 | }; 20 | ofstream & operator<<(ofstream &ofs, Student s){ 21 | ofs << s.Name<>(ifstream &ifs, Student &s){ 33 | ifs>>s.Name; 34 | ifs>>s.Roll; 35 | ifs>>s.Branch; 36 | return ifs; 37 | } 38 | int main(){ 39 | ofstream ofs("My.txt"); 40 | Student Swaraj("Swaraj", 52, "CS"); 41 | ofs<> Swaraj; 46 | cout < 4 | using namespace std; 5 | 6 | // defining the number of vertices 7 | #define nV 4 8 | 9 | #define INF 999 10 | 11 | void printMatrix(int matrix[][nV]); 12 | 13 | // Implementing floyd warshall algorithm 14 | void floydWarshall(int graph[][nV]) { 15 | int matrix[nV][nV], i, j, k; 16 | 17 | for (i = 0; i < nV; i++) 18 | for (j = 0; j < nV; j++) 19 | matrix[i][j] = graph[i][j]; 20 | 21 | // Adding vertices individually 22 | for (k = 0; k < nV; k++) { 23 | for (i = 0; i < nV; i++) { 24 | for (j = 0; j < nV; j++) { 25 | if (matrix[i][k] + matrix[k][j] < matrix[i][j]) 26 | matrix[i][j] = matrix[i][k] + matrix[k][j]; 27 | } 28 | } 29 | } 30 | printMatrix(matrix); 31 | } 32 | 33 | void printMatrix(int matrix[][nV]) { 34 | for (int i = 0; i < nV; i++) { 35 | for (int j = 0; j < nV; j++) { 36 | if (matrix[i][j] == INF) 37 | printf("%4s", "INF"); 38 | else 39 | printf("%4d", matrix[i][j]); 40 | } 41 | printf("\n"); 42 | } 43 | } 44 | 45 | int main() { 46 | int graph[nV][nV] = {{0, 3, INF, 5}, 47 | {2, 0, INF, 4}, 48 | {INF, 1, 0, INF}, 49 | {INF, INF, 2, 0}}; 50 | floydWarshall(graph); 51 | } 52 | -------------------------------------------------------------------------------- /structure-python/structure.py: -------------------------------------------------------------------------------- 1 | # Max-Heap data structure in Python 2 | 3 | def heapify(arr, n, i): 4 | largest = i 5 | l = 2 * i + 1 6 | r = 2 * i + 2 7 | 8 | if l < n and arr[i] < arr[l]: 9 | largest = l 10 | 11 | if r < n and arr[largest] < arr[r]: 12 | largest = r 13 | 14 | if largest != i: 15 | arr[i],arr[largest] = arr[largest],arr[i] 16 | heapify(arr, n, largest) 17 | 18 | def insert(array, newNum): 19 | size = len(array) 20 | if size == 0: 21 | array.append(newNum) 22 | else: 23 | array.append(newNum); 24 | for i in range((size//2)-1, -1, -1): 25 | heapify(array, size, i) 26 | 27 | def deleteNode(array, num): 28 | size = len(array) 29 | i = 0 30 | for i in range(0, size): 31 | if num == array[i]: 32 | break 33 | 34 | array[i], array[size-1] = array[size-1], array[i] 35 | 36 | array.remove(num) 37 | 38 | for i in range((len(array)//2)-1, -1, -1): 39 | heapify(array, len(array), i) 40 | 41 | arr = [] 42 | 43 | insert(arr, 3) 44 | insert(arr, 4) 45 | insert(arr, 9) 46 | insert(arr, 5) 47 | insert(arr, 2) 48 | 49 | print ("Max-Heap array: " + str(arr)) 50 | 51 | deleteNode(arr, 4) 52 | print("After deleting an element: " + str(arr)) 53 | -------------------------------------------------------------------------------- /lcs/lcs.cpp: -------------------------------------------------------------------------------- 1 | // The longest common subsequence in C++ 2 | 3 | #include 4 | using namespace std; 5 | 6 | void lcsAlgo(char *S1, char *S2, int m, int n) { 7 | int LCS_table[m + 1][n + 1]; 8 | 9 | 10 | // Building the mtrix in bottom-up way 11 | for (int i = 0; i <= m; i++) { 12 | for (int j = 0; j <= n; j++) { 13 | if (i == 0 || j == 0) 14 | LCS_table[i][j] = 0; 15 | else if (S1[i - 1] == S2[j - 1]) 16 | LCS_table[i][j] = LCS_table[i - 1][j - 1] + 1; 17 | else 18 | LCS_table[i][j] = max(LCS_table[i - 1][j], LCS_table[i][j - 1]); 19 | } 20 | } 21 | 22 | int index = LCS_table[m][n]; 23 | char lcsAlgo[index + 1]; 24 | lcsAlgo[index] = '\0'; 25 | 26 | int i = m, j = n; 27 | while (i > 0 && j > 0) { 28 | if (S1[i - 1] == S2[j - 1]) { 29 | lcsAlgo[index - 1] = S1[i - 1]; 30 | i--; 31 | j--; 32 | index--; 33 | } 34 | 35 | else if (LCS_table[i - 1][j] > LCS_table[i][j - 1]) 36 | i--; 37 | else 38 | j--; 39 | } 40 | 41 | // Printing the sub sequences 42 | cout << "S1 : " << S1 << "\nS2 : " << S2 << "\nLCS: " << lcsAlgo << "\n"; 43 | } 44 | 45 | int main() { 46 | char S1[] = "ACADB"; 47 | char S2[] = "CBDA"; 48 | int m = strlen(S1); 49 | int n = strlen(S2); 50 | 51 | lcsAlgo(S1, S2, m, n); 52 | } 53 | -------------------------------------------------------------------------------- /Inheritance/excercise.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Employee{ 4 | private: 5 | int id; 6 | string name; 7 | public: 8 | Employee(int id, string name){ 9 | this->id = id; 10 | this->name = name; 11 | } 12 | int getid(){ 13 | return id; 14 | } 15 | string getname(){ 16 | return name; 17 | } 18 | }; 19 | class Fulltime : public Employee{ 20 | private: 21 | int salary; 22 | public: 23 | Fulltime(int salary, int id, string name): Employee(id, name){ 24 | this->salary = salary; 25 | } 26 | void showsalary(){ 27 | cout << "The salary of " << getname() << " with id "<< getid() << " is " << salary << endl; 28 | } 29 | }; 30 | class Parttime : public Employee{ 31 | private: 32 | int DailyWage; 33 | public: 34 | Parttime(int DailyWage, int id, string name): Employee(id, name){ 35 | this->DailyWage = DailyWage; 36 | } 37 | void showwage(){ 38 | cout << "The DailyWage of " << getname() << " with id "<< getid() << " is " << DailyWage<< endl; 39 | } 40 | }; 41 | int main(){ 42 | Fulltime f1(20000000, 1, "Swaraj"); 43 | Parttime f2(200000000, 2, "Mhatre"); 44 | f1.showsalary(); 45 | f2.showwage(); 46 | return 0; 47 | } -------------------------------------------------------------------------------- /Linked List/insert-at-beginning-of-singlylinkedlist.cpp: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | import java.lang.*; 4 | 5 | class Node 6 | { 7 | int data; 8 | Node next; 9 | Node(int d){ 10 | data=d; 11 | next=null; 12 | } 13 | } 14 | 15 | class Test { 16 | 17 | public static void main(String args[]) 18 | { 19 | Node head=new Node(10); 20 | head.next=new Node(20); 21 | head.next.next=new Node(30); 22 | head.next.next.next=head; 23 | head=insertBegin(head,15); 24 | printlist(head); 25 | 26 | } 27 | 28 | public static void printlist(Node head) 29 | { 30 | if(head==null)return; 31 | Node r=head; 32 | do{ 33 | System.out.print(r.data+" "); 34 | r=r.next; 35 | }while(r!=head); 36 | } 37 | 38 | static Node insertBegin(Node head,int x) 39 | { 40 | Node temp=new Node(x); 41 | if(head==null){ 42 | temp.next=temp; 43 | return temp; 44 | } 45 | else 46 | { 47 | temp.next=head.next; 48 | head.next=temp; 49 | int t=head.data; 50 | head.data=temp.data; 51 | temp.data=t; 52 | return head; 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /transpose_matrix.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int a[10][10], transpose[10][10], row, column, i, j; 6 | 7 | cout << "Enter rows and columns of matrix: "; 8 | cin >> row >> column; 9 | 10 | cout << "\nEnter elements of matrix: " << endl; 11 | 12 | // Storing matrix elements 13 | for (int i = 0; i < row; ++i) { 14 | for (int j = 0; j < column; ++j) { 15 | cout << "Enter element a" << i + 1 << j + 1 << ": "; 16 | cin >> a[i][j]; 17 | } 18 | } 19 | 20 | // Printing the a matrix 21 | cout << "\nEntered Matrix: " << endl; 22 | for (int i = 0; i < row; ++i) { 23 | for (int j = 0; j < column; ++j) { 24 | cout << " " << a[i][j]; 25 | if (j == column - 1) 26 | cout << endl << endl; 27 | } 28 | } 29 | 30 | // Computing transpose of the matrix 31 | for (int i = 0; i < row; ++i) 32 | for (int j = 0; j < column; ++j) { 33 | transpose[j][i] = a[i][j]; 34 | } 35 | 36 | // Printing the transpose 37 | cout << "\nTranspose of Matrix: " << endl; 38 | for (int i = 0; i < column; ++i) 39 | for (int j = 0; j < row; ++j) { 40 | cout << " " << transpose[i][j]; 41 | if (j == row - 1) 42 | cout << endl << endl; 43 | } 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /Guess the Number/guess_the_number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | back: 9 | int number, guess, nguesses = 1; 10 | ; 11 | srand(time(0)); 12 | number = rand() % 100 + 1; // Generates a random number between 1 and 100 13 | // cout<<"The number is "<> guess; 21 | if (guess > number) 22 | { 23 | cout << "Lower number please!" << endl; 24 | } 25 | else if (guess < number) 26 | { 27 | cout << "Higher number please!" << endl; 28 | } 29 | else 30 | { 31 | cout << "You guessed it in " << nguesses << " attempts" << endl; 32 | } 33 | nguesses++; 34 | } while (guess != number); 35 | 36 | char restart; 37 | cout << "press R for play again:"; 38 | cin >> restart; 39 | if (restart == 'R' || restart == 'r') 40 | { 41 | goto back; 42 | } 43 | else 44 | { 45 | cout << "INVALID CODE" << endl; 46 | } 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /Dynamic Programming/EditDistance.cpp: -------------------------------------------------------------------------------- 1 | // Edit Distance - variation of LCS Problem 2 | // Problem link: https://leetcode.com/problems/edit-distance/ 3 | 4 | 5 | #include 6 | using namespace std; 7 | 8 | 9 | class Solution { 10 | public: 11 | int editDistance(string s, string t) 12 | { 13 | int n = s.size(); 14 | int m = t.size(); 15 | 16 | int dp[n+1][m+1]; 17 | 18 | for(int i = 0; i <= n; i++) 19 | { 20 | for(int j = 0; j <= m; j++) 21 | { 22 | if(i == 0) 23 | dp[i][j] = j; 24 | if(j == 0) 25 | dp[i][j] = i; 26 | } 27 | } 28 | 29 | for(int i = 1; i <= n; i++) 30 | { 31 | for(int j = 1; j <= m; j++) 32 | { 33 | if(s[i-1] == t[j-1]) 34 | dp[i][j] = dp[i-1][j-1]; 35 | else 36 | dp[i][j] = 1 + min({dp[i-1][j], dp[i][j-1], dp[i-1][j-1]}); 37 | } 38 | } 39 | 40 | return dp[n][m]; 41 | } 42 | }; 43 | 44 | int main() 45 | { 46 | string s, t; 47 | cin >> s >> t; 48 | Solution ob; 49 | int ans = ob.editDistance(s, t); 50 | cout << ans << "\n"; 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /Hashing/linearprobing.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Solution 5 | { 6 | public: 7 | vector linearProbing(int hashSize, int arr[], int sizeOfArray) 8 | { 9 | // Your code here 10 | vector v(hashSize, -1); 11 | for (int i = 0; i < sizeOfArray; i++) 12 | { 13 | int k = arr[i] % hashSize; 14 | int p = k; 15 | while (v[k] != -1 && v[k] != arr[i]) 16 | { 17 | k = (k + 1) % hashSize; 18 | if (k == p) 19 | break; 20 | } 21 | if (v[k] == -1) 22 | v[k] = arr[i]; 23 | } 24 | return v; 25 | } 26 | }; 27 | 28 | int main() 29 | { 30 | int t; 31 | cin >> t; 32 | while (t--) 33 | { 34 | int hashSize; 35 | cin >> hashSize; 36 | 37 | int sizeOfArray; 38 | cin >> sizeOfArray; 39 | int arr[sizeOfArray]; 40 | 41 | for (int i = 0; i < sizeOfArray; i++) 42 | cin >> arr[i]; 43 | 44 | vector hash; 45 | Solution obj; 46 | hash = obj.linearProbing(hashSize, arr, sizeOfArray); 47 | 48 | for (int i = 0; i < hashSize; i++) 49 | cout << hash[i] << " "; 50 | 51 | cout << endl; 52 | } 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /travelling salesman prblm/tsp.cpp: -------------------------------------------------------------------------------- 1 | // CPP program to implement traveling salesman 2 | // problem using naive approach. 3 | #include 4 | using namespace std; 5 | #define V 4 6 | 7 | // implementation of traveling Salesman Problem 8 | int travllingSalesmanProblem(int graph[][V], int s) 9 | { 10 | // store all vertex apart from source vertex 11 | vector vertex; 12 | for (int i = 0; i < V; i++) 13 | if (i != s) 14 | vertex.push_back(i); 15 | 16 | // store minimum weight Hamiltonian Cycle. 17 | int min_path = INT_MAX; 18 | do { 19 | 20 | // store current Path weight(cost) 21 | int current_pathweight = 0; 22 | 23 | // compute current path weight 24 | int k = s; 25 | for (int i = 0; i < vertex.size(); i++) { 26 | current_pathweight += graph[k][vertex[i]]; 27 | k = vertex[i]; 28 | } 29 | current_pathweight += graph[k][s]; 30 | 31 | // update minimum 32 | min_path = min(min_path, current_pathweight); 33 | 34 | } while ( 35 | next_permutation(vertex.begin(), vertex.end())); 36 | 37 | return min_path; 38 | } 39 | 40 | // Driver Code 41 | int main() 42 | { 43 | // matrix representation of graph 44 | int graph[][V] = { { 0, 10, 15, 20 }, 45 | { 10, 0, 35, 25 }, 46 | { 15, 35, 0, 30 }, 47 | { 20, 25, 30, 0 } }; 48 | int s = 0; 49 | cout << travllingSalesmanProblem(graph, s) << endl; 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /Matrix-Transpose/matrix_tranpose.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int a[10][10], transpose[10][10], row, column, i, j; 6 | 7 | cout << "Enter rows and columns of matrix: "; 8 | cin >> row >> column; 9 | 10 | cout << "\nEnter elements of matrix: " << endl; 11 | 12 | // Storing matrix elements 13 | for (int i = 0; i < row; ++i) { 14 | for (int j = 0; j < column; ++j) { 15 | cout << "Enter element a" << i + 1 << j + 1 << ": "; 16 | cin >> a[i][j]; 17 | } 18 | } 19 | 20 | // Printing the a matrix 21 | cout << "\nEntered Matrix: " << endl; 22 | for (int i = 0; i < row; ++i) { 23 | for (int j = 0; j < column; ++j) { 24 | cout << " " << a[i][j]; 25 | if (j == column - 1) 26 | cout << endl << endl; 27 | } 28 | } 29 | 30 | // Computing transpose of the matrix 31 | for (int i = 0; i < row; ++i) 32 | for (int j = 0; j < column; ++j) { 33 | transpose[j][i] = a[i][j]; 34 | } 35 | 36 | // Printing the transpose 37 | cout << "\nTranspose of Matrix: " << endl; 38 | for (int i = 0; i < column; ++i) 39 | for (int j = 0; j < row; ++j) { 40 | cout << " " << transpose[i][j]; 41 | if (j == row - 1) 42 | cout << endl << endl; 43 | } 44 | 45 | return 0; 46 | } 47 | Output 48 | -------------------------------------------------------------------------------- /bintree.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class BinaryTreeNode 6 | { 7 | public: 8 | BinaryTreeNode(int d, BinaryTreeNode *L, BinaryTreeNode *R) : data(d), left(L), right(R) {} 9 | int data; 10 | BinaryTreeNode *left, *right; 11 | }; 12 | 13 | void visit(BinaryTreeNode node) 14 | { 15 | cout << node.data << endl; 16 | } 17 | 18 | void print_BFT(BinaryTreeNode *T) 19 | { 20 | queue q; 21 | q.push(T); 22 | while (q.size()) 23 | { 24 | BinaryTreeNode *cur = q.front(); 25 | visit(*cur); 26 | if (cur->left) 27 | q.push(cur->left); 28 | if (cur->right) 29 | q.push(cur->right); 30 | q.pop(); 31 | } 32 | } 33 | 34 | void test1() 35 | { 36 | BinaryTreeNode *T = new BinaryTreeNode(50, 37 | new BinaryTreeNode(25, 38 | new BinaryTreeNode(10, nullptr, nullptr), new BinaryTreeNode(30, nullptr, nullptr)), 39 | new BinaryTreeNode(75, 40 | new BinaryTreeNode(60, nullptr, nullptr), new BinaryTreeNode(85, nullptr, nullptr))); 41 | 42 | print_BFT(T); 43 | } 44 | 45 | int main() 46 | { 47 | test1(); 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /rock_paper_scissors.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int rockpaperscissor(char you ,char comp) 5 | { 6 | //returns 1 if you win ,-1 if you loose and 0 if draw 7 | if(you==comp) 8 | { 9 | return 0; 10 | } 11 | if(you=='r' && comp=='p') 12 | { 13 | return -1; 14 | } 15 | else if(you=='p' && comp=='r') { 16 | return 1; 17 | } 18 | if(you=='r' && comp=='s'){ 19 | return 1; 20 | } 21 | else if(you=='s' && comp=='r'){ 22 | return -1; 23 | } 24 | if(you=='p' && comp=='s'){ 25 | return -1; 26 | } 27 | else if(you=='s' && comp=='p') { 28 | return 1; 29 | } 30 | } 31 | int main() 32 | { 33 | char you,comp; 34 | int number; 35 | srand(time(0)); 36 | number = rand()%100+1; 37 | if(number<=33){ 38 | comp='r'; 39 | } 40 | else if(number>33 && number <=66){ 41 | comp='p'; 42 | } 43 | else 44 | { 45 | comp='s'; 46 | } 47 | 48 | printf("Enter r for rock , p for paper and s for scissor\n"); 49 | scanf("%c",&you); 50 | int result=rockpaperscissor(you ,comp); 51 | printf("You chose %c and computer chose %c.\n",you,comp); 52 | if(result==0){ 53 | printf("Game draw\n"); 54 | } 55 | else if(result==1){ 56 | printf("You Win\n"); 57 | } 58 | else { 59 | printf("You Lose\n"); 60 | } 61 | return 0; 62 | 63 | } -------------------------------------------------------------------------------- /DSA in CPP/Array Adt/BinarySearch.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | struct Array 4 | { 5 | /* data */ 6 | int A[10]; 7 | int size; 8 | int length; 9 | }; 10 | int BinarySearch(struct Array arr, int key) 11 | { 12 | int l, h, mid; 13 | l = 0; 14 | h = arr.length - 1; 15 | while (l <= h) 16 | { 17 | mid = (l + h) / 2; 18 | /* code */ 19 | if (key == arr.A[mid]) 20 | { 21 | return mid; 22 | } 23 | else if (key < arr.A[mid]) 24 | { 25 | h = mid - 1; 26 | } 27 | else 28 | { 29 | l = mid + 1; 30 | } 31 | } 32 | return -1; 33 | } 34 | int BSearch(int a[],int l, int h, int key){ 35 | int mid; 36 | static int c; 37 | cout<< c< 3 | using namespace std; 4 | 5 | /* A binary tree node has data, pointer to left child 6 | and a pointer to right child */ 7 | class node { 8 | public: 9 | int data; 10 | node* left; 11 | node* right; 12 | }; 13 | 14 | /* Compute the "maxDepth" of a tree -- the number of 15 | nodes along the longest path from the root node 16 | down to the farthest leaf node.*/ 17 | int maxDepth(node* node) 18 | { 19 | if (node == NULL) 20 | return 0; 21 | else { 22 | /* compute the depth of each subtree */ 23 | int lDepth = maxDepth(node->left); 24 | int rDepth = maxDepth(node->right); 25 | 26 | /* use the larger one */ 27 | if (lDepth > rDepth) 28 | return (lDepth + 1); 29 | else 30 | return (rDepth + 1); 31 | } 32 | } 33 | 34 | /* Helper function that allocates a new node with the 35 | given data and NULL left and right pointers. */ 36 | node* newNode(int data) 37 | { 38 | node* Node = new node(); 39 | Node->data = data; 40 | Node->left = NULL; 41 | Node->right = NULL; 42 | 43 | return (Node); 44 | } 45 | 46 | // Driver code 47 | int main() 48 | { 49 | node* root = newNode(1); 50 | 51 | root->left = newNode(2); 52 | root->right = newNode(3); 53 | root->left->left = newNode(4); 54 | root->left->right = newNode(5); 55 | 56 | cout << "Height of tree is " << maxDepth(root); 57 | return 0; 58 | } 59 | 60 | 61 | -------------------------------------------------------------------------------- /DSA in CPP/Array Adt/All_together_in_CPP.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Array{ 4 | int *A; 5 | int size; 6 | int length; 7 | public: 8 | Array(){ 9 | size = 10; 10 | A = new int [size]; 11 | length = 0; 12 | } 13 | Array(int z){ 14 | size =z; 15 | length =0; 16 | A = new int[size]; 17 | } 18 | ~Array(){ 19 | delete []A; 20 | } 21 | void Display(); 22 | void Insert(int index, int x); 23 | int Delete(int index); 24 | }; 25 | void Array:: Display(){ 26 | for(int i= 0; i< length; i++){ 27 | cout << A[i]<< " "<< endl; 28 | } 29 | } 30 | void Array:: Insert(int index, int x){ 31 | if(index>= 0 && index <= length){ 32 | for(int i=length-1; i>=index; i++){ 33 | A[i+1]= A[i]; 34 | } 35 | A[index] = x; 36 | length++; 37 | } 38 | } 39 | int Array:: Delete(int index){ 40 | int x= 0; 41 | if(index >=0 && index< length){ 42 | x = A[index]; 43 | for(int i = index; iInsert(0,5); 54 | arr->Insert(1,6); 55 | arr->Insert(2,4); 56 | arr->Display(); 57 | cout << endl << arr->Delete(1)<< endl; 58 | arr->Display(); 59 | return 0; 60 | } -------------------------------------------------------------------------------- /calculator/calculator.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | float numOne, numTwo, res; 6 | int choice; 7 | do 8 | { 9 | cout<<"1. Addition\n"; 10 | cout<<"2. Subtraction\n"; 11 | cout<<"3. Multiplication\n"; 12 | cout<<"4. Division\n"; 13 | cout<<"5. Exit\n\n"; 14 | cout<<"Enter Your Choice(1-5): "; 15 | cin>>choice; 16 | if(choice>=1 && choice<=4) 17 | { 18 | cout<<"\nEnter any two Numbers: "; 19 | cin>>numOne>>numTwo; 20 | } 21 | switch(choice) 22 | { 23 | case 1: 24 | res = numOne+numTwo; 25 | cout<<"\nResult = "< 3 | using namespace std; 4 | 5 | int partition(int arr[], int start, int end) 6 | { 7 | 8 | int pivot = arr[start]; 9 | 10 | int count = 0; 11 | for (int i = start + 1; i <= end; i++) { 12 | if (arr[i] <= pivot) 13 | count++; 14 | } 15 | 16 | // Giving pivot element its correct position 17 | int pivotIndex = start + count; 18 | swap(arr[pivotIndex], arr[start]); 19 | 20 | // Sorting left and right parts of the pivot element 21 | int i = start, j = end; 22 | 23 | while (i < pivotIndex && j > pivotIndex) { 24 | 25 | while (arr[i] <= pivot) { 26 | i++; 27 | } 28 | 29 | while (arr[j] > pivot) { 30 | j--; 31 | } 32 | 33 | if (i < pivotIndex && j > pivotIndex) { 34 | swap(arr[i++], arr[j--]); 35 | } 36 | } 37 | 38 | return pivotIndex; 39 | } 40 | 41 | void quickSort(int arr[], int start, int end) 42 | { 43 | 44 | // base case 45 | if (start >= end) 46 | return; 47 | 48 | // partitioning the array 49 | int p = partition(arr, start, end); 50 | 51 | // Sorting the left part 52 | quickSort(arr, start, p - 1); 53 | 54 | // Sorting the right part 55 | quickSort(arr, p + 1, end); 56 | } 57 | 58 | int main() 59 | { 60 | 61 | int arr[] = { 9, 3, 4, 2, 1, 8 }; 62 | int n = 6; 63 | 64 | quickSort(arr, 0, n - 1); 65 | 66 | for (int i = 0; i < n; i++) { 67 | cout << arr[i] << " "; 68 | } 69 | 70 | return 0; 71 | } 72 | -------------------------------------------------------------------------------- /some basic data structures in cpp/quicksort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void display(int arr[], int n){ 5 | for(int i=0; ipivot){ 20 | j--; 21 | } 22 | if(i>n; 47 | int arr[n]; 48 | for(int i=0; i>arr[i]; 50 | } 51 | display(arr,n); 52 | quickSort(arr,0, n-1); 53 | display(arr,n); 54 | 55 | return 0; 56 | } --------------------------------------------------------------------------------