above in the image is a linked
list with 2 nodes. You can use this or write a similar one. The
assignment is to write 2 functions. One function will add another
node at the end of the list. The other function will delete a node.
Don't forget - No dangling pointers
C++ language
Make sure its corect and runs without errors and I promise to give you a thumbs up.
#include <iostream>
using namespace std;
class Node {
int data;
Node* next;
public:
void setdata(int d) { data = d; }
void setnext(Node* p) { next = p; }
int getdata() { return data; }
Node *getnext() { return next; }
};
void add(Node **head, int data) {
Node *n = new Node;
n->setdata(data);
n->setnext(NULL);
if(*head == NULL) {
*head = n;
} else {
Node *temp = *head;
while(temp->getnext() != NULL)
{
temp =
temp->getnext();
}
temp->setnext(n);
}
}
void remove(Node **head, int data) {
if(*head != NULL) {
if((*head)->getdata() == data)
{
*head =
(*head)->getnext();
} else {
Node *temp =
*head;
while(temp->getnext() != NULL) {
if(temp->getnext()->getdata() == data)
{
Node *d =
temp->getnext();
temp->setnext(temp->getnext()->getnext());
delete d;
break;
}
temp = temp->getnext();
}
}
}
}
void print(Node *head) {
Node *temp = head;
while(temp != NULL) {
cout << temp->getdata()
<< " -> ";
temp = temp->getnext();
}
cout << endl;
}
int main()
{
Node *head = NULL;
add(&head, 5);
add(&head, 3);
add(&head, 1);
add(&head, 7);
add(&head, 6);
cout << "Initial linked list: ";
print(head);
remove(&head, 5);
remove(&head, 7);
cout << "Linked list after removing 5 and
7: ";
print(head);
return 0;
}

above in the image is a linked list with 2 nodes. You can use this or...
PLEASE USE C++ Source Code
Attached is a linked list with 2 nodes. You can use this or
write a similar one. The assignment is to write 2 functions. One
function will add another node at the end of the list. The other
function will delete a node. Don't forget - No dangling pointers
!
Example linked source code attached below
#include<iostream>
using namespace std;
class Node
{
int data;
Node *next;
public:
void setdata(int d) {data = d;}
void...
You are given the code for a singly linked list-based implementation of the List ADT. You will add a function called isUnique( ) to the List class such that the function will return true if all the integer elements in the List are unique and return false otherwise. The main function is written in such a way that it will create 1000 Lists (each of size listSize) of random integers in a range [1...maxValue] and will call the isUnique function...
Please answer in C++ Derive a class called Queue from the linked list described in Assignment 2 (list of Dates). This means the Queue class will inherit all the properties (data and functions) of the linked list. But, since a queue allows pushing only at the back and popping at the front of the list, you will need to prevent the addition in the front and removal at the back. To do this, you must derive the Queue class in...
Please answer in C++. Derive a class called Stack from the linked list described in Assignment 2 (list of Dates). This means the Stack class will inherit all the properties (data and functions) of the linked list. But, since a stack only allows pushing and popping at the front of the list only, you will need to prevent the operations at the back. To do this, derive the Stack class in such a way that the base class (LinkedList) functions...
C++ program: Convert the classes to template classes #include <iostream> #include <string> using namespace std; class Node { private: int data; Node* next; public: Node(int data) { this->data=data; this->next = 0; } int getData(){return data;} Node* getNext(){return next;} void setNext(Node* next){this->next=next;} }; class LinkedList { private: Node* head = 0; public: int isEmpty() {return head == 0;} void print() { Node* currNode = head; while(currNode!=0) { cout << currNode->getData() << endl; currNode = currNode->getNext(); } } void append(int data) {...
C++: I need implement this code using Double Linked List using the cosiderations 1. head point to null in an empty list 2. There is not need of a tail pointer /*This class implements the singly linked list using templates Each list has two attributes: -head: first node in the list -tail: last node in the list #include "circDLLNode.h" template class { public: //Default constructor: creates an empty list (); //Destructor: deallocate memory ~(); ...
Question: SWAPPING NODES IN A SINGULARLY LINKED LIST: I am attempting to create a program that swaps 2 nodes (no matter where they are in the list) and am having some difficulty. I can't seem to figure out why this swap method is throwing an error. Code: (SWAPPING METHOD AND TEST LINE BOLDED) package linkedlists; public class SinglyLinkedList<E> implements Cloneable { //---------------- nested Node class ---------------- /** * Node of a singly linked list, which stores a reference to its...
iImplement a Singly Linked List detectLoop in Java, it would check whether the linked list contains a loop. Print true if yes, false if not. Test by using the following code: LL<Integer> L = new LL<>(); for (int i = 1000; i > 0; i-=3) sl.add(i); try { L.insert(122, L.getNode(70), L.getNode(21)); if (L.detectLoop()) System.out.println("True"); else System.out.println("False."); } catch(Exception e){ e.printStackTrace(); } class Linkedlist<E>{ private static class Node<E>{ private E element; private Node<E> next; public Node(E e, Node<E> n){ element =...
Need help completing my instance method for deleteFront() as specified below To the class IntegerLinkedList, add an instance method deleteFront such that … Method deleteFront has no input. Method deleteFront returns … an empty Optional instance if the list is empty an Optional instance whose value is the integer that was deleted from the front of the list, otherwise Hints https://docs.oracle.com/javase/10/docs/api/java/util/Optional.html import java.util.Optional; public class IntegerLinkedList { private IntegerNode head ; private int numberOfItems ; public int getNumberOfItems() { return...
Doubly Linked List The assignment is to modify the below code in any way (like changing the method of a function). Time complexity is omitted. Any methods/functions below could be changed into something different. I was thinking of changing the method of getting size of list and maybe change from numbers to letters for nodes. import java.util.Scanner; /* Class Node */ class Node { protected int data; protected Node next, prev; /* Constructor */ public Node() { next = null;...