code
code
CODES
return;
} }
LINKED LISTS void remove_head(Node** head_ref) { Node* tail = head;
if (*head_ref == NULL) { while (tail->next != NULL) {
Single
STACK struct Node {
cout << "Underflow\n"; tail = tail->next;
#include <stack> return; }
int data;
stack<int> stack; } cout << "Head=" << head->data << ",
Node* next;
stack.push(num); Node* temp = *head_ref; Tail=" << tail->data << ", ";
stack.pop() };
*head_ref = (*head_ref)->next; Node* current = head;
stack.empty() void insert_front(Node** head_ref, int
delete temp; while (current != NULL) {
stack.top() key) {
} cout << current->data;
stackname1.swap(stackname2) Node* new_node = new Node();
void remove_element(Node** head_ref, int if (current->next != NULL) {
mystack.emplace(1); new_node->data = key;
key) { cout << " ";
QUEUE new_node->next = *head_ref;
Node* current = *head_ref; }
*head_ref = new_node;
#include <queue> Node* prev = NULL; current = current->next;
queue<int> gquiz; }
}
gquiz.push(10); void insert_back(Node** head_ref, int key)
gquiz.size(); { if (current != NULL && current->data cout << "\n";
gquiz.front(); == key) { }
Node* new_node = new Node();
gquiz.back(); *head_ref = current->next;
new_node->data = key;
gquiz.pop(); delete current;
new_node->next = NULL; int main() {
g.front();
return; Node* head = NULL;
g.empty(); if (*head_ref == NULL) {
queue1.swap(queue2); } int choice, key, v;
*head_ref = new_node;
while (current != NULL && current- cout << "Press 1 to insert at front\n";
PRORITY QUEUE return;
>data != key) {
cout << "Press 2 to insert at back\n";
}
priority_queue<int> pq; prev = current;
Node* current = *head_ref; cout <<"Press 3 to insert after a node\n";
current = current->next;
DEQUE while (current->next != NULL) {
}
cout << "Press 4 to update a node\n";