├── 16-05-23 [Lab Performance ].c ├── 3 Data part.cpp ├── ALL link list [ Node insert , Node Delete].c ├── AllLink List.cpp ├── Array Lab 2.cpp ├── Basic 20-09-2023 ├── Stack.c └── stack.cpp ├── Binary Tree └── Binary tree with linklist implement.c ├── Delete Node all node.c ├── Fall 2020 MID.c ├── Lab 20-09-2023 ├── Queue.c └── Stack.c ├── Lab 20-10-23 ├── Queue.c └── Stack code.c ├── Lab Tast [ 30 └── 08 │ └── 2023 ].c ├── Lab2.cpp ├── Link List File ├── ALL link list [ Node inset (last and First ) ].c ├── Add data middle.c ├── Link List create,delete (condition ).c ├── Project Lab 09-08-2023.c ├── Spring 2023 .c ├── link list User input Node.cpp ├── linkList_Last Node insert.c └── user Input linkList.c ├── LinkList.c ├── LinkList.cpp ├── QuestionSolve 2022.cpp ├── Queue ├── Queue Basic Function.c └── Queue.c ├── Spring 2023 .c ├── Spring 2023.cpp ├── Spring Mid 2023.c ├── Stack All Code ├── Spring 2022.c ├── Stack Full system.cpp ├── Stack full function.c ├── Stack with LinkList.c └── User input stack with Linklist.c ├── Summer 2020 Mid.c ├── Using Malloc and Data entry Student.cpp └── discoverTheWeb.c /16-05-23 [Lab Performance ].c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct node { 5 | int data; 6 | struct node *next; 7 | } *head; 8 | typedef struct node node; 9 | void createList(int n); 10 | 11 | void createList(int n) { 12 | node *newnode, *temp; 13 | head = (node*)malloc(sizeof(node)); 14 | printf("Enter the data for the first node: "); 15 | scanf("%d", &head->data); 16 | head->next = head; 17 | temp = head; 18 | 19 | for (int i = 2; i <= n; i++) 20 | { 21 | newnode = (node*)malloc(sizeof(node)); 22 | printf("Enter data for node %d : ", i); 23 | scanf("%d",&newnode->data); 24 | newnode->next = head; 25 | temp->next = newnode; 26 | temp = temp->next; 27 | } 28 | } 29 | 30 | 31 | void insert_First() 32 | { 33 | int newData; 34 | printf("\nEnter data at the First node: "); 35 | scanf("%d", &newData); 36 | 37 | node *newNode = (node*)malloc(sizeof(node)); 38 | newNode->data =newData; 39 | newNode->next = head; 40 | 41 | node *temp = head; 42 | while (temp->next != head) 43 | { 44 | temp = temp->next; 45 | } 46 | temp->next = newNode; 47 | head = newNode; 48 | } 49 | 50 | void insertAtEnd(int data) 51 | { 52 | node *newNode = (node*)malloc(sizeof(node)); 53 | newNode->data = data; 54 | newNode->next = head; 55 | 56 | node *temp = head; 57 | while (temp->next != head) 58 | { 59 | temp = temp->next; 60 | } 61 | temp->next = newNode; 62 | } 63 | 64 | void displayNode() { 65 | if(head == NULL) 66 | { 67 | printf("Linklist NULL !!! "); 68 | } 69 | 70 | else 71 | { 72 | struct node* temp = head; 73 | printf("\n"); 74 | do{ 75 | printf("Current Address: %p DATA: %d \t", temp, temp->data); 76 | printf("\nNext Address: %p ",temp->next); 77 | temp = temp->next; 78 | } 79 | while(temp != head); 80 | printf("\n"); 81 | } 82 | } 83 | 84 | int main() { 85 | int n; 86 | printf("Input the number of nodes: "); 87 | scanf("%d", &n); 88 | createList(n); 89 | displayNode(); 90 | 91 | 92 | insert_First(); 93 | 94 | printf("\nData after inserting at the First !!\n"); 95 | displayNode(); 96 | 97 | int newData; 98 | printf("\nEnter data end of the Node : "); 99 | scanf("%d", &newData); 100 | insertAtEnd(newData); 101 | 102 | printf("\nData after inserting at the end !!!\n"); 103 | displayNode(); 104 | 105 | return 0; 106 | } 107 | -------------------------------------------------------------------------------- /3 Data part.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | struct node 7 | { 8 | int x ; 9 | float y; 10 | char z; 11 | 12 | struct node *next; // self refefarencial pointer creation 13 | }; 14 | typedef struct node head; 15 | 16 | int main() 17 | { 18 | head *node1 , * node2; 19 | node1 =(head*)malloc(sizeof(head)); // Memory Address create 20 | node2 =(head*)malloc(sizeof(head)); // Memory Address create 21 | node1-> x =6; 22 | node1->y =64.99; 23 | node1->z = 'Aim'; 24 | node1->next=node2; 25 | 26 | node2-> x = 9; 27 | node2->y =3.19; 28 | node2->z = 'Blim'; 29 | node2->next=NULL; 30 | 31 | cout <<"Print value "<< node1->x << endl; 32 | cout <<"Print value "<< node1->y << endl; 33 | cout <<"Print value "<< node1->z << endl<x << endl; 36 | cout <<"Print value "<< node2->y << endl; 37 | cout <<"Print value "<< node2->z << endl; 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /ALL link list [ Node insert , Node Delete].c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct node { 5 | int data; 6 | struct node *next; 7 | }; 8 | 9 | typedef struct node node; 10 | 11 | node *head; 12 | void createnode(int n); 13 | void display(); 14 | void insert_beg(); 15 | void insert_end(); 16 | void insert_middle(int position); 17 | void delete_first(); 18 | void delete_middle(int position); 19 | void delete_last(); 20 | 21 | void createnode(int n) { 22 | node *newnode, *temp; 23 | head = (node *)malloc(sizeof(node)); 24 | 25 | head->next = NULL; 26 | printf("\nEnter data for Node 1 : "); 27 | scanf("%d", &head->data); 28 | temp = head; 29 | for (int i = 2; i <= n; i++) { 30 | newnode = (node *)malloc(sizeof(node)); 31 | printf("\nEnter data for Node %d : ", i); 32 | scanf("%d", &newnode->data); 33 | newnode->next = NULL; 34 | temp->next = newnode; 35 | temp = temp->next; 36 | } 37 | } 38 | 39 | void insert_beg() { 40 | node *newnode; 41 | newnode = (node *)malloc(sizeof(node)); 42 | printf("\nEnter data for beginning node: "); 43 | scanf("%d", &newnode->data); 44 | newnode->next = head; 45 | head = newnode; 46 | } 47 | 48 | void insert_middle(int position) { 49 | 50 | node *newnode, *temp; 51 | temp = head; 52 | for (int i = 1; i < position - 1; i++) { 53 | temp = temp->next; 54 | } 55 | newnode = (node *)malloc(sizeof(node)); 56 | printf("Enter data at MIDDLE position: "); 57 | scanf("%d", &newnode->data); 58 | newnode->next = temp->next; 59 | temp->next = newnode; 60 | } 61 | 62 | void insert_end() { 63 | node *temp, *newnode; 64 | newnode = (node *)malloc(sizeof(node)); 65 | printf("\nEnter data for last node: "); 66 | scanf("%d", &newnode->data); 67 | temp = head; 68 | while (temp->next != NULL) { 69 | temp = temp->next; 70 | } 71 | temp->next = newnode; 72 | newnode->next = NULL; 73 | } 74 | 75 | void delete_first() { 76 | node *temp; 77 | temp = head; 78 | head = temp->next; 79 | free(temp); 80 | } 81 | 82 | void delete_middle(int position) { 83 | node *current, *temp, *prev; 84 | temp = head; 85 | for (int i = 1; i < position; i++) { 86 | prev = temp; 87 | current = temp->next; 88 | temp = temp->next; 89 | } 90 | prev->next = current->next; 91 | free(current); 92 | } 93 | 94 | void delete_last() { 95 | node *temp, *prev; 96 | temp = head; 97 | prev = NULL; 98 | while (temp->next != NULL) { 99 | prev = temp; 100 | temp = temp->next; 101 | } 102 | prev->next = NULL; 103 | 104 | free(temp); 105 | } 106 | 107 | void display() { 108 | node *temp; 109 | temp = head; 110 | printf("\nYou have Successfully Print the following linked list :\n"); 111 | while (temp != NULL) { 112 | printf("%d -> ", temp->data); 113 | temp = temp->next; 114 | } 115 | printf("NULL\n"); 116 | } 117 | 118 | int main() { 119 | int n; 120 | printf("\nEnter total number of nodes: "); 121 | scanf("%d", &n); 122 | createnode(n); 123 | display(); 124 | 125 | printf("\nInserting new node at the beginning...\n"); 126 | insert_beg(); 127 | display(); 128 | 129 | int pos; 130 | printf("\nInserting the value at the MIDDLE position......\n"); 131 | printf("Enter the position number: "); 132 | scanf("%d", &pos); 133 | insert_middle(pos); 134 | display(); 135 | 136 | printf("\nInserting new node at the end...\n"); 137 | insert_end(); 138 | display(); 139 | 140 | // Delete Node First 141 | printf("\nDelete node First Data !!!\n"); 142 | delete_first(); 143 | display(); 144 | 145 | // Delete Middle / Any Node 146 | printf("\nDeleting a node from the middle...\n"); 147 | printf("Enter the position number to delete : "); 148 | scanf("%d", &pos); 149 | delete_middle(pos); 150 | display(); 151 | 152 | // Delete Last Node 153 | printf("\nDelete node Last Data !!!\n"); 154 | delete_last(); 155 | display(); 156 | 157 | return 0; 158 | } 159 | 160 | 161 | -------------------------------------------------------------------------------- /AllLink List.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | using namespace std; 4 | 5 | struct Node { 6 | int data; 7 | Node* next; 8 | } ; 9 | 10 | Node* head = nullptr; 11 | 12 | void createNode(int n) { 13 | Node* newNode, * temp; 14 | int i; 15 | head = new Node; 16 | head->next = nullptr; 17 | cout << "\nEnter data for Node 1: "; 18 | cin >> head->data; 19 | temp = head; 20 | for (i = 2; i <= n; i++) { 21 | newNode = new Node; 22 | cout << "\nEnter data for Node " << i << ": "; 23 | cin >> newNode->data; 24 | newNode->next = nullptr; 25 | temp->next = newNode; 26 | temp = temp->next; 27 | } 28 | } 29 | 30 | void insertBeginning() { 31 | Node* newNode = new Node; 32 | cout << "\nEnter data for beginning node: "; 33 | cin >> newNode->data; 34 | newNode->next = head; 35 | head = newNode; 36 | } 37 | 38 | void insertEnd() { 39 | Node* temp, * newNode; 40 | newNode = new Node; 41 | cout << "\nEnter data for last node: "; 42 | cin >> newNode->data; 43 | temp = head; 44 | while (temp->next != nullptr) { 45 | temp = temp->next; 46 | } 47 | temp->next = newNode; 48 | newNode->next = nullptr; 49 | } 50 | 51 | void display() { 52 | Node* temp; 53 | temp = head; 54 | cout << "\nYou have Successfully created the following linked list: \n"; 55 | while (temp != nullptr) { 56 | cout << temp->data << "-> "; 57 | temp = temp->next; 58 | } 59 | cout << "nullptr" << endl; 60 | } 61 | 62 | void deleteFirst() { 63 | if (head == nullptr) { 64 | cout << "List is empty. Nothing to delete." << endl; 65 | return; 66 | } 67 | Node* temp; 68 | temp = head; 69 | head = temp->next; 70 | delete temp; 71 | } 72 | 73 | void deleteMiddle() { 74 | if (head == nullptr) { 75 | cout << "List is empty. Nothing to delete." << endl; 76 | return; 77 | } 78 | int pos, i = 1; 79 | Node* current, * temp, * prev; 80 | cout << "\nEnter the position of the node you want to delete: "; 81 | cin >> pos; 82 | temp = head; 83 | for (i = 1; i < pos; i++) { 84 | prev = temp; 85 | current = temp->next; 86 | temp = temp->next; 87 | } 88 | prev->next = current->next; 89 | delete current; 90 | } 91 | 92 | void deleteLast() { 93 | if (head == nullptr) { 94 | cout << "List is empty. Nothing to delete." << endl; 95 | return; 96 | } 97 | Node* temp, * prev; 98 | temp = head; 99 | while (temp->next != nullptr) { 100 | prev = temp; 101 | temp = temp->next; 102 | } 103 | prev->next = nullptr; 104 | delete temp; 105 | } 106 | 107 | int main() { 108 | int n; 109 | cout << "\nEnter total number of nodes: "; 110 | cin >> n; 111 | createNode(n); 112 | display(); 113 | cout << "\nInserting new node at the beginning...\n"; 114 | insertBeginning(); 115 | display(); 116 | cout << "\nInserting new node at the end...\n"; 117 | insertEnd(); 118 | display(); 119 | cout << "\nDeleting the first node...\n"; 120 | deleteFirst(); 121 | display(); 122 | cout << "\nDeleting a middle node...\n"; 123 | deleteMiddle(); 124 | display(); 125 | cout << "\nDeleting the last node...\n"; 126 | deleteLast(); 127 | display(); 128 | return 0; 129 | } 130 | 131 | -------------------------------------------------------------------------------- /Array Lab 2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | //// Array//// 7 | int x[5] ={10,20,30,40,50}; 8 | int *p; 9 | 10 | for(int i=0 ; i< 5; i++) 11 | { 12 | // cout << &x[i] << endl; 13 | cout <<"Address ="<< i<<" "<<&x[i] << endl; 14 | } 15 | p = x; 16 | cout <<"**** Second Address ****"< 2 | #define CAPACITY 3 3 | int stack[CAPACITY]; 4 | int top = -1; 5 | 6 | void push(int x) // Added the stack Value 7 | { 8 | if( top < CAPACITY -1 ) 9 | { 10 | top = top + 1; 11 | stack[top] = x; 12 | printf("Successfully added in stack : %d\n",x); 13 | } 14 | else 15 | { 16 | printf("Capacity overflow...........\n"); 17 | } 18 | } 19 | 20 | int pop() // Remove the stack value 21 | { 22 | if(top >= 0) 23 | { 24 | int value = stack[top]; 25 | top = top -1; 26 | return value; 27 | } 28 | printf("Stack is empty....................\n"); 29 | } 30 | 31 | int peek() //Only see stack function Value 32 | { 33 | if( top >= 0) 34 | { 35 | return stack[top]; 36 | } 37 | printf("Stack is Empty .............\n"); 38 | return -1; 39 | 40 | } 41 | 42 | int main() 43 | { 44 | printf("My stack c............\n"); 45 | peek(); 46 | push(10); 47 | push(20); 48 | push(30); 49 | printf("\nRemove the stack value : %d\n",pop()); 50 | push(40); 51 | printf("\nTop of stack value : %d \n",peek()); 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /Basic 20-09-2023/stack.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define CAPACITY 3 3 | int stack[CAPACITY]; 4 | using namespace std; 5 | int top = -1; 6 | void push(int x) 7 | { 8 | if( top < CAPACITY-1) 9 | { 10 | top = top +1; 11 | stack[top] =x; 12 | cout <<"Stack value added : " <= 0 ) 22 | { 23 | int value = stack[top]; 24 | top = top -1; 25 | return value; 26 | } 27 | cout <<"Stack has no value to remove .............."<= 0 ) 35 | { 36 | return stack[top]; 37 | } 38 | cout << "Stack has no Data......" << endl; 39 | return -1; 40 | } 41 | 42 | int main() 43 | { 44 | cout <<"My Stack C++................!!!!"< 2 | #include 3 | 4 | struct Node { 5 | int data; 6 | struct Node* left; 7 | struct Node* right; 8 | }; 9 | 10 | struct Node* newNode(int data) { 11 | struct Node* node = (struct Node*) malloc(sizeof(struct Node)); 12 | node->data = data; 13 | node->left = NULL; 14 | node->right = NULL; 15 | return node; 16 | } 17 | 18 | void print_In_Order(struct Node* node) { 19 | if (node == NULL) return; 20 | print_In_Order(node->left); 21 | printf("%d ", node->data); 22 | print_In_Order(node->right); 23 | } 24 | 25 | int main() 26 | { 27 | struct Node* root = newNode(10); 28 | root->left = newNode(20); 29 | root->right = newNode(30); 30 | root->left->left = newNode(40); 31 | root->left->right = newNode(50); 32 | printf("Traversal of a binary tree: \n"); 33 | print_In_Order(root); 34 | return 0; 35 | } 36 | 37 | -------------------------------------------------------------------------------- /Delete Node all node.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct node 5 | { 6 | int data; 7 | struct node *next; 8 | }; 9 | typedef struct node node; 10 | node *head; 11 | void createnode(int n); 12 | void display(); 13 | void delete_first(); 14 | void delete_middle(); 15 | void delete_last(); 16 | //void insert_beg(); 17 | int main() 18 | { 19 | int n; 20 | printf("\n Enter total number of node: "); 21 | scanf("%d",&n); 22 | createnode(n); 23 | display(); 24 | //printf("\n Inserting new node at beginning...\n"); 25 | //insert_beg(); 26 | // display(); 27 | printf("\n AFTER DELETING THE LAST NODE...."); 28 | //delete_first(); 29 | delete_last(); 30 | display(); 31 | return 0; 32 | } 33 | 34 | void createnode(int n) 35 | { 36 | node *newnode, *temp; 37 | int i; 38 | head= (node*)malloc(sizeof(node)); 39 | head->next=NULL; 40 | printf("\n Enter data for Node 1: "); 41 | scanf("%d", &head->data); 42 | temp=head; 43 | for(i=2;i<=n;i++) 44 | { 45 | newnode= (node*)malloc(sizeof(node)); 46 | printf("\n Enter data for Node %d: ",i); 47 | scanf("%d", &newnode->data); 48 | newnode->next=NULL; 49 | temp->next=newnode; 50 | temp=temp->next; 51 | } 52 | } 53 | 54 | void insert_beg() 55 | { 56 | node *newnode; 57 | 58 | newnode= (node*)malloc(sizeof(node)); 59 | printf("\n Enter data for beginning node: "); 60 | scanf("%d", &newnode->data); 61 | newnode->next=head; 62 | head=newnode; 63 | } 64 | void delete_first() 65 | { 66 | node *temp; 67 | temp=head; 68 | head=temp->next; 69 | free(temp); 70 | } 71 | 72 | void delete_middle() 73 | { 74 | int pos,i; 75 | node *current, *temp, *prev; 76 | printf("\n Enter the position of the node you want to delete..\n"); 77 | scanf("%d",&pos); 78 | temp=head; 79 | for(i=1;inext; 83 | temp=temp->next; 84 | } 85 | prev->next=current->next; 86 | free(current); 87 | } 88 | void delete_last() 89 | { 90 | node *temp, *prev; 91 | temp=head; 92 | while(temp->next!=NULL) 93 | { 94 | prev=temp; 95 | temp=temp->next; 96 | } 97 | prev->next=NULL; 98 | free(temp); 99 | } 100 | void display() 101 | { 102 | node *temp; 103 | temp=head; 104 | printf("\n You have Successfully created the following linkedlist: \n"); 105 | while(temp!=NULL) 106 | { 107 | printf("%d-> ",temp->data); 108 | temp=temp->next; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /Fall 2020 MID.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct node{ 5 | int data; 6 | struct node *next; 7 | 8 | }*head; 9 | typedef struct node nodal; 10 | 11 | void createnode (int n); 12 | void displayList(); 13 | int main() 14 | { 15 | int n; 16 | printf("Enter number of nodes: "); 17 | scanf("%d", &n); 18 | 19 | createnode(n); 20 | printf("\nLinked list created successfully!\n"); 21 | 22 | printf("The linked list elements are: "); 23 | displayList(); 24 | return 0; 25 | } 26 | 27 | void createnode(int n) 28 | { 29 | head = (nodal*)malloc(sizeof(nodal)); 30 | 31 | 32 | printf("Enter data for node 1: "); 33 | scanf("%d", &head->data); 34 | 35 | head->next = NULL; 36 | 37 | int i; 38 | nodal *newnode, *temp; 39 | temp = head; 40 | 41 | for (i = 2; i <= n; i++) 42 | { 43 | newnode = (nodal*)malloc(sizeof(nodal)); 44 | 45 | printf("Enter data for node %d: ", i); 46 | scanf("%d", &newnode->data); 47 | 48 | newnode->next = NULL; 49 | temp->next = newnode; 50 | temp = temp->next; 51 | } 52 | } 53 | 54 | void displayList() 55 | { 56 | nodal *current = head; 57 | while (current != NULL) { 58 | printf("%d-> ", current->data); 59 | current = current->next; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Lab 20-09-2023/Queue.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sajjadjim/Data_Structure/3c57b33dcd06bc85371aac5fdf17cffc011912d7/Lab 20-09-2023/Queue.c -------------------------------------------------------------------------------- /Lab 20-09-2023/Stack.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sajjadjim/Data_Structure/3c57b33dcd06bc85371aac5fdf17cffc011912d7/Lab 20-09-2023/Stack.c -------------------------------------------------------------------------------- /Lab 20-10-23/Queue.c: -------------------------------------------------------------------------------- 1 | #include 2 | int top=-1; 3 | int stack[]; 4 | 5 | void push(int maxstack) 6 | { 7 | int x; 8 | for(int i=1; i<=maxstack; i++) 9 | { 10 | if(top==maxstack-1) 11 | { 12 | printf("Overflow."); 13 | } 14 | else 15 | { 16 | printf("Enter data for stack:%d\n",i); 17 | scanf("%d",&x); 18 | top++; 19 | stack[top]=x; 20 | } 21 | } 22 | 23 | } 24 | void pop(int maxstack) 25 | { 26 | for(int i=0; i",stack[i]); 45 | } 46 | } 47 | int main() 48 | { 49 | int maxstack; 50 | printf("Enter how many data in Stack: "); 51 | scanf("%d",&maxstack); 52 | push(maxstack); 53 | 54 | printf("\n Stack:"); 55 | display(); 56 | 57 | printf("\n\n After pop data from stack:"); 58 | pop(maxstack); 59 | 60 | printf("\n\n After pop element from the stack: "); 61 | display(); 62 | 63 | } 64 | -------------------------------------------------------------------------------- /Lab 20-10-23/Stack code.c: -------------------------------------------------------------------------------- 1 | #include 2 | int top=-1; 3 | int stack[]; 4 | 5 | void push(int maxstack) 6 | { 7 | int x; 8 | for(int i=1; i<=maxstack; i++) 9 | { 10 | if(top==maxstack-1) 11 | { 12 | printf("Stack Overflow."); 13 | } 14 | else 15 | { 16 | printf("Enter data for stack %d : ",i); 17 | scanf("%d",&x); 18 | top++; 19 | stack[top]=x; 20 | } 21 | } 22 | 23 | } 24 | void pop(int maxstack) 25 | { 26 | for(int i=0; i",stack[i]); 45 | } 46 | } 47 | int main() 48 | { 49 | int maxstack; 50 | printf("Enter how many data in Stack: "); 51 | scanf("%d",&maxstack); 52 | push(maxstack); 53 | 54 | printf("\n Stack:"); 55 | display(); 56 | 57 | printf("\n\n After pop data from stack:"); 58 | pop(maxstack); 59 | 60 | printf("\n\n After pop element from the stack: "); 61 | display(); 62 | 63 | } 64 | -------------------------------------------------------------------------------- /Lab Tast [ 30/08/2023 ].c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct node { 4 | int data; 5 | struct node* prev; 6 | struct node* next; 7 | }*head; 8 | typedef struct node node; 9 | void create_List(int n); 10 | void insertAtBeginning(int data); 11 | void deleteAtBeginning(); 12 | 13 | void create_List(int n) 14 | { 15 | struct node* newnode, * temp; 16 | head = (node*)malloc(sizeof(node)); 17 | printf("Enter the data for the first node: "); 18 | scanf("%d", &head->data); 19 | head->prev = NULL; 20 | head->next = NULL; 21 | temp = head; 22 | 23 | for (int i = 2; i <= n; i++) { 24 | newnode = (struct node*)malloc(sizeof(struct node)); 25 | printf("Input data for node %d: ", i); 26 | scanf("%d", &newnode->data); 27 | newnode->prev = temp; 28 | newnode->next = NULL; 29 | temp->next = newnode; 30 | temp = temp->next; 31 | } 32 | } 33 | 34 | void insertAtBeginning(int data) 35 | { 36 | node *newnode =(node*)malloc(sizeof(node)); 37 | newnode->data = data; 38 | newnode->prev = NULL; 39 | newnode->next = head; 40 | 41 | if (head != NULL) 42 | { 43 | head->prev = newnode; 44 | } 45 | 46 | head = newnode; 47 | } 48 | void insertAtMiddle(int position, int data) 49 | { 50 | node *newNode =(node*)malloc(sizeof(node)); 51 | newNode->data = data; 52 | 53 | node *temp = head; 54 | for (int i = 1; i < position - 1 && temp != NULL; i++) 55 | { 56 | temp = temp->next; 57 | } 58 | 59 | newNode->prev = temp; 60 | newNode->next = temp->next; 61 | if (temp->next != NULL) 62 | { 63 | temp->next->prev = newNode; 64 | } 65 | temp->next = newNode; 66 | } 67 | 68 | void deleteAtBeginning() 69 | { 70 | 71 | node *temp = head; 72 | head = head->next; 73 | if (head != NULL) 74 | { 75 | head->prev = NULL; 76 | } 77 | free(temp); 78 | } 79 | 80 | void Display() 81 | { 82 | node *temp = head; 83 | while (temp!= NULL) 84 | { 85 | printf("DATA: %d\n",temp->data); 86 | temp = temp->next; 87 | } 88 | printf("\n\n"); 89 | } 90 | 91 | int main() { 92 | int n; 93 | printf("Input the number of nodes : "); 94 | scanf("%d", &n); 95 | create_List(n); 96 | printf("\nData entered in the doubly linked list:\n"); 97 | Display(); 98 | 99 | int b_data; 100 | printf("Enter data : "); 101 | scanf("%d",&b_data); 102 | insertAtBeginning(b_data); 103 | Display(); 104 | 105 | int position; 106 | int data; 107 | printf("Enter middle position : "); 108 | scanf("%d",&position); 109 | printf("Enter Middle position data : "); 110 | scanf("%d",&data); 111 | insertAtMiddle(position,data); 112 | Display(); 113 | 114 | printf("\n \n After Delete First position !!! \n"); 115 | deleteAtBeginning(); 116 | Display(); 117 | 118 | 119 | 120 | return 0; 121 | } 122 | -------------------------------------------------------------------------------- /Lab2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | 6 | { 7 | int a; 8 | a=10; 9 | int *p; 10 | p = &a; 11 | cout << a << endl; 12 | cout << &a << endl; 13 | cout << p << endl; 14 | cout << *p << endl; 15 | 16 | *p = 20; 17 | cout << a << endl; 18 | 19 | a = 20; 20 | cout << *p<< endl << endl; 21 | 22 | // Array 23 | int x[5] ={10,20,30,40,50}; 24 | int *p; 25 | for(int i=0 ; i< 5; i++) 26 | { 27 | cout << &x[i] << endl; 28 | } 29 | cout < 2 | #include 3 | 4 | struct node { 5 | int data; 6 | struct node *next; 7 | }; 8 | 9 | typedef struct node node; 10 | node *head; 11 | void createnode(int n); 12 | void display(); 13 | void insert_beg(); 14 | void insert_end(); 15 | void insert_middle(int position); 16 | void delete_first(); 17 | void delete_middle(int position); 18 | void delete_last(); 19 | 20 | void createnode(int n) { 21 | node *newnode, *temp; 22 | head = (node *)malloc(sizeof(node)); 23 | 24 | head->next = NULL; 25 | printf("\nEnter data for Node 1 : "); 26 | scanf("%d", &head->data); 27 | temp = head; 28 | for (int i = 2; i <= n; i++) { 29 | newnode = (node *)malloc(sizeof(node)); 30 | printf("\nEnter data for Node %d : ", i); 31 | scanf("%d", &newnode->data); 32 | newnode->next = NULL; 33 | temp->next = newnode; 34 | temp = temp->next; 35 | } 36 | } 37 | 38 | void insert_beg() { 39 | node *newnode; 40 | newnode = (node *)malloc(sizeof(node)); 41 | printf("\nEnter data for beginning node: "); 42 | scanf("%d", &newnode->data); 43 | newnode->next = head; 44 | head = newnode; 45 | } 46 | 47 | void insert_middle(int position) { 48 | 49 | node *newnode, *temp; 50 | temp = head; 51 | for (int i = 1; i < position - 1; i++) { 52 | temp = temp->next; 53 | } 54 | newnode = (node *)malloc(sizeof(node)); 55 | printf("Enter data at MIDDLE position: "); 56 | scanf("%d", &newnode->data); 57 | newnode->next = temp->next; 58 | temp->next = newnode; 59 | } 60 | 61 | void insert_end() { 62 | node *temp, *newnode; 63 | newnode = (node *)malloc(sizeof(node)); 64 | printf("\nEnter data for last node: "); 65 | scanf("%d", &newnode->data); 66 | temp = head; 67 | while (temp->next != NULL) { 68 | temp = temp->next; 69 | } 70 | temp->next = newnode; 71 | newnode->next = NULL; 72 | } 73 | 74 | void delete_first() { 75 | node *temp; 76 | temp = head; 77 | head = temp->next; 78 | free(temp); 79 | } 80 | 81 | void delete_middle(int position) { 82 | node *current, *temp, *prev; 83 | temp = head; 84 | for (int i = 1; i < position; i++) { 85 | prev = temp; 86 | current = temp->next; 87 | temp = temp->next; 88 | } 89 | prev->next = current->next; 90 | free(current); 91 | } 92 | 93 | void delete_last() { 94 | node *temp, *prev; 95 | temp = head; 96 | prev = NULL; 97 | while (temp->next != NULL) { 98 | prev = temp; 99 | temp = temp->next; 100 | } 101 | prev->next = NULL; 102 | 103 | free(temp); 104 | } 105 | 106 | void display() { 107 | node *temp; 108 | temp = head; 109 | printf("\nYou have Successfully Print the following linked list :\n"); 110 | while (temp != NULL) { 111 | printf("%d -> ", temp->data); 112 | temp = temp->next; 113 | } 114 | printf("NULL\n"); 115 | } 116 | 117 | int main() { 118 | int n; 119 | printf("\nEnter total number of nodes: "); 120 | scanf("%d", &n); 121 | createnode(n); 122 | display(); 123 | 124 | printf("\nInserting new node at the beginning...\n"); 125 | insert_beg(); 126 | display(); 127 | 128 | int pos; 129 | printf("\nInserting the value at the MIDDLE position......\n"); 130 | printf("Enter the position number: "); 131 | scanf("%d", &pos); 132 | insert_middle(pos); 133 | display(); 134 | 135 | printf("\nInserting new node at the end...\n"); 136 | insert_end(); 137 | display(); 138 | 139 | // Delete Node First 140 | printf("\nDelete node First Data !!!\n"); 141 | delete_first(); 142 | display(); 143 | 144 | // Delete Middle / Any Node 145 | printf("\nDeleting a node from the middle...\n"); 146 | printf("Enter the position number to delete : "); 147 | scanf("%d", &pos); 148 | delete_middle(pos); 149 | display(); 150 | 151 | // Delete Last Node 152 | printf("\nDelete node Last Data !!!\n"); 153 | delete_last(); 154 | display(); 155 | 156 | return 0; 157 | } 158 | 159 | 160 | -------------------------------------------------------------------------------- /Link List File/Add data middle.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct node 4 | { 5 | int data; 6 | struct node *next; 7 | }*head; 8 | typedef struct node node; 9 | void nodeDisplay(); 10 | void insert_middle(int pos); 11 | 12 | void createNode(int n) 13 | { 14 | head =(node*)malloc(sizeof(node)); 15 | printf("Enter node 1 data :"); 16 | scanf("%d",&head->data); 17 | 18 | node *newnode ,* temp; 19 | temp = head; 20 | for(int i=2 ; i<=n ; i++) 21 | { 22 | newnode=(node*)malloc(sizeof(node)); 23 | printf("Enter node %d data :",i); 24 | scanf("%d",&newnode->data); 25 | newnode->next =NULL; 26 | temp->next =newnode; 27 | temp = temp->next; 28 | } 29 | } 30 | 31 | void insert_middle(int pos){ 32 | node *newnode, *prev ,*current ,*temp; 33 | newnode=(node*)malloc(sizeof(node)); 34 | printf("Enter %d node data :",pos); 35 | scanf("%d",&newnode->data); 36 | temp = head; 37 | for(int i=1; inext; 41 | temp = temp->next; 42 | } 43 | prev->next =newnode; 44 | newnode->next =current; 45 | } 46 | /* 47 | void insert_middle(int pos){ 48 | struct node *newnode, *temp; 49 | temp=head; 50 | newnode = (node*) malloc(sizeof(node)); 51 | printf("Enter %d node data :",pos); 52 | scanf("%d",&newnode->data); 53 | for(int i=1; inext; 56 | } 57 | newnode->next=temp->next; 58 | temp->next=newnode; 59 | } */ 60 | 61 | 62 | //Display the node value ~~ 63 | void nodeDisplay(){ 64 | node *value; 65 | int i=1; 66 | value= head; 67 | while(value !=NULL) 68 | { 69 | printf("Node %d data ->%d",i,value->data); 70 | value = value->next; 71 | i++; 72 | printf("\n"); 73 | } 74 | } 75 | 76 | int main(){ 77 | int n; 78 | printf("Enter number of node :"); 79 | scanf("%d",&n); 80 | createNode(n); 81 | printf("\nLinkList Create successfully Done !!!\n"); 82 | nodeDisplay(); 83 | 84 | //New node add middle 85 | printf("\nEnter position number :"); 86 | int pos; 87 | scanf("%d",&pos); 88 | insert_middle(pos); 89 | nodeDisplay(); 90 | return 0; 91 | } 92 | -------------------------------------------------------------------------------- /Link List File/Link List create,delete (condition ).c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct node { 5 | int data; 6 | struct node *next; 7 | }; 8 | 9 | typedef struct node node; 10 | 11 | node *head; 12 | 13 | void createnode(int n); 14 | void display(); 15 | void insert_beg(); 16 | void insert_end(); 17 | void insert_middle(int position); 18 | void delete_first(); 19 | void delete_middle(int position); 20 | void delete_last(); 21 | 22 | void createnode(int n) { 23 | node *newnode, *temp; 24 | int i; 25 | head = (node *)malloc(sizeof(node)); 26 | if (head == NULL) { 27 | printf("Memory allocation failed."); 28 | exit(1); 29 | } 30 | head->next = NULL; 31 | printf("\nEnter data for Node 1: "); 32 | scanf("%d", &head->data); 33 | temp = head; 34 | for (i = 2; i <= n; i++) { 35 | newnode = (node *)malloc(sizeof(node)); 36 | if (newnode == NULL) { 37 | printf("Memory allocation failed."); 38 | exit(1); 39 | } 40 | printf("\nEnter data for Node %d: ", i); 41 | scanf("%d", &newnode->data); 42 | newnode->next = NULL; 43 | temp->next = newnode; 44 | temp = temp->next; 45 | } 46 | } 47 | 48 | void insert_beg() { 49 | node *newnode; 50 | newnode = (node *)malloc(sizeof(node)); 51 | if (newnode == NULL) { 52 | printf("Memory allocation failed."); 53 | exit(1); 54 | } 55 | printf("\nEnter data for beginning node: "); 56 | scanf("%d", &newnode->data); 57 | newnode->next = head; 58 | head = newnode; 59 | } 60 | 61 | void insert_middle(int position) { 62 | if (position < 1) { 63 | printf("Invalid position.\n"); 64 | return; 65 | } 66 | node *newnode, *temp; 67 | temp = head; 68 | for (int i = 1; i < position - 1; i++) { 69 | if (temp == NULL) { 70 | printf("Invalid position.\n"); 71 | return; 72 | } 73 | temp = temp->next; 74 | } 75 | newnode = (node *)malloc(sizeof(node)); 76 | if (newnode == NULL) { 77 | printf("Memory allocation failed."); 78 | exit(1); 79 | } 80 | printf("Enter data at MIDDLE position: "); 81 | scanf("%d", &newnode->data); 82 | newnode->next = temp->next; 83 | temp->next = newnode; 84 | } 85 | 86 | void insert_end() { 87 | node *temp, *newnode; 88 | newnode = (node *)malloc(sizeof(node)); 89 | if (newnode == NULL) { 90 | printf("Memory allocation failed."); 91 | exit(1); 92 | } 93 | printf("\nEnter data for last node: "); 94 | scanf("%d", &newnode->data); 95 | temp = head; 96 | while (temp->next != NULL) { 97 | temp = temp->next; 98 | } 99 | temp->next = newnode; 100 | newnode->next = NULL; 101 | } 102 | 103 | void delete_first() { 104 | if (head == NULL) { 105 | printf("List is empty.\n"); 106 | return; 107 | } 108 | node *temp; 109 | temp = head; 110 | head = temp->next; 111 | free(temp); 112 | } 113 | 114 | void delete_middle(int position) { 115 | if (position < 1 || head == NULL) { 116 | printf("Invalid position or empty list.\n"); 117 | return; 118 | } 119 | node *current, *temp, *prev; 120 | temp = head; 121 | for (int i = 1; i < position; i++) { 122 | prev = temp; 123 | current = temp->next; 124 | if (current == NULL) { 125 | printf("Invalid position.\n"); 126 | return; 127 | } 128 | temp = temp->next; 129 | } 130 | prev->next = current->next; 131 | free(current); 132 | } 133 | 134 | void delete_last() { 135 | if (head == NULL) { 136 | printf("List is empty.\n"); 137 | return; 138 | } 139 | node *temp, *prev; 140 | temp = head; 141 | prev = NULL; 142 | while (temp->next != NULL) { 143 | prev = temp; 144 | temp = temp->next; 145 | } 146 | if (prev != NULL) { 147 | prev->next = NULL; 148 | } else { 149 | head = NULL; 150 | } 151 | free(temp); 152 | } 153 | 154 | void display() { 155 | node *temp; 156 | temp = head; 157 | if (temp == NULL) { 158 | printf("\nThe list is empty.\n"); 159 | return; 160 | } 161 | printf("\nYou have Successfully created the following linked list:\n"); 162 | while (temp != NULL) { 163 | printf("%d -> ", temp->data); 164 | temp = temp->next; 165 | } 166 | printf("NULL\n"); 167 | } 168 | 169 | int main() { 170 | int n; 171 | printf("\nEnter total number of nodes: "); 172 | scanf("%d", &n); 173 | createnode(n); 174 | display(); 175 | 176 | printf("\nInserting new node at the beginning...\n"); 177 | insert_beg(); 178 | display(); 179 | 180 | int pos; 181 | printf("\nInserting the value at the MIDDLE position......\n"); 182 | printf("Enter the position number: "); 183 | scanf("%d", &pos); 184 | insert_middle(pos); 185 | display(); 186 | 187 | printf("\nInserting new node at the end...\n"); 188 | insert_end(); 189 | display(); 190 | 191 | // Delete Node First 192 | delete_first(); 193 | display(); 194 | 195 | // Delete Middle / Any Node 196 | printf("\nDeleting a node from the middle...\n"); 197 | printf("Enter the position number to delete: "); 198 | scanf("%d", &pos); 199 | delete_middle(pos); 200 | display(); 201 | 202 | // Delete Last Node 203 | delete_last(); 204 | display(); 205 | 206 | return 0; 207 | } 208 | -------------------------------------------------------------------------------- /Link List File/Project Lab 09-08-2023.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct node { 4 | int StudentID; 5 | float Marks; 6 | char Section; 7 | struct node *next; 8 | }*head; 9 | typedef struct node node; 10 | void createNode(int n); 11 | void nodeDisplay(); 12 | void new_nodeFirst(); 13 | void insert_end(); 14 | void insert_middle(int pos); 15 | void searchNode(int StudentID); 16 | 17 | void createNode(int n) { 18 | head = (node*)malloc(sizeof(node)); 19 | printf("Enter Student 1 StudentID: "); 20 | scanf("%d", &head->StudentID); 21 | printf("Marks: "); 22 | scanf("%f", &head->Marks); 23 | printf("Section: "); 24 | getchar(); 25 | scanf("%c", &head->Section); 26 | printf("\n"); 27 | head->next = NULL; 28 | 29 | node *newnode, *temp; 30 | temp = head; 31 | 32 | for (int i = 2; i <= n; i++) { 33 | newnode = (node*)malloc(sizeof(node)); 34 | printf("Enter Student %d StudentID: ", i); 35 | scanf("%d", &newnode->StudentID); 36 | printf("Enter Student %d Marks: ", i); 37 | scanf("%f", &newnode->Marks); 38 | printf("Enter Student %d Section: ", i); 39 | getchar(); 40 | scanf("%c", &newnode->Section); 41 | newnode->next = NULL; 42 | temp->next = newnode; 43 | temp = temp->next; 44 | printf("\n"); 45 | } 46 | } 47 | //Insert Value at First 48 | void new_nodeFirst() 49 | { 50 | node *temp, *newnode; 51 | temp = head; 52 | newnode=(node*)malloc(sizeof(node)); 53 | printf("New Student StudentID: "); 54 | scanf("%d", &newnode->StudentID); 55 | printf("Marks: "); 56 | scanf("%f", &newnode->Marks); 57 | printf("Section: "); 58 | getchar(); 59 | scanf("%c", &newnode->Section); 60 | newnode->next=head; 61 | head=newnode; 62 | } 63 | // Insert Value at End 64 | void insert_end() 65 | { 66 | node *temp,*newnode; 67 | temp=head; 68 | newnode=(node*)malloc(sizeof(node)); 69 | printf("Student 1 StudentID: "); 70 | scanf("%d", &newnode->StudentID); 71 | printf("Enter Student 1 Marks: "); 72 | scanf("%f", &newnode->Marks); 73 | printf("Enter Student 1 Section: "); 74 | getchar(); 75 | scanf("%c", &newnode->Section); 76 | 77 | temp=head; 78 | while(temp->next!=NULL) 79 | { 80 | temp=temp->next; 81 | } 82 | temp->next=newnode; 83 | newnode->next=NULL; 84 | } 85 | // Add middle position 86 | void insert_middle(int pos){ 87 | node *newnode, *prev ,*current ,*temp; 88 | newnode=(node*)malloc(sizeof(node)); 89 | printf("Student 1 StudentID: "); 90 | scanf("%d", &newnode->StudentID); 91 | printf("Enter Student 1 Marks: "); 92 | scanf("%f", &newnode->Marks); 93 | printf("Enter Student 1 Section: "); 94 | getchar(); 95 | scanf("%c", &newnode->Section); 96 | temp = head; 97 | for(int i=1; inext; 101 | temp = temp->next; 102 | } 103 | prev->next =newnode; 104 | newnode->next =current; 105 | } 106 | // Searching 107 | void searchNode(int ID){ 108 | node *temp; 109 | temp = head; 110 | while(temp != NULL) 111 | { 112 | if(temp->StudentID == ID) 113 | { 114 | printf("Search Item Found !!\n"); 115 | break; 116 | } 117 | else{ 118 | temp = temp->next; 119 | } 120 | } 121 | if(temp == NULL){ 122 | printf("Search Item Not Found !!\n"); 123 | } 124 | } 125 | 126 | void nodeDisplay() { 127 | node *value; 128 | int i = 1; 129 | value = head; 130 | printf("\n\nNode Print Successfully Done !!! \n"); 131 | while (value != NULL) { 132 | printf("Student %d StudentID -> %d\n", i, value->StudentID); 133 | printf("Marks -> %.2f\n", value->Marks); 134 | printf("Section -> %c\n", value->Section); 135 | value = value->next; 136 | i++; 137 | printf("\n"); 138 | } 139 | } 140 | int main() { 141 | int n; 142 | printf("Enter number of students : "); 143 | scanf("%d", &n); 144 | createNode(n); 145 | printf("\nLinkedList created successfully!\n"); 146 | nodeDisplay(); 147 | //Node First 148 | new_nodeFirst(); 149 | nodeDisplay(); 150 | //Node at Last 151 | insert_end(); 152 | nodeDisplay(); 153 | //Add random position 154 | printf("Enter any random number where you want :"); 155 | int pos; 156 | scanf("%d",&pos); 157 | insert_middle(pos); 158 | // Search Which node number 159 | printf("Enter which Student_ID you want to search :"); 160 | int ID; 161 | scanf("%d",&ID); 162 | searchNode(ID); 163 | 164 | return 0; 165 | } 166 | -------------------------------------------------------------------------------- /Link List File/Spring 2023 .c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct node{ 4 | struct node *prev; 5 | char data; 6 | struct node *next; 7 | }; 8 | typedef struct node node; 9 | int main() 10 | { 11 | node *n1 , *n2 , *n3 ,*n4; 12 | 13 | n1 =(node*)malloc(sizeof(node)); 14 | n2 =(node*)malloc(sizeof(node)); 15 | n3 =(node*)malloc(sizeof(node)); 16 | n4 =(node*)malloc(sizeof(node)); 17 | 18 | n1->data ='A'; 19 | n1->next = n2; 20 | 21 | n2->data ='B'; 22 | n2->next =n3; 23 | n3->prev =n2; 24 | 25 | n3->data ='B'; 26 | n3->next =n4; 27 | n3->prev =n2; 28 | 29 | n4->data ='D'; 30 | n4->next =NULL; 31 | n4->prev =n3; 32 | 33 | printf(" Link list Create successfully !!\n"); 34 | printf("%c-> ",n1->data); 35 | printf("%c-> ",n2->data); 36 | printf("%c-> ",n3->data); 37 | printf("%c-> ",n4->data); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /Link List File/link list User input Node.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | struct node{ 5 | int data; 6 | struct node *next; 7 | }*head; 8 | typedef struct node nodal; 9 | void createNode(int n); 10 | void displayNode(); 11 | 12 | void createNode(int n) 13 | { 14 | head =(nodal*)malloc(sizeof(nodal)); 15 | cout <<"Enter node 1 data :"; 16 | cin >>head->data; 17 | head->next=NULL; 18 | 19 | nodal *newnode ,*temp; 20 | temp=head; 21 | 22 | for(int i=2; i<=n ; i++) 23 | { 24 | newnode =(nodal*)malloc(sizeof(nodal)); 25 | cout <<"Enter node "<>newnode->data; 27 | newnode->next = NULL; 28 | temp->next = newnode; 29 | temp= temp->next; 30 | } 31 | } 32 | void displayNode() 33 | { 34 | nodal *value=head; 35 | int i=1; 36 | while(value != NULL) 37 | { 38 | cout <<"Node "<data<next; 40 | i++; 41 | } 42 | cout <> newnodeFirst->data; 50 | 51 | newnodeFirst->next = head; // Newnode next add to the head pointer value 52 | head = newnodeFirst; // Here initialization the new node first to head 53 | } 54 | 55 | int main() 56 | { 57 | int n; 58 | cout << "Enter number of nodes :"; 59 | cin >>n; 60 | createNode(n); 61 | cout << endl <<"Node create Successfully !"<< endl; 62 | displayNode(); 63 | // ADD node First position 64 | create_node_first(); 65 | cout < 2 | #include 3 | struct node{ 4 | int data; 5 | struct node *next; 6 | }*head; 7 | 8 | typedef struct node nodal; 9 | 10 | void createnode(int n); 11 | void displayList(); 12 | void insert_node_last(); 13 | 14 | int main() 15 | { 16 | int n; 17 | printf("Enter number of nodes: "); 18 | scanf("%d", &n); 19 | 20 | createnode(n); 21 | printf("\nLinked list created successfully!\n"); 22 | 23 | printf("The linked list elements are: "); 24 | displayList(); 25 | 26 | insert_node_last(); // Here call the LastNode add function 27 | 28 | printf("\nLinked list last node insert successfully!\n"); 29 | printf("The linked list elements are: "); 30 | displayList(); // Again print the value 31 | return 0; 32 | } 33 | 34 | void createnode(int n) 35 | { 36 | head = (nodal*)malloc(sizeof(nodal)); 37 | 38 | 39 | printf("Enter data for node 1: "); 40 | scanf("%d", &head->data); 41 | 42 | head->next = NULL; 43 | 44 | int i; 45 | nodal *newnode, *temp; 46 | temp = head; 47 | 48 | for (i = 2; i <= n; i++) 49 | { 50 | newnode = (nodal*)malloc(sizeof(nodal)); 51 | 52 | printf("Enter data for node %d: ", i); 53 | scanf("%d", &newnode->data); 54 | 55 | newnode->next = NULL; 56 | temp->next = newnode; 57 | temp = temp->next; 58 | } 59 | } 60 | 61 | void insert_node_last() 62 | { 63 | nodal *newnodeLast ,*temp; 64 | temp = head; // Full node insert to store the temp , then it should be connect to last add new node process 65 | newnodeLast =(nodal*)malloc(sizeof(nodal)); 66 | printf("\nInsert last node Data again to add :"); 67 | scanf("%d",&newnodeLast->data); 68 | 69 | while(temp->next != NULL) // This loop will be continue , when the temp last node not found NULL 70 | { 71 | temp = temp->next; 72 | } 73 | temp->next = newnodeLast; // Here temp full node connected , at last create newNode 74 | newnodeLast->next=NULL; 75 | } 76 | 77 | void displayList() 78 | { 79 | nodal *current = head; 80 | while (current != NULL) { 81 | printf("%d ", current->data); 82 | current = current->next; 83 | } 84 | printf("\n"); 85 | } 86 | -------------------------------------------------------------------------------- /Link List File/user Input linkList.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct node{ 5 | int data; 6 | struct node *next; 7 | }*head; 8 | 9 | typedef struct node nodal; 10 | 11 | void createnode(int n); 12 | void displayList(); 13 | void insert_node_last(); 14 | 15 | int main() 16 | { 17 | int n; 18 | printf("Enter number of nodes: "); 19 | scanf("%d", &n); 20 | 21 | createnode(n); 22 | printf("Linked list created successfully!\n"); 23 | 24 | printf("The linked list elements are: "); 25 | displayList(); 26 | 27 | insert_node_last(); // Here call the LastNode add function 28 | 29 | printf("Linked list last node insert successfully!\n"); 30 | printf("The linked list elements are: "); 31 | displayList(); // Again print the value 32 | return 0; 33 | } 34 | 35 | void createnode(int n) 36 | { 37 | head = (nodal*)malloc(sizeof(nodal)); 38 | 39 | 40 | printf("Enter data for node 1: "); 41 | scanf("%d", &head->data); 42 | 43 | head->next = NULL; 44 | 45 | int i; 46 | nodal *newnode, *temp; 47 | temp = head; 48 | 49 | for (i = 2; i <= n; i++) 50 | { 51 | newnode = (nodal*)malloc(sizeof(nodal)); 52 | 53 | printf("Enter data for node %d: ", i); 54 | scanf("%d", &newnode->data); 55 | 56 | newnode->next = NULL; 57 | temp->next = newnode; 58 | temp = temp->next; 59 | } 60 | } 61 | 62 | void insert_node_last() 63 | { 64 | nodal *newnodeLast ,*temp; 65 | temp = head; // Full node insert to store the temp , then it should be connect to last add new node process 66 | newnodeLast =(nodal*)malloc(sizeof(nodal)); 67 | printf("\nInsert last node Data again to add :"); 68 | scanf("%d",&newnodeLast->data); 69 | 70 | while(temp->next != NULL) // This loop will be continue , when the temp last node not found NULL 71 | { 72 | temp = temp->next; 73 | } 74 | temp->next = newnodeLast; // Here temp full node connected , at last create newNode 75 | newnodeLast->next=NULL; 76 | } 77 | 78 | void displayList() 79 | { 80 | nodal *current = head; 81 | while (current != NULL) { 82 | printf("%d ", current->data); 83 | current = current->next; 84 | } 85 | printf("\n"); 86 | } 87 | -------------------------------------------------------------------------------- /LinkList.c: -------------------------------------------------------------------------------- 1 | ## 2 | 3 | 4 | -------------------------------------------------------------------------------- /LinkList.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | struct student { 5 | int data; 6 | struct student *next; // Use student* instead of struct node* 7 | }a,b,c,d; 8 | 9 | int main() { 10 | // student a, b, c, d; 11 | a.data = 10; 12 | b.data = 20; 13 | c.data = 30; 14 | d.data = 40; 15 | 16 | a.next = &b; 17 | b.next = &c; 18 | c.next = &d; 19 | d.next = NULL; // Use null pointer instead of NULL 20 | 21 | cout << "A Data = " << a.data << endl; 22 | cout << "B Data = " << b.data << endl; 23 | cout << "C Data = " << c.data << endl; 24 | cout << "D Data = " << d.data << endl << endl; 25 | 26 | cout << "Location of A address = " << a.next << endl; 27 | cout << "Location of B address = " << b.next << endl; 28 | cout << "Location of C address = " << c.next << endl; 29 | cout << "Location of D address = " << d.next << endl; 30 | 31 | return 0; 32 | } 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /QuestionSolve 2022.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | struct node { 6 | int x ; 7 | float y; 8 | char z; 9 | struct node *next; // self refarencial pointer 10 | }; 11 | typedef struct node head; 12 | int main() 13 | { 14 | head *baby , *fish ,*cat; 15 | baby =(head*)malloc(sizeof(head)); // Memory Address create 16 | fish =(head*)malloc(sizeof(head)); // Memory Address create 17 | cat =(head*)malloc(sizeof(head)); // Memory Address create 18 | 19 | baby->x =7; baby->y =1.5; baby->z = 'A'; 20 | baby->next=fish; 21 | 22 | fish->x = 10; fish->y =3.5; fish->z = 'B'; 23 | fish->next=cat; 24 | 25 | cat->x = 13; cat->y =5.5; cat->z = 'C'; 26 | cat->next=NULL; 27 | 28 | cout <<"Print value "<< baby->x << endl; 29 | cout <<"Print value "<< baby->y << endl; 30 | cout <<"Print value "<< baby->z << endl<x << endl; 33 | cout <<"Print value "<< fish->y << endl; 34 | cout <<"Print value "<< fish->z << endl<x << endl; 37 | cout <<"Print value "<< cat->y << endl; 38 | cout <<"Print value "<< cat->z << endl; 39 | 40 | return 0; 41 | } 42 | 43 | -------------------------------------------------------------------------------- /Queue/Queue Basic Function.c: -------------------------------------------------------------------------------- 1 | // Queue implementation in C 2 | #include 3 | #include 4 | #define SIZE 5 5 | //Function prototype 6 | void enQueue(int); 7 | void deQueue(); 8 | void display(); 9 | 10 | int items[SIZE], front = -1, rear = -1; 11 | 12 | void enQueue(int value) { 13 | if (front == -1) 14 | front = 0; 15 | rear++; 16 | items[rear] = value; 17 | printf("\nInserted -> %d", value); 18 | } 19 | 20 | void deQueue() { 21 | printf("\nDeleted : %d", items[front]); 22 | front++; 23 | if (front > rear) 24 | front = rear = -1; 25 | } 26 | 27 | // Function to print the queue 28 | void display() { 29 | 30 | int i; 31 | printf("\nQueue elements are: \n"); 32 | for (i = front; i <= rear; i++){ 33 | printf("%d ", items[i]); 34 | } 35 | printf("\n"); 36 | } 37 | 38 | 39 | int main() { 40 | //deQueue is not possible on empty queue 41 | deQueue(); 42 | display(); 43 | 44 | //enQueue 5 elements 45 | enQueue(1); 46 | enQueue(2); 47 | enQueue(3); 48 | enQueue(4); 49 | enQueue(5); 50 | 51 | // 6th element can't be added to because the queue is full 52 | enQueue(6); 53 | display(); 54 | 55 | //deQueue removes element entered first i.e. 1 56 | deQueue(); 57 | 58 | //Now we have just 4 elements 59 | display(); 60 | 61 | return 0; 62 | } 63 | 64 | -------------------------------------------------------------------------------- /Queue/Queue.c: -------------------------------------------------------------------------------- 1 | // Queue implementation in C 2 | #include 3 | #include 4 | #define SIZE 5 5 | 6 | void enQueue(int); 7 | void deQueue(); 8 | void display(); 9 | 10 | int items[SIZE], front = -1, rear = -1; 11 | 12 | void enQueue(int value) { 13 | if (rear == SIZE - 1) 14 | printf("\nQueue is Full!!"); 15 | else { 16 | if (front == -1) 17 | front = 0; 18 | rear++; 19 | items[rear] = value; 20 | printf("\nInserted -> %d", value); 21 | } 22 | } 23 | 24 | void deQueue() { 25 | if (front == -1) 26 | printf("\nQueue is Empty!!"); 27 | else { 28 | printf("\nDeleted : %d", items[front]); 29 | front++; 30 | if (front > rear) 31 | front = rear = -1; 32 | } 33 | } 34 | 35 | // Function to print the queue 36 | void display() { 37 | if (rear == -1) 38 | printf("\nQueue is Empty!!!"); 39 | else { 40 | int i; 41 | printf("\nQueue elements are:\n"); 42 | for (i = front; i <= rear; i++) 43 | printf("%d ", items[i]); 44 | } 45 | printf("\n"); 46 | } 47 | 48 | int main() { 49 | //deQueue is not possible on empty queue 50 | deQueue(); 51 | display(); 52 | 53 | //enQueue 5 elements 54 | enQueue(1); 55 | enQueue(2); 56 | enQueue(3); 57 | enQueue(4); 58 | enQueue(5); 59 | 60 | // 6th element can't be added to because the queue is full 61 | enQueue(6); 62 | 63 | display(); 64 | 65 | //deQueue removes element entered first i.e. 1 66 | deQueue(); 67 | 68 | //Now we have just 4 elements 69 | display(); 70 | 71 | return 0; 72 | } 73 | -------------------------------------------------------------------------------- /Spring 2023 .c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct node{ 4 | struct node *prev; 5 | char data; 6 | struct node *next; 7 | }; 8 | typedef struct node node; 9 | int main() 10 | { 11 | node *n1 , *n2 , *n3 ,*n4; 12 | 13 | n1 =(node*)malloc(sizeof(node)); 14 | n2 =(node*)malloc(sizeof(node)); 15 | n3 =(node*)malloc(sizeof(node)); 16 | n4 =(node*)malloc(sizeof(node)); 17 | 18 | n1->data ='A'; 19 | n1->next = n2; 20 | 21 | n2->data ='B'; 22 | n2->next =n3; 23 | n3->prev =n2; 24 | 25 | n3->data ='B'; 26 | n3->next =n4; 27 | n3->prev =n2; 28 | 29 | n4->data ='D'; 30 | n4->next =NULL; 31 | n4->prev =n3; 32 | 33 | printf(" Link list Create successfully !!\n"); 34 | printf("%c-> ",n1->data); 35 | printf("%c-> ",n2->data); 36 | printf("%c-> ",n3->data); 37 | printf("%c-> ",n4->data); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /Spring 2023.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | struct node{ 6 | struct node *prev; 7 | char data; 8 | struct node *next; 9 | }; 10 | typedef struct node head; 11 | 12 | int main() 13 | { 14 | node *n1 , *n2 , *n3 ,*n4; 15 | 16 | n1 =(head*)malloc(sizeof(n1)); 17 | n2 =(head*)malloc(sizeof(n2)); 18 | n3 =(head*)malloc(sizeof(n3)); 19 | n4 =(head*)malloc(sizeof(n4)); 20 | 21 | n1->data ='A'; 22 | n1->next = n2; 23 | 24 | n2->data ='B'; 25 | n2->next =n3; 26 | n3->prev =n2; 27 | 28 | n3->data ='B'; 29 | n3->next =n4; 30 | n3->prev =n2; 31 | 32 | n4->data ='D'; 33 | n4->next =NULL; 34 | n4->prev =n3; 35 | 36 | cout << n1->data << endl; 37 | 38 | cout << n2->data << endl; 39 | 40 | cout << n3->data << endl; 41 | 42 | cout << n4->data << endl; 43 | return 0; 44 | } 45 | 46 | -------------------------------------------------------------------------------- /Spring Mid 2023.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct node { 5 | int StudentID; 6 | float Marks; 7 | char Section; 8 | struct node *next; 9 | }*head; 10 | typedef struct node node; 11 | void createNode(int n); 12 | void nodeDisplay(); 13 | 14 | void createNode(int n) { 15 | head = (node*)malloc(sizeof(node)); 16 | printf("Enter Student 1 StudentID: "); 17 | scanf("%d", &head->StudentID); 18 | printf("Enter Student 1 Marks: "); 19 | scanf("%f", &head->Marks); 20 | printf("Enter Student 1 Section: "); 21 | getchar(); 22 | scanf("%c", &head->Section); 23 | printf("\n"); 24 | head->next = NULL; 25 | 26 | node *newnode, *temp; 27 | temp = head; 28 | 29 | for (int i = 2; i <= n; i++) { 30 | newnode = (node*)malloc(sizeof(node)); 31 | printf("Enter Student %d StudentID: ", i); 32 | scanf("%d", &newnode->StudentID); 33 | printf("Enter Student %d Marks: ", i); 34 | scanf("%f", &newnode->Marks); 35 | printf("Enter Student %d Section: ", i); 36 | getchar(); 37 | scanf("%c", &newnode->Section); 38 | newnode->next = NULL; 39 | temp->next = newnode; 40 | temp = temp->next; 41 | printf("\n"); 42 | } 43 | } 44 | 45 | void nodeDisplay() { 46 | node *value; 47 | int i = 1; 48 | value = head; 49 | while (value != NULL) { 50 | printf("Student %d StudentID -> %d\n", i, value->StudentID); 51 | printf("Marks -> %.2f\n", value->Marks); 52 | printf("Section -> %c\n", value->Section); 53 | value = value->next; 54 | i++; 55 | printf("\n"); 56 | } 57 | } 58 | int main() { 59 | int n; 60 | printf("Enter number of studens : "); 61 | scanf("%d", &n); 62 | createNode(n); 63 | printf("\nLinkedList created successfully!\n"); 64 | nodeDisplay(); 65 | return 0; 66 | 67 | } 68 | -------------------------------------------------------------------------------- /Stack All Code/Spring 2022.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct node { 4 | int n; 5 | char o[10]; 6 | struct node *p; 7 | 8 | }; 9 | typedef struct node node ; 10 | int main() 11 | { 12 | node *node1 , *node2; 13 | node1=(node*)malloc(sizeof(node)); 14 | node2=(node*)malloc(sizeof(node)); 15 | 16 | node1->n = 18; 17 | strcpy(node1->o, "Head"); // Use strcpy to copy the string 18 | node1->p = node2; 19 | 20 | node2->n = 13; 21 | strcpy(node2->o, "Tail"); // Use strcpy to copy the string 22 | node2->p = NULL; 23 | 24 | printf(" Node 1 Data : %d\n",node1->n); 25 | printf(" Node 1 Data : %s\n",node1->o); 26 | 27 | printf(" Node 2 Data : %d\n",node2->n); 28 | printf(" Node 2 Data : %s\n",node1->o); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Stack All Code/Stack Full system.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define CAPACITY 3 4 | int stack[CAPACITY]; 5 | int top = -1; 6 | 7 | void push(int x) 8 | { 9 | 10 | if( top == CAPACITY -1) 11 | { 12 | cout <<"Stack OVERflow....."<> stack[x]; 20 | top = top + 1; 21 | stack[top] = x; 22 | } 23 | 24 | } 25 | 26 | int pop() 27 | { 28 | 29 | } 30 | 31 | int display() 32 | { 33 | if(top == -1) 34 | { 35 | cout <<"Stack Empty"<= 0 ; i--) 41 | { 42 | cout << "|" << stack[i] << "|" < 2 | #include 3 | #define MAX_SIZE 100 4 | 5 | int stack[MAX_SIZE]; 6 | int top = -1; 7 | 8 | // Function to push an element onto the stack 9 | void push(int value) { 10 | if (top >= MAX_SIZE - 1) 11 | { 12 | printf("Stack Overflow\n"); 13 | return false; 14 | } 15 | 16 | else 17 | { 18 | top = top + 1; 19 | stack[top]=value; 20 | return true; 21 | } 22 | } 23 | 24 | // Function to pop an element from the stack 25 | int pop() 26 | { 27 | if (top == -1) 28 | { 29 | printf("Stack Underflow\n"); 30 | return false; 31 | } 32 | 33 | else 34 | { 35 | top--; 36 | return true; 37 | } 38 | } 39 | 40 | // Function to display the elements of the stack 41 | void display() 42 | { 43 | if (top == -1) 44 | { 45 | printf("Stack is empty\n"); 46 | } 47 | 48 | else { 49 | printf("Stack elements: \n"); 50 | for (int i = 0; i <= top; i++) 51 | { 52 | printf("|%d| \n", stack[i]); 53 | } 54 | printf("\n"); 55 | } 56 | } 57 | 58 | int main() { 59 | push(10); 60 | push(20); 61 | push(30); 62 | 63 | display(); // Display: 10 20 30 64 | 65 | pop(); 66 | 67 | display(); // Display: 10 20 68 | 69 | push(40); 70 | 71 | display(); // Display: 10 20 40 72 | 73 | return 0; 74 | } 75 | -------------------------------------------------------------------------------- /Stack All Code/Stack with LinkList.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct node { 5 | int data; 6 | struct node *next; 7 | }; 8 | typedef struct node node; 9 | node *top = NULL; 10 | 11 | void push(int value) { 12 | node *newnode; 13 | newnode = (node *)malloc(sizeof(node)); 14 | newnode->data = value; 15 | newnode->next = top; 16 | top = newnode; 17 | } 18 | 19 | void display() { 20 | node *temp; 21 | temp = top; 22 | 23 | if (temp == NULL) { 24 | printf("Stack is EMPTY \n"); 25 | } else { 26 | printf("Stack: \n"); 27 | while (temp != NULL) { 28 | printf("|%d| \n", temp->data); 29 | temp = temp->next; 30 | } 31 | printf("\n"); 32 | } 33 | } 34 | 35 | void peek() { 36 | if (top == NULL) { 37 | printf("TOP is NULL\n"); 38 | } else { 39 | printf("TOP = |%d|\n", top->data); 40 | } 41 | } 42 | 43 | void pop() { 44 | node *temp; 45 | temp = top; 46 | if (temp == NULL) { 47 | printf("UNDERFLOW stack...\n"); 48 | } else { 49 | printf("Popped: %d\n", temp->data); 50 | top = top->next; 51 | free(temp); 52 | } 53 | } 54 | 55 | int main() { 56 | push(11); 57 | push(22); 58 | push(33); 59 | push(44); 60 | 61 | display(); 62 | peek(); 63 | pop(); 64 | display(); 65 | 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /Stack All Code/User input stack with Linklist.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct node { 5 | int data; 6 | struct node *next; 7 | }; 8 | typedef struct node node; 9 | node *top = NULL; 10 | 11 | void push(int n) { 12 | node *newnode; 13 | int value; 14 | 15 | for(int i=0 ;i < n ; i++) 16 | { 17 | printf("Enter %d data : ",i+1); 18 | scanf("%d",&value); 19 | 20 | newnode = (node *)malloc(sizeof(node)); 21 | newnode->data = value; 22 | newnode->next = top; 23 | top = newnode; 24 | } 25 | } 26 | 27 | void display() { 28 | node *temp; 29 | temp = top; 30 | 31 | if (temp == NULL) { 32 | printf("\n \t Stack is EMPTY \n"); 33 | } else { 34 | printf("\n Stack : \n"); 35 | while (temp != NULL) { 36 | printf("\t |%d| \n", temp->data); 37 | temp = temp->next; 38 | } 39 | printf("\n"); 40 | } 41 | } 42 | 43 | void peek() { 44 | if (top == NULL) { 45 | printf("TOP is NULL\n"); 46 | } else { 47 | printf("TOP = |%d|\n", top->data); 48 | } 49 | } 50 | 51 | void pop() { 52 | node *temp; 53 | temp = top; 54 | if (temp == NULL) { 55 | printf("UNDERFLOW stack...\n"); 56 | } else { 57 | printf("Pop Value : %d \n", temp->data); 58 | top = top->next; 59 | free(temp); 60 | } 61 | } 62 | 63 | int main() { 64 | int n; 65 | printf("How many data input in stack :"); 66 | scanf("%d",&n); 67 | push(n); 68 | display(); 69 | peek(); 70 | pop(); 71 | display(); 72 | return 0; 73 | } 74 | 75 | -------------------------------------------------------------------------------- /Summer 2020 Mid.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct node{ 5 | int data; 6 | struct node *next; 7 | }; 8 | typedef struct node node; 9 | 10 | int main() 11 | { node *Head , *Second , *Third ,*Fourth ,*Fifth; 12 | 13 | Head =(node*)malloc(sizeof(node)); 14 | Second =(node*)malloc(sizeof(node)); 15 | Third =(node*)malloc(sizeof(node)); 16 | Fourth =(node*)malloc(sizeof(node)); 17 | Fifth =(node*)malloc(sizeof(node)); 18 | 19 | Head->data =1; 20 | Head->next = Second; 21 | 22 | Second->data =3; 23 | Second->next = Third; 24 | 25 | Third->data =2; 26 | Third->next = Fourth; 27 | 28 | Fourth->data =20; 29 | Fourth->next = Fifth; 30 | 31 | Fifth->data =30; 32 | Fifth->next = NULL; 33 | 34 | node *value = Head; 35 | while(value !=NULL) 36 | { 37 | printf("%d-> ",value->data); 38 | value =value->next; 39 | } 40 | return 0; 41 | } 42 | 43 | -------------------------------------------------------------------------------- /Using Malloc and Data entry Student.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | struct student{ 6 | int id; 7 | float cgpa; 8 | struct student *next; 9 | }; //*std1,*std2,*std3 10 | typedef struct student node; // Here decleaire the 'Node' 11 | 12 | int main() 13 | { 14 | node *std1 , *std2 ,*std3; 15 | 16 | std1 = (node*)malloc(sizeof(node)); 17 | std2 = (node*)malloc(sizeof(node)); 18 | std3 = (node*)malloc(sizeof(node)); 19 | 20 | std1->id = 5364; 21 | std1->cgpa = 3.42; 22 | std1->next = std2; 23 | 24 | std2->id =5566; 25 | std2->cgpa = 3.55; 26 | std2->next = std3; 27 | 28 | std3->id =5090; 29 | std3->cgpa = 3.34; 30 | std3->next = NULL; 31 | 32 | 33 | cout << "Student ID =" << std1->id << endl; 34 | cout << "Student CGPA =" << std1->cgpa << endl << endl; 35 | 36 | cout << "Student ID =" << std2->id << endl; 37 | cout << "Student CGPA =" << std2->cgpa << endl << endl; 38 | 39 | cout << "Student ID =" << std3->id << endl; 40 | cout << "Student CGPA =" << std3->cgpa << endl << endl; 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /discoverTheWeb.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | ///**************QUEUE**********////////// 7 | typedef struct NodE { 8 | char* data; 9 | struct NodE* next,*prev; 10 | }NodE; 11 | 12 | // Structure for the queue 13 | typedef struct Queue { 14 | NodE* front; 15 | NodE* rear; 16 | }Queue; 17 | 18 | void initializeQueue(Queue* queue) { 19 | queue->front = queue->rear = NULL; 20 | } 21 | 22 | int isEmptyQ(Queue* queue) { 23 | return queue->front == NULL; 24 | } 25 | int QSize(Queue* queue) { //Queue Size Count 26 | int size = 0; 27 | NodE* current = queue->front; 28 | 29 | while (current != NULL) { 30 | size++; 31 | current = current->next; 32 | } 33 | 34 | return size; 35 | } 36 | 37 | 38 | const char* dequeue(Queue* queue) { 39 | if (isEmptyQ(queue)) { 40 | printf("There is nothing in history.\n"); 41 | exit(1); 42 | } 43 | 44 | NodE* temp = queue->front; //page deletion simple deque 45 | char* data = temp->data; 46 | queue->front = queue->front->next; 47 | queue->front->prev = NULL; 48 | free(temp); 49 | 50 | if (queue->front == NULL) { 51 | queue->rear = NULL; // Queue is empty 52 | } 53 | 54 | return data; 55 | } 56 | 57 | NodE *prevTemp=NULL; 58 | void enqueue(Queue* queue,const char* data) { 59 | // printf("Q::%d",QSize(queue)); 60 | if(QSize(queue)==5){ //history overflow check 61 | dequeue(queue); 62 | } 63 | NodE* newNode = (NodE*)malloc(sizeof(NodE)); 64 | if(newNode == NULL){ 65 | dequeue(queue); 66 | NodE* newNode = (NodE*)malloc(sizeof(NodE)); 67 | } 68 | 69 | newNode->data = strdup(data); 70 | newNode->next = NULL; 71 | newNode->prev=prevTemp; 72 | 73 | if (isEmptyQ(queue)) { //check empty or not 74 | queue->front = queue->rear = newNode; 75 | } else { 76 | queue->rear->next = newNode; 77 | queue->rear = newNode; 78 | } 79 | prevTemp=newNode; 80 | } 81 | 82 | 83 | 84 | const char* front(Queue* queue) { 85 | if (isEmptyQ(queue)) { 86 | printf("Queue is empty. Front operation failed.\n"); 87 | exit(1); 88 | } 89 | 90 | return queue->front->data; 91 | } 92 | 93 | void displayReverseQueue(Queue* queue) { // OUTPUT HISTORY HERE 94 | if (isEmptyQ(queue)) { 95 | printf("There in no history.\n"); 96 | return; 97 | } 98 | printf("\n\nYour search history:\n"); 99 | 100 | NodE* current = queue->rear; 101 | while (current != NULL) { 102 | printf("%s\n\n", current->data); 103 | current = current->prev; 104 | } 105 | printf("\n"); 106 | } 107 | 108 | 109 | ///**********QUEUE END***********///////// 110 | 111 | 112 | 113 | 114 | ///********STACK********/// 115 | typedef struct Node { 116 | char* data; 117 | struct Node* next; 118 | }Stack; 119 | 120 | 121 | Stack* createNode(const char* data) { 122 | Stack* newNode = (Stack*)malloc(sizeof(Stack)); 123 | newNode->data = strdup(data); 124 | newNode->next = NULL; 125 | return newNode; 126 | } 127 | 128 | 129 | void push(Stack** top, const char* data) {//double pointer for top inside stack pointer 130 | Stack* newNode = createNode(data); 131 | newNode->next = *top; 132 | *top = newNode; 133 | } 134 | 135 | 136 | char* pop(Stack** top) { //double pointer for top inside stack pointer 137 | if (*top == NULL) { 138 | return NULL; 139 | } 140 | Stack* temp = *top; 141 | *top = (*top)->next; 142 | char* data = temp->data; 143 | free(temp); 144 | return data; 145 | } 146 | 147 | 148 | int isEmpty(Stack* top) { 149 | return top == NULL; 150 | } 151 | 152 | //**********STACK END***************// 153 | 154 | int main() { 155 | 156 | Stack* stk = NULL; // Stack for visited addresses 157 | Stack* stk_back = NULL; // Stack for addresses to go back 158 | Queue historyQ; 159 | initializeQueue(&historyQ); 160 | 161 | // push(&stk, "http//.lightoj.com/"); 162 | 163 | printf("\n\nAvailavle comands:\n\n"); 164 | printf("VISIT website_address\n"); 165 | printf("FORWARD\n"); 166 | printf("BACK\n"); 167 | printf("HISTORY\n"); 168 | printf("QUIT\n\n\n"); 169 | 170 | 171 | 172 | char cmnd[10]; 173 | while (scanf("%s", cmnd) == 1 && strcmp(cmnd, "QUIT") != 0) { 174 | if (strcmp(cmnd, "VISIT") == 0) { 175 | getchar(); // Consume the whitespace 176 | char addrs[1024]; 177 | fgets(addrs, sizeof(addrs), stdin); 178 | 179 | addrs[strcspn(addrs, "\n")] = '\0'; // Removing newline 180 | push(&stk,addrs); 181 | enqueue(&historyQ,addrs); 182 | printf("%s\n\n", addrs); 183 | 184 | // Clear the backward stack 185 | while (!isEmpty(stk_back)) { 186 | pop(&stk_back); 187 | } 188 | } else if (strcmp(cmnd, "BACK") == 0) { 189 | if (isEmpty(stk) || stk->next == NULL) { 190 | printf("Ignored\n"); 191 | } else { 192 | push(&stk_back, pop(&stk)); 193 | printf("%s\n\n", stk->data); 194 | enqueue(&historyQ,stk->data); 195 | } 196 | } 197 | else if (strcmp(cmnd, "FORWARD") == 0) { 198 | if (isEmpty(stk_back)) { 199 | printf("Ignored\n"); 200 | } else { 201 | push(&stk, pop(&stk_back)); 202 | printf("%s\n\n", stk->data); 203 | } 204 | } 205 | else if (strcmp(cmnd, "HISTORY") == 0) { 206 | displayReverseQueue(&historyQ); 207 | } 208 | } 209 | 210 | 211 | // while (!isEmpty(stk)) { 212 | // pop(&stk); 213 | // } 214 | // while (!isEmpty(stk_back)) { 215 | // pop(&stk_back); 216 | // } 217 | 218 | 219 | return 0; 220 | } 221 | --------------------------------------------------------------------------------