Using a class template, write a linked list with 5 nodes and print the linked list. Then make a second linked list with the values from the first linked list and reverse the values and print. (C++)
// do comment if any problem arises
// code
#include <iostream>
using namespace std;
template <class T>
struct node
{
T data;
node *next;
};
template <class T>
class LinkedList
{
public:
// head of linked list
node<T> *head;
// default constructor
LinkedList()
{
head = NULL;
}
// insert at top of list
void insert(T item)
{
node<T> *temp = head;
head = new node<T>;
head->data = item;
head->next = temp;
}
// print list
void print()
{
node<T> *temp = head;
while (temp != NULL)
{
cout << temp->data << " ";
temp = temp->next;
}
cout << endl;
}
};
template <class T>
// this function inserts element in given list in reverse order
void reverse(LinkedList<T> from, LinkedList<T> &to)
{
node<T> *temp = from.head;
while (temp != NULL)
{
to.insert(temp->data);
temp = temp->next;
}
}
int main()
{
// create linkel list with 5 elements
LinkedList<int> testing;
testing.insert(4);
testing.insert(1);
testing.insert(34);
testing.insert(98);
testing.print();
// create list with reverse
LinkedList<int> reverse_list;
reverse(testing, reverse_list);
cout << "After reverse: ";
reverse_list.print();
}
Output:

Using a class template, write a linked list with 5 nodes and print the linked list....
Write a C++implementation of a doubly linked list class using a template class representation for a node and using pointers.In its public API provide functions to insert,find, delete, get size and get position of an element. Write C++ code to show those functions work as expected. (MUST COMPILE AND RUN)
c++ only Program 2: Linked List Class For this problem, let us take the linked list we wrote in a functional manner in a previous assignment and convert it into a Linked List class. For extra practice with pointers we’ll expand its functionality and make it a doubly linked list with the ability to traverse in both directions. Since the list is doubly linked, each node will have the following structure: struct Node { int number; Node * nextNode;...
Write a Java class myLinkedList to simulate a singly linked list using arrays as the underlying structure. Include the following methods: 1. insert an element within the linked list.(this should also work for the front and the rear of the list) 2. Remove an element from the linked list 3. Display (print) the elements of the linked list in order. 4. A method to check if the list is "empty". Test your solution using a linked list that initially has...
a. Using C++, define a node structure of the linked list (e.g. value is an integer, next is a node type pointer), construct a linked list of 10 nodes and assign random numbers as the nodes’ values. Use loop to track and print from the first node to the last and output all nodes’ values. Finally, free all memories of the linked list.
Write a function to implement linked list consisting of five nodes. Store the data in the nodes in the order given below. Also, write a function to display the data stored in the implemented linked list. in C++ programming George, Paul, Ross, Joe, Elaine, Robert1 Insert three nodes in between second node and third node in the linked list that you implemented in problem 1. Store the following data in the new (inserted) nodes in the following order. (You have...
use python
In class, we've studied Singly-Linked Lists which are made of nodes that point at subsequent nodes. One of the biggest annoyances with Linked Lists is the difficulty of going backwards through a list (such as getting the previous node or traversing the list backwards). An intuitive solution to this inefficiency is the doubly-linked list, which adds pointers to previ- ous nodes. Doubly-Linked Lists are not very different from Singly-Linked Lists, but are far more common because they are...
use python
In class, we've studied Singly-Linked Lists which are made of nodes that point at subsequent nodes. One of the biggest annoyances with Linked Lists is the difficulty of going backwards through a list (such as getting the previous node or traversing the list backwards). An intuitive solution to this inefficiency is the doubly-linked list, which adds pointers to previ- ous nodes. Doubly-Linked Lists are not very different from Singly-Linked Lists, but are far more common because they are...
use python
In class, we've studied Singly-Linked Lists which are made of nodes that point at subsequent nodes. One of the biggest annoyances with Linked Lists is the difficulty of going backwards through a list (such as getting the previous node or traversing the list backwards). An intuitive solution to this inefficiency is the doubly-linked list, which adds pointers to previ- ous nodes. Doubly-Linked Lists are not very different from Singly-Linked Lists, but are far more common because they are...
Using the provided Linked List template, add the following recursive functions and demonstrate them in a separate cpp file. Write a recursive function to print the list in order. Write a recursive function to print the list in reverse order. Write a recursive function to print every other node in the list in order. Write a recursive function to return the number of nodes in the list. Write a Boolean function that implements the recursive version of sequential search. THIS...
Using C++ language, Design and implement a class representing a doubly linked list. The class must have the following requirements: The linked list and the nodes must be implemented as a C++ templates The list must be generic – it should not implement arithmetic/logic functions. (template class) It must include a destructor and a copy constructor It must include methods to insert at the front and at the back of the list It must include a method to return the...