Professional Documents
Culture Documents
#include <iostream>
struct Node {
int data;
Node* next;
};
if (current->data == key) {
current = current->next;
newNode->data = item;
newNode->next = *head;
*head = newNode;
}
// Function to display the linked list
current = current->next;
int main() {
insert(&head, 10);
insert(&head, 20);
insert(&head, 30);
insert(&head, 40);
insert(&head, 50);
display(head);
cout << key1 << " is found in the linked list." << endl;
} else {
cout << key1 << " is not found in the linked list." << endl;
endl;
if (search(head, key2)) {
cout << key2 << " is found in the linked list." << endl;
} else {
cout << key2 << " is not found in the linked list." << endl;
return 0;
#include <iostream>
struct Node {
int data;
Node* next;
};
// Function to search for an element in the linked list using binary search
int length = 0;
length++;
end = start;
start = start->next;
start = head;
int low = 0;
start = start->next;
if (start->data == key) {
} else {
newNode->data = item;
newNode->next = *head;
*head = newNode;
current = current->next;
int main() {
Node* head = nullptr;
insert(&head, 10);
insert(&head, 20);
insert(&head, 30);
insert(&head, 40);
insert(&head, 50);
display(head);
if (binarySearch(head, key1)) {
cout << key1 << " is found in the linked list." << endl;
} else {
cout << key1 << " is not found in the linked list." << endl;
if (binarySearch(head, key2)) {
cout << key2 << " is found in the linked list." << endl;
} else {
cout << key2 << " is not found in the linked list." << endl;
return 0;
}