Professional Documents
Culture Documents
Project 2.0 PDF
Project 2.0 PDF
Project 2.0 PDF
} previous = current;
int value; Node* current = head; cout << "Element not found in the linked list.\n";
class LinkedList { cout << "Element found at index " << index << "\n"; Node* current = head;
cout << "Enter the size of the linked list: "; cout << "Element not found in the linked list.\n"; }
for (int i = 0; i < size; ++i) { void deleteElement(int value) { cout << "Element not found in the linked list.\n";
cout << "Enter the element " << (i + 1) << ": "; Node* current = head; }
Node* newNode = new Node; if (current->value == value) { Node* newNode = new Node;
} else { } } else {
Node* current = head; cout << "Enter the size of the array: "; } else {
while (current->next != nullptr) { int size; cout << "Element not found in the array.\n";
} arr.resize(size); }
current->next = newNode; cout << "Enter the elements of the array: ";
cout << "Element added successfully.\n"; cin >> arr[i]; cout << "Enter the value to modify: ";
} } int value;
while (current != nullptr) { cout << "Enter the element to search: "; cout << "Enter the new value: ";
cout << current->value << " "; int searchElement; int newValue;
cout << "\n"; if (it != arr.end()) { cout << "Element modified successfully.\n";
} cout << "Element found at index " << distance(arr.begin(), it) << "\n"; } else {
Node* head; } }
}; }
void displayMenu() { void deleteElement(vector<int>& arr) { cout << "Enter the new value to add: ";
cout << "UTILITY MENU\n"; cout << "Enter the value to delete: "; int newValue;
cout << "1. Linked List Operations\n"; int value; cin >> newValue;
cout << "0. Exit the program\n"; auto it = find(arr.begin(), arr.end(), value); cout << "Element added successfully.\n";
} if (it != arr.end()) { }
arr.erase(it);
void createArray(vector<int>& arr) { cout << "Element deleted successfully.\n"; int main() {
int choice; cin >> newValue; default:
while (true) { list.modifyElement(value, newValue); cout << "Invalid choice. Please enter again.\n";
cout << "1. Create a new linked list\n"; case 4: { cout << " ARRAY MENU\n";
cout << "2. Modify an existing value\n"; int value; cout << "1. Create a new array\n";
cout << "3. Search for an element\n"; cout << "Enter the value to delete: "; cout << "2. Modify an existing value\n";
cout << "4. Delete an element\n"; cin >> value; cout << "3. Search for an element\n";
cout << "5. Add a new element\n"; list.deleteElement(value); cout << "4. Delete an element\n";
cout << "6. Display the linked list\n"; break; cout << "5. Add a new element\n";
cout << "0. Return to main menu\n"; } cout << "0. Return to main menu\n";
cout << "Enter your choice: "; case 5: { cout << "Enter your choice: ";
break; } break;
case 4:
deleteElement(arr);
break;
case 5:
addElement(arr);
break;
case 0:
break;
default:
break;
break;
case 0:
return 0;
default:
break;
return 0;