c++
Goal:
Learn how to use class and struct to construct a linkedlist.
Learn how to new and delete object. (Dynamic memoryallocation)
Requirement:
Please use the skeleton code below to implement a class formanipulating linked lists.
#include <iostream>
using namespace std;
struct ListNode {
int data;
ListNode *next;
ListNode(int x) : data(x),next(nullptr) {}
};
class LinkedList {
private:
ListNode *head = nullptr;
ListNode *tail = nullptr;
public:
void addNode(int x)
{
/// Add code here
/// Add a node to the list
/// 1. If the list is empty, create thehead node.
/// 2. If the list exists, add the nodeto the tail.
}
void addNodeToSortedList(int x)
{
/// Add code here
PayPal Gateway not configured
PayPal Gateway not configured