diff --git a/C-C++/(0-1)KnapSack.cpp b/C-C++/(0-1)KnapSack.cpp index b5c2382..12103bc 100755 --- a/C-C++/(0-1)KnapSack.cpp +++ b/C-C++/(0-1)KnapSack.cpp @@ -30,20 +30,20 @@ int main() int profit[100], weight[100], w_max, n, i, total; cout << "Enter no of items: "; cin >> n; - + cout << "Enter profits respectively: "; for(i = 0; i < n; i++) cin >> profit[i]; - - printf("Enter the weights respectively: "); + + cout << "Enter the weights respectively: "; for(i = 0; i < n; i++) cin >> weight[i]; - + cout << "Enter max capacity: "; cin >> w_max; - + total = knapsack(weight, profit, n, w_max); cout << "\nTotal profit: " << total << endl; - + return 0; } diff --git a/C-C++/(0-1)KnapSack.exe b/C-C++/(0-1)KnapSack.exe new file mode 100644 index 0000000..c79b2f7 Binary files /dev/null and b/C-C++/(0-1)KnapSack.exe differ diff --git a/C-C++/(0-1)KnapSack.o b/C-C++/(0-1)KnapSack.o new file mode 100644 index 0000000..0e13820 Binary files /dev/null and b/C-C++/(0-1)KnapSack.o differ diff --git a/C-C++/Fibonacci_Search.exe b/C-C++/Fibonacci_Search.exe new file mode 100644 index 0000000..35e4fc4 Binary files /dev/null and b/C-C++/Fibonacci_Search.exe differ diff --git a/C-C++/Fibonacci_Search.o b/C-C++/Fibonacci_Search.o new file mode 100644 index 0000000..8a75562 Binary files /dev/null and b/C-C++/Fibonacci_Search.o differ diff --git a/C-C++/Longest_Palindromic_Subsequence.exe b/C-C++/Longest_Palindromic_Subsequence.exe new file mode 100644 index 0000000..b489f6e Binary files /dev/null and b/C-C++/Longest_Palindromic_Subsequence.exe differ diff --git a/C-C++/Longest_Palindromic_Subsequence.o b/C-C++/Longest_Palindromic_Subsequence.o new file mode 100644 index 0000000..d7d5971 Binary files /dev/null and b/C-C++/Longest_Palindromic_Subsequence.o differ diff --git a/C-C++/activitySelection(DP).cpp b/C-C++/activitySelection(DP).cpp index 20bf0db..901a9ea 100755 --- a/C-C++/activitySelection(DP).cpp +++ b/C-C++/activitySelection(DP).cpp @@ -16,25 +16,27 @@ int activity_dp(activity a[], int i, int finish) { if(i == n) return 0; - + int x = 0, y = 0; - + if(matrix[i][finish] != -1) return matrix[i][finish]; - + x = activity_dp(a, i + 1, finish); - + if(a[i].s >= finish) y = activity_dp(a, i + 1, a[i].f) + 1; - + return matrix[i][finish] = max(x, y); } int main() { + cout<<"enter value of n"; + cin>>n; cout<<"Start time Finish time"<>a[i].f; } memset(matrix, -1, sizeof(matrix)); - + cout << activity_dp(a, 0, 0); - + return 0; -} \ No newline at end of file +} diff --git a/C-C++/activitySelection(DP).exe b/C-C++/activitySelection(DP).exe new file mode 100644 index 0000000..e98f60d Binary files /dev/null and b/C-C++/activitySelection(DP).exe differ diff --git a/C-C++/activitySelection(DP).o b/C-C++/activitySelection(DP).o new file mode 100644 index 0000000..cfd9037 Binary files /dev/null and b/C-C++/activitySelection(DP).o differ diff --git a/C-C++/binarySearch.cpp b/C-C++/binarySearch.cpp index 7262d2a..4053e27 100755 --- a/C-C++/binarySearch.cpp +++ b/C-C++/binarySearch.cpp @@ -23,12 +23,13 @@ int binarySearch(int a[], int x, int l, int r) int main() { int n, x; + cout<<"enter number of elements :"; cin>>n; int a[n]; - +cout<<"enter array elements \n"; for(int i = 0; i < n ; i++) cin>>a[i]; - +cout<<"enter search element :"; cin>>x; int flag = binarySearch(a, x, 0, n-1); @@ -39,4 +40,4 @@ int main() cout<<"Present at pos: "< + +void towers(int, char, char, char); + +int main() +{ + int num; + + printf("Enter the number of disks : "); + scanf("%d", &num); + printf("The sequence of moves involved in the Tower of Hanoi are :\n"); + towers(num, 'A', 'C', 'B'); + return 0; +} +void towers(int num, char frompeg, char topeg, char auxpeg) +{ + if (num == 1) + { + printf("\n Move disk 1 from peg %c to peg %c", frompeg, topeg); + return; + } + towers(num - 1, frompeg, auxpeg, topeg); + printf("\n Move disk %d from peg %c to peg %c", num, frompeg, topeg); + towers(num - 1, auxpeg, topeg, frompeg); +} diff --git a/C-C++/tower of hanoi.exe b/C-C++/tower of hanoi.exe new file mode 100644 index 0000000..93c5194 Binary files /dev/null and b/C-C++/tower of hanoi.exe differ diff --git a/C-C++/tower of hanoi.o b/C-C++/tower of hanoi.o new file mode 100644 index 0000000..dbbc9d0 Binary files /dev/null and b/C-C++/tower of hanoi.o differ