Question: Linked Lists Problem I have a class node, which contains data and a value. I would like to create objects of my Node class and

Linked Lists Problem

I have a class node, which contains data and a value.

I would like to create objects of my Node class and put them into a Linked List.

I have trouble making my: Insert, Remove, Print and get value functions

template class Node { public: Node(const T& data = T(), int value = 0, Node* next = nullptr) : data(data), value(value), next(next) {} T data; int value; Node* next; };

Here is my LinkedList Class:

template class Queue { public:

// PRECONDITION: None // POSTCONDITIONCONDITION: The queue is empty Queue() { head = NULL; // Empty list with no objects. }

void headInsert(T data, T value) { head = new Node(data, value, head); // head pointer assignment. }

// PRECONDITION: value > 0 // POSTCONDITION: Object of Node, which contains (data,value) has been inserted void insert(const T& data, int value) { if (value > 0) { Node* next = tail->next; tail->next = new Node(data, value, next); // Insertion of new Node } }

// PRECONDITION: None // POSTCONDITION: I search for data, and delete the object which contains that value of data. void remove(const T& data) { if (tail == NULL) return; if (tail->next == NULL) return;

//... }

// PRECONDITION: None // POSTCONDITION: Prints out all objects in the Linked List void print() { }

// PRECONDITION: - // POSTCONDITION: - Returns the "value" that correspons with the data. int getvalue(const T& data) const { return 0; }

// PRECONDITION: - // POSTCONDITION: Returns 'true if the queue is empty, 'false' otherwise bool isEmpty() const { if (head == NULL) return true; return false; }

~Queue() { while (!isEmpty()) remove(head->data); }

private: Node* head; };

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!