/* * List.h file */ #include <iostream> using namespace std; struct NodeType { int data; NodeType *next; }; class List { private: NodeType *front, *rear; public: List(); void getList(); void addNodeLast(int val); NodeType* getFront() { return front; } NodeType* getRear() { return rear; } }; /* List.h file ends here */ /* * List.cpp file */ #include "List.h" List :: List() { front = NULL; rear = NULL; } void List :: getList() { NodeType *ptr = new NodeType; ptr = front; while (ptr != NULL) { cout << ptr->data << " "; ptr = ptr->next; } } void List :: addNodeLast(int val) { NodeType *newNode = new NodeType; newNode->data = val; newNode->next = NULL; if (front == NULL) { front = newNode; rear = newNode; newNode = NULL; } else { rear->next = newNode; rear = newNode; } } /* List.cpp file ends here */ /* * Main.cpp file */ #include <iostream> #include <cstdlib> #include <ctime> using namespace std; #include "List.h" List getSubset(List M, int N) { List sub; NodeType *ptr = new NodeType; ptr = M.getFront(); while (N--) { sub.addNodeLast(ptr->data); //cout << ptr->data << " "; ptr = ptr->next; } return sub; } int main() { List M, N, subset; srand(time(NULL)); for (int i = 0; i < 10; i++) { M.addNodeLast(rand()%25 + 18); } cout << "Linked List M: "; M.getList(); cout << endl; for (int i = 0; i < 6; i++) { N.addNodeLast(rand()%25 + 18); } cout << "Linked List N: "; N.getList(); cout << endl; // calling functions from question 2 int subLen = 4; subset = getSubset(M, subLen); cout << "Subset of M with subset length " << subLen << ": ";subset.getList(); // calling functions from question 3 return 0; } /* Main.cpp file ends here */
Note: This part is done, with all the necessary parts (1, 2, and 4). Please upload the 3rd question. I will do it for you.
in c++ only. second part of the first question. M is a linked list. this question as well as 3 and 4 are built off of question 1. 2. Write a function definition to create a new list. sub, that i...
write the function definition to create a linked list of 8 nodes that contain randomly generated characters between .с. 99) and· 119). The function should return t new linked list. (HINT: keep in mind the member function defined in question 2). 3.
In C++ - Learn how to implement linked lists Part 1 Node and Linked List Class (50 pts): Create node with public properties: Block type block and block ptr next. Create a linked list class that uses the node you generated without an add or delete method with a head and optional tail and counter. Make a driver that generates a node to test your implementation. Part 2 Add Method (30 pts): Create an add method in your linked list...
a) 7% Define a function (the function definition only) named combine_lists that receives two lists of integers (the function has 2 parameters). You can assume that each list is the same length and each list is not empty. The function will create a new list which is composed of the addition of each element of the two lists. The function returns the new list. For example, if the function is sent this list: [2,4,6,8,10] and this list: [5,6,7,8,9] then the...
Write a C++ function to add a node to the beginning of a linked list. Your function takes two arguments - the head of the linked list and the value num to be added. Note that the list may be empty! Your function should modify the head of the linked list to point to the new node, and set the new node to point to the rest of the list (if not empty). Example: Initial Array: 4->2->3, key = 5...
Draw a sketch of a singly linked list containing the following int values: 3, 1, 4, 1, 5. The 3 should be at the front of the list. Remember to sketch the head pointer, each node, and each node's next pointer. 2. Write the code for the following new member function for our SinglyLinkedList class. You should write out the definition of the function, but do not need to write out all of the rest of the class. Your code...
Simple singly-linked list question: write an iterative function position(p, target) that returns position (1, 2, 3, or .......) of the target in the list to which p points. If target is not on the list the function returns -1. please write the function in C++ thanks
I need this in C++. This is all
one question
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...
The question I want answered is in C++. How can I pass a value to a function and create a new linked list out of it? For example I have: void getIntegerInput(List<int> list) { int s; std::cout << "Type a positive integer then click enter to add it to the linked list\n"; std::cout << "Type -1 to stop\nType -2 to delete an item from the list\n"; std::cin >> s; while (s != -1) { if (s == -2) { int...
1. Create a class MLL, a singly linked, non-circular list where each node only has one link next and the list has a head and a tail link (think about implementation of node). The MLL class also implements the Iterable interface. The following should be implemented as well: 2. Add the methods to the MLL class: a. iterator() to implement the Iterable interface. This method returns an instance of MLLI initialized appropriately. b. addFirst( value) that adds a value to...
Problem 1 Given a linked list of integers, write a function getUnique that removes all duplicates elements in the linked list and returns the new linked list of unique elements (The order does not matter). Example: Input: 1-»2->3->1-2 Output: 1->2->3 public class Node f int iterm Node next; Node(int d) t item = d; next-null; ) import java.util.ArrayList; public class ExtraLab public static void main (String[] args)t PROBLEM 1 System.out.println("PROBLEM 1"); Node head new Node(1); head.next-new Node (2); head.next.next-new Node(3);...