***CODE MUST BE IN C++***
Using the linked list in "basic linked list" which has a STRUCTURE for each node, write FUNCTION which starts at the head and outputs the value for each node until the last node is reached. Note: your function should work with the structure that is in this program. Please do not use the example which is for a class, but this example canbe helkpful. Also note that the function must work no matter how many nodes are in the list.
// ILLUSTRATES LINKED LIST
// NOTE USING POINTER TO ACCESS
// without naming variable
#include<iostream>
using namespace std;
struct ListNode
{
double value; // data member
ListNode *next; // pointer to next node
// NOTE this is pointer to same struct type
ListNode *prev;
};
int main()
{
ListNode *head; // define pointer to be used as list head
// create first node with data value 12.5
head = new ListNode; // Allocate new node
head->value = 12.5; // store the value
head->next = NULL; // signify end of list
// create second node with data value 13.5
ListNode *secondPtr = new ListNode;
secondPtr->value = 13.5;
secondPtr->next = NULL; // second node is end of list
head->next = secondPtr; // first node points to second node
// print the list
cout<< "First item is "<< head->value<<endl;
cout<< "Second item is "<<head->next->value<<endl;
system("pause");
return }
// ILLUSTRATES LINKED LIST
// NOTE USING POINTER TO ACCESS
// without naming variable
#include<iostream>
using namespace std;
struct ListNode {
double value; // data member
ListNode *next; // pointer to next node
// NOTE this is pointer to same struct type
ListNode *prev;
};
void printList(ListNode * head) {
cout << "List is: ";
while (head != NULL) {
cout << head->value << " ";
head = head->next;
}
cout << endl;
}
int main() {
ListNode *head; // define pointer to be used as list head
// create first node with data value 12.5
head = new ListNode; // Allocate new node
head->value = 12.5; // store the value
head->next = NULL; // signify end of list
// create second node with data value 13.5
ListNode *secondPtr = new ListNode;
secondPtr->value = 13.5;
secondPtr->next = NULL; // second node is end of list
head->next = secondPtr; // first node points to second node
// print the list
cout << "First item is " << head->value << endl;
cout << "Second item is " << head->next->value << endl;
printList(head);
system("pause");
return 0;
}
***CODE MUST BE IN C++*** Using the linked list in "basic linked list" which has a...
Programming in C: I am trying to modify this linked list to be doubly linked list. I’m also trying to add a print in reverse function. I’m really struggling with how to change the insert function to doubly link the nodes without effecting the alphabetical sorting mechanism. Example of desired output: Enter your choice: 1 to insert an element into the list. 2 to delete an element from the list. 3 to end. ? 1 Enter a character: a The...
#include <iostream> using namespace std; struct ListNode { float value; ListNode *next; }; ListNode *head; class LinkedList { public: int insertNode(float num); void deleteNode(float num); void destroyList(); void displayList(); LinkedList(void) {head = NULL;} ~LinkedList(void) {destroyList();} }; int LinkedList::insertNode(float num) { struct ListNode *newNode, *nodePtr = head, *prevNodePtr = NULL; newNode = new ListNode; if(newNode == NULL) { cout << "Error allocating memory for new list member!\n"; return 1; } newNode->value = num; newNode->next = NULL; if(head==NULL) { cout << "List...
C++ Consider the following structure of node and linked list. struct Node { int key; Node *next; }; 10 -> 20 -> 30 -> 10 -> 10 -> 50 -> 10 -> NULL What will be the output of following pseudo-code? Consider head is the pointer to the first node of above linked list. Node *walker = head; int count = 0; while(walker!= NULL && count < 3) { if(walker->key == 10) { count = count + 1; } walker...
Working in C++, Complete the code. // Lab 9 code /* Insert leading comments with your name and the date. Describe the purpose of the code. Also, list each pointer and describe how it is used to enable the selection sort for the linked list structure. */ /* Insert code as described by the comments. */ /* Add comments to each line of code that uses a pointer, describing how it is being used. */ #include <iostream> using namespace std;...
Design and implement your own linked list class to hold a sorted list of integers in ascending order. The class should have member function for inserting an item in the list, deleting an item from the list, and searching the list for an item. Note: the search function should return the position of the item in the list (first item at position 0) and -1 if not found. In addition, it should member functions to display the list, check if...
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...
Please fill in this code to reverse a linked list: (written in C/C++) #include #include #include using namespace std; /* Link list node */ struct Node { int data; // your code here }; /* Function to reverse the linked list */ static void reverse(struct Node** head_ref) { // your code here } /* Function to push a node */ void push(struct Node** head_ref, int new_data) { // your code here } /* Function to print linked list */ void...
Please fill in the code to reverse a linked list. IN C++ #include <stdio.h> #include <stdlib.h> #include <iostream> using namespace std; /* Link list node */ struct Node { int data; // your code here }; /* Function to reverse the linked list */ static void reverse(struct Node** head_ref) { // your code here } /* Function to push a node */ void push(struct Node** head_ref, int new_data) { // your code here } /* Function to print linked list...
In C++, change this code to a circular linked list #include <iostream> using namespace std; struct node { string data; node *next; }; class linked_list { private: node *head,*tail; public: linked_list() { head = NULL; tail = NULL; } void add_node(string n) { node *tmp = new node; tmp->data = n; tmp->next = NULL; if(head == NULL) { head = tmp; tail = tmp; } else { tail->next = tmp; tail = tail->next; } } void display() { while (tmp...
Design and implement your own linked list class to hold a sorted list of integers in ascending order. The class should have member function for inserting an item in the list, deleting an item from the list, and searching the list for an item. Note: the search function should return the position of the item in the list (first item at position 0) and -1 if not found. In addition, it should member functions to display the list, check if...