diff --git a/Computer Science - BE/Sem 5/Sem 3/UCS301/Assignment_1/Q1.cpp b/Computer Science - BE/Sem 5/Sem 3/UCS301/Assignment_1/Q1.cpp new file mode 100644 index 0000000..2c4d88c --- /dev/null +++ b/Computer Science - BE/Sem 5/Sem 3/UCS301/Assignment_1/Q1.cpp @@ -0,0 +1,116 @@ +#include +using namespace std; +int main() +{ + int n,x; + int a,b,c; + int pos; + int key; + int array[100]; + int ch = 0; + int flag = 0; + int choice; + while(true) + { + cout<<"--MENU--"<>choice; + switch(choice) + { + + + case 1: + { + cout<<"Enter the size of an array "<>n; + cout<<"Enter the elements of the array "<>array[i]; + } + break; + } + + + + case 2: + { + cout<<"The Elements of the array are "<>a; + cout<<"Enter the position at which element to be inserted "<>b; + for(int i = n; i>=b; i--) + { + array[i+1] = array[i]; + } + array[b] = a; + break; + } + + + case 4: + { + cout<<"Enter the position of the element to be deleted "<>pos; + while(pos-1>key; + for(int i=0;i +using namespace std; +int main() +{ + int n; + cout<<"Enter the size of the array "<>n; + int array[n]; + cout<<"Enter the elements of the array "<>array[i]; + } + for(int i=0; i +using namespace std; +int main() +{ + int n; + cout<<"Enter the size of an array "<>n; + int array[n]; + cout<<"Enter the elements of the array "<>array[i]; + } + cout<<"Array before reversing: "<=0; i--) + { + cout< +using namespace std; +int main() +{ + int n1, n2, n3; + cin>>n1>>n2>>n3; + + int m1[n1][n2]; + int m2[n2][n3]; + + for(int i=0;i>m1[i][j]; + } + } + + for(int i=0;i>m2[i][j]; + } + } + + int ans[n1][n3]; + for(int i=0;i +using namespace std; +int main() +{ + int i,j,m,n; + cout<<"Enter the number of rows "<>n; + cout<<"enter the number of columns "<>m; + int array[n][m]; + for(int i=0;i>array[i][j]; + } + } + for(int i=0;i +using namespace std; +int binarysearch(int n, int array[], int key) +{ + int s =0; + int e=n; + while(s<=e) + { + int mid = (s+e)/2; + + if(array[mid] == key) + { + return mid; + } + else if(array[mid] > key) + { + e = mid - 1; + } + else + { + s = mid + 1; + } + } + return -1; +} +int main() +{ + int n; + cout<<"Enter the size of an array "<>n; + int array[n]; + cout<<"Enter the elements in an array "<>array[i]; + } + int key; + cout<<"Enter the key to be searched "<>key; + cout< +using namespace std; +int main() +{ + int array[7] = {64,34,25,12,22,11,90}; + int counter = 1; + while(counter < 7) + { + for(int i=0;i<7-counter;i++) + { + if(array[i]>array[i+1]) + { + int temp; + temp = array[i]; + array[i] = array[i+1]; + array[i+1] = temp; + } + } + counter++; + } + for(int i=0;i<7;i++) + { + cout< +using namespace std; +int main() +{ + int n; + cout<<"Enter the size of an array "<>n; + int array[n]; + cout<<"Enter the elements of the array "<>array[i]; + } + for(int i=0;i +using namespace std; +int main() { + int n; + cout<<"Enter the size of the matrix row "<>n; + int array[n]; + cout<<"Enter the row majors now "<>array[i]; + } + cout<<"The Diagnol Matrix is "< +using namespace std; +int main() { + int n,k=0; + cout<<"Enter the diagnols "<>n; + int array[n]; + cout<<"Enter the elements of the diagnol "<>array[i]; + } + cout<<"The tridiagnol matrix is: "< +using namespace std; +int main () { + int n; + cout<<"Enter the size of the array "<>n; + int array[n][n]; + cout<<"Enter the elements of the array "<>array[i][j]; + } + } + } + cout<<"The Lower triangular matrix is "< +using namespace std; +int main() { + int n; + cout<<"Enter the size of the array "<>n; + int array[n][n]; + cout<<"Enter the no of elemets of the array "<j) { + array[i][j] = 0; + } + else { + cin>>array[i][j]; + } + } + } + cout<<"The Upper triangular matrix is "< +using namespace std; +int main() { + int n,m,sum = 0; + cout<<"Enter the no of rows of the matrix "<>n; + cout<<"Enter the no of columns of the matrix "<>m; + int array[n][m]; + cout<<"Enter the elements of the array "<>array[i][j]; + } + } + for(int i=0; i>n; + cout<<"Enter the no of columns in the 2-D array "<>m; + int array[n][m]; + cout<<"Enter the elements of the 2-D array: "<>array[i][j]; + } + } + + for(int i=0; i array[i][j]) { + + row_min = array[i][j]; + col_index = j; + } + } + + for(k=0; k +using namespace std; +int main(){ + int m,n; + cout<<"Enter the number of rows "<>m; + cout<<"Enter the number of columns "<>n; + int array[n][m]; + cout<<"Enter the elements of the array "<>array[i][j]; + } + } + // spiral order print + + int row_start = 0, row_end = n-1, column_start = 0, column_end = m-1; + while(row_start <= row_end && column_start<= column_end) { + + // for row start + for(int col = column_start; col<=column_end; col++) { + cout<< array[row_start][col]<<" "; + } + + row_start++; + + // for column end + for(int row = row_start; row<=row_end; row++) { + cout<< array[row][column_end]<<" "; + } + column_end--; + + // for row end + for(int col= column_end; col>=column_start; col--) { + cout<< array[row_end][col]<<" "; + } + row_end--; + + //for column start + for(int row=row_end; row>=row_start; row--) { + cout<< array[row][column_start]<<" "; + } + column_start++; + } + return 0; +} \ No newline at end of file diff --git a/Computer Science - BE/Sem 5/Sem 3/UCS301/Assignment_1a/assignment_e.cpp b/Computer Science - BE/Sem 5/Sem 3/UCS301/Assignment_1a/assignment_e.cpp new file mode 100644 index 0000000..856dd20 --- /dev/null +++ b/Computer Science - BE/Sem 5/Sem 3/UCS301/Assignment_1a/assignment_e.cpp @@ -0,0 +1,44 @@ +#include +using namespace std; +int main() { + int n,m; + bool flag = false; + cout<<"Enter the no of rows in the array "<>n; + cout<<"Enter the no of columns in the array "<>m; + int array1[n][m]; + int array2[n][m]; + cout<<"Enter the elements of the array "<>array1[i][j]; + } + } + for(int i=0; i +using namespace std; +class Node +{ + public: + int data; + Node *next; + + Node(int data) { + this -> data = data; + next = NULL; + } +}; + +Node* takeInput_better() { + cout<<"Enter the data of your inked List: "<>data; + Node *head = NULL; + Node *tail = NULL; + while(data!= -1){ + Node *newNode = new Node(data); + if(head == NULL){ + head = newNode; + tail = newNode; + } + else { + tail -> next = newNode; + tail = tail -> next; + } + cin>>data; + } + return head; +} +Node* begininsert(Node* head, int data) { + + Node* newNode = new Node(data); + newNode -> next = head; + head = newNode; + return head; +} +Node* lastinsertion(Node* head, int data) { + Node* temp = head; + Node* newNode = new Node(data); + while(temp -> next != NULL) { + temp = temp -> next; + } + temp -> next = newNode; + return head; +} +Node* insertionbetween(Node* head, int data, int i){ + Node* temp = head; + Node* newNode = new Node(data); + int count = 0; + while(count < i-1) { + temp = temp -> next; + count++; + } + newNode -> next = temp -> next; + temp -> next = newNode; + return head; +} +Node* deletefromBegin(Node* head) { + head = head -> next; + return head; +} +Node* deleteFromEnd(Node* head) { + Node* temp = head; + while(temp -> next -> next != NULL) { + temp = temp -> next; + } + temp -> next = NULL; + return head; +} +Node* deleteSpecific(Node* head, int i) { + + Node* temp = head; + int count = 0; + while(count < i-1 && temp!= NULL) { + temp = temp -> next; + count ++; + } + if(temp != NULL){ + Node* a = temp -> next; + Node* b = a -> next; + temp -> next = b; + } + return head; +} +Node* searchindex(Node* head, int x) { + Node* temp = head; + int count = 0; + while(temp != NULL) { + if(temp -> data == x) { + cout<<"The element is found at index: "< next; + count++; + } + } +} +void print(Node *head){ + Node *temp = head; + + while(temp!=NULL){ + cout<< temp -> data <<" "; + temp = temp -> next; + } + cout<>ch; + switch(ch) { + case 'a': { + int data; + cout<<"Enter the data you want to insert in beginning: "<>data; + head = begininsert(head, data); + break; + } + case 'b': { + int data; + cout<<"Enter the data you want to insert at the end: "<>data; + head = lastinsertion(head, data); + break; + } + case 'c' : { + int data, i; + cout<<"Enter the data and the index: "<>data>>i; + head = insertionbetween(head, data, i); + break; + } + case 'd' : { + head = deletefromBegin(head); + break; + } + case 'e' : { + head = deleteFromEnd(head); + break; + } + case 'f' : { + int i; + cout<<"Enter the index you want to get deleted: "<>i; + head = deleteSpecific(head, i); + break; + } + case 'g' : { + int x; + cout<<"Enter the key you want to search in linked list: "<>x; + head = searchindex(head, x); + break; + } + case 'h' : { + print(head); + break; + } + default: + cout<<"You entered wrong choice "<>m; +} +return 0; +} \ No newline at end of file diff --git a/Computer Science - BE/Sem 5/Sem 3/UCS301/Assignment_2/Q2.cpp b/Computer Science - BE/Sem 5/Sem 3/UCS301/Assignment_2/Q2.cpp new file mode 100644 index 0000000..589aa35 --- /dev/null +++ b/Computer Science - BE/Sem 5/Sem 3/UCS301/Assignment_2/Q2.cpp @@ -0,0 +1,75 @@ +#include +using namespace std; + +class Node +{ + public: + int data; + Node *next; + + Node(int data) { + this -> data = data; + next = NULL; + } +}; + +Node* takeInput_better() { + cout<<"Enter the data of your inked List: "<>data; + Node *head = NULL; + Node *tail = NULL; + while(data!= -1){ + Node *newNode = new Node(data); + if(head == NULL){ + head = newNode; + tail = newNode; + } + else { + tail -> next = newNode; + tail = tail -> next; + } + cin>>data; + } + return head; +} + +Node* repeat(Node* head, int x) { + + Node* temp = head; + while(head -> data == x) { + head = head -> next; + } + while(temp -> next != NULL) { + + if(temp -> next -> data == x) { + temp -> next = temp -> next -> next; + } + else { + temp = temp -> next; + } + } + return head; +} + +void print(Node *head){ + Node *temp = head; + + while(temp!=NULL){ + cout<< temp -> data <<" "; + temp = temp -> next; + } + cout<>x; + head = repeat(head, x); + cout<<"The updated linked list is: "< +using namespace std; + +class Node { + + public: + int data; + Node* next; + + Node(int data) { + this -> data = data; + next = NULL; + } +}; + +Node* takeinput_better() { + cout<<"Enter the data in your linked list: "<>data; + Node* head = NULL; + Node* tail = NULL; + while(data!= -1) { + + Node* newNode = new Node(data); + if(head == NULL) { + head = newNode; + tail = newNode; + } + else { + tail -> next = newNode; + tail = tail -> next; + } + cin>>data; + } + return head; +} + +int length(Node* head) { + Node* temp = head; + int length = 0; + while(temp != NULL) { + temp = temp -> next; + length++; + } + temp = head; + int mid = (length -1)/2; + for(int i=0; i next; + } + int curl = temp -> data; + return curl; +} + +void print(Node* head) { + + Node* temp = head; + while(temp != NULL) { + cout<< temp -> data <<" "; + temp = temp -> next; + } + cout< +using namespace std; +class Node +{ + public: + int data; + Node *next; + + Node(int data) { + this -> data = data; + next = NULL; + } +}; + +Node* takeInput_better() { + cout<<"Enter the data of your inked List: "<>data; + Node *head = NULL; + Node *tail = NULL; + while(data!= -1){ + Node *newNode = new Node(data); + if(head == NULL){ + head = newNode; + tail = newNode; + } + else { + tail -> next = newNode; + tail = tail -> next; + } + cin>>data; + } + return head; +} + +Node* reverse(Node* head) { + if(head == NULL || head -> next == NULL) { + return head; + } + Node* smalloutput = reverse(head -> next); + Node* temp = smalloutput; + while(temp -> next !=NULL) { + temp = temp -> next; + } + temp -> next = head; + head -> next = NULL; + return smalloutput; +} + +void print(Node *head){ + Node *temp = head; + + while(temp!=NULL){ + cout<< temp -> data <<" "; + temp = temp -> next; + } + cout< +#include +using namespace std; +template +class stackusingArray { + private: + T *data; + int nextIndex; + int capacity; + + public: + stackusingArray() { + data = new T[4]; + nextIndex = 0; + capacity = 4; + } + + // return the no of elements present in my stack + int size () { + return nextIndex; + } + + bool isEmpty() { + if(nextIndex == 0) { + return true; + } + else { + return false; + } + } + //insert element + + void push(T element) { + if(nextIndex == capacity) { + T *newData = new T[2 * capacity]; + for(int i=0; i s; + int n; + int choice; + cout<<"Enter the optin from the given menu "<>choice; + switch(choice) + { + case 1: { + cout<<"Enter the element you want to push in the given stack "<>n; + s.push(n); + break; + } + case 2: { + cout<<"The top element of the stack is: "<< s.peek() < +#include +#include +using namespace std; + +void reverseString(string s) { + + stack str; + for(int i=0; i=0; j--) { + reverseWord += word[j]; + } + str.push(reverseWord); + } + while(!str.empty()) { + cout< +#include +#include +using namespace std; + +bool isValid(string S) { + + stack st; + bool ans = true; + for(int i=0; i>str; + if(isValid(str)) { + cout<< "The paranthesis expression are balanced "<< endl; + } + else { + cout<< "The paranthesis expression are unbalanced "< +// #include +// #include +// using namespace std; + +// bool checkValidString(string s) { +// stack open; +// stack star; +// for(int i=0; i +#include +#include +#include +using namespace std; + +int prec(char c) { + + if(c == '^') { + return 3; + } + else if(c == '*' || c=='/') { + return 2; + } + else if(c == '+' || c == '-') { + return 1; + } + else { + return -1; + } +} + +string infixtoPostfix(string s) { + stack st; + string res; + + for(int i=0; i='a' && s[i]<='z') || (s[i]>='A' && s[i]<='Z')) { + res = res + s[i]; + } + else if(s[i] == '(') { + st.push(s[i]); + } + else if(s[i] == ')') { + while(!st.empty() && st.top() != '(') { + res = res + st.top(); + st.pop(); + } + if(!st.empty()) { + st.pop(); + } + } + else { + while(!st.empty() && prec(st.top())>prec(s[i])) { + res = res + st.top(); + st.pop(); + } + st.push(s[i]); + } + } + while(!st.empty()) { + res = res + st.top(); + st.pop(); + } + return res; +} + +int main() { + string s; + cout<<"Enter the string in infix "<>s; + cout<<"The postfix string is "< +using namespace std; + +int postfixEvaluation(string s) { + stack st; + for(int i=0; i='0' && s[i]<='9') { + st.push(s[i] - '0'); + } + else { + int op2 = st.top(); + st.pop(); + int op1 = st.top(); + st.pop(); + + switch (s[i]) + { + case '+': + st.push(op1+op2); + break; + case '-': + st.push(op1-op2); + break; + case '*': + st.push(op1*op2); + break; + case '/': + st.push(op1/op2); + break; + case '^': + st.push(pow(op1,op2)); + break; + } + } + } + return st.top(); +} +int main() { + string s; + cout<<"Enter the string "<