data structure task
data structure task
code : 231335
group : 9
struct Node
{
int data;
Node *next;
Node(int val) : data(val), next(nullptr) {}
};
int main()
{
Node *main = nullptr;
insert(main, 5);
insert(main, -3);
insert(main, 10);
insert(main, -7);
insert(main, 2);
insert(main, -1);
template<typename T>
class Node {
public:
T data;
Node* next;
Node* prev;
Node(T val) {
this->data = val;
this->next = nullptr;
this->prev = nullptr;
}
};
template<typename T>
class DoublyLinkedList {
Node<T>* head;
Node<T>* last;
public:
DoublyLinkedList() {
head = last = nullptr;
}
void display() {
if (head == nullptr) return;
Node<T>* curr = head;
void deleteDuplicates() {
if (head == nullptr) return;
if (temp == last) {
// If the node to delete is the last node
last = last->prev;
last->next = nullptr;
} else {
// If the node to delete is in the middle
temp->prev->next = temp->next;
temp->next->prev = temp->prev;
}
delete temp;
} else {
runner = runner->next;
}
}
curr = curr->next;
}
}
};
int main() {
DoublyLinkedList<int> lst;
lst.push_back(5);
lst.push_back(3);
lst.push_back(5);
lst.push_back(2);
lst.push_back(3);
lst.push_back(1);
cout << "Original Linked List: ";
lst.display();
lst.deleteDuplicates();
return 0;
}
else {
string op(1, str[i]);
string right = infix.top(); infix.pop();
string left = infix.top(); infix.pop();
string s = "(" + left + op + right + ")";
infix.push(s);
}
}
return infix.top();
}
int main() {
cout << prefix_infix("*+AB-CD") << endl;
cout << prefix_postfix("*+AB-CD") << endl;
return 0;
}
class Node {
public:
string Data;
int priority;
Node* next;
Node(string d, int p) {
Data = d;
priority = p;
next = nullptr;
}
};
class PriorityQueue {
Node* head;
int size;
public:
PriorityQueue() {
head = nullptr;
size = 0;
}
~PriorityQueue() {
clear();
}
void clear() {
while (head != nullptr) {
Node* temp = head;
head = head->next;
delete temp;
}
size = 0;
}
bool empty() {
return head == nullptr;
}
int Size() {
return size;
}
void display() {
if (empty()) {
cout << "Queue is empty.\n" << endl;
}
Node* temp = head;
while (temp != nullptr) {
cout << "[" << temp->Data << "," << temp->priority << "]";
temp = temp->next;
}
cout << endl;
}
string pop() {
if (empty()) {
cout << "empty queue\n";
return "";
} else {
Node* temp = head;
head = head->next;
string ret = temp->Data;
delete temp;
size--;
return ret;
}
}
string top() {
return head->Data;
}
};
int main() {
PriorityQueue pq;
pq.push("ABC", 2);
pq.push("XYZ", 1);
pq.push("PQR", 1);
pq.push("RTZ", 3);
pq.push("CBZ", 2);
pq.push("QQQ", 3);
pq.push("XXX", 4);
pq.push("RRR", 1);
pq.display();
return 0;
}