I need help with C++. I want to create a function that will remove all target nodes in a single linked list.
`Hey,
Note: If you have any queries related the answer please do comment. I would be very happy to resolve all your queries.
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile
and execute it.
*******************************************************************************/
#include <iostream>
#include <stdlib.h>
using namespace std;
// A linked list node
struct Node
{
int data;
struct Node *next;
};
/* Given a reference (pointer to pointer) to the head of a
list
and an int, inserts a new node on the front of the list. */
void push(struct Node** head_ref, int new_data)
{
struct Node* new_node = (struct Node*) malloc(sizeof(struct
Node));
new_node->data = new_data;
new_node->next = (*head_ref);
(*head_ref) = new_node;
}
/* Given a reference (pointer to pointer) to the head of a list
and
a key, deletes all occurrence of the given key in linked list
*/
void deleteKey(struct Node **head_ref, int key)
{
// Store head node
struct Node* temp = *head_ref, *prev;
// If head node itself holds the key or multiple occurrences of
key
while (temp != NULL && temp->data == key)
{
*head_ref = temp->next; // Changed head
free(temp); // free old head
temp = *head_ref; // Change Temp
}
// Delete occurrences other than head
while (temp != NULL)
{
// Search for the key to be deleted, keep track of the
// previous node as we need to change 'prev->next'
while (temp != NULL && temp->data != key)
{
prev = temp;
temp = temp->next;
}
// If key was not present in linked list
if (temp == NULL) return;
// Unlink the node from linked list
prev->next = temp->next;
free(temp); // Free memory
//Update Temp for next iteration of outer loop
temp = prev->next;
}
}
// This function prints contents of linked list starting from
// the given node
void printList(struct Node *node)
{
while (node != NULL)
{
cout<<" "<<node->data<<" ";
node = node->next;
}
}
/* Driver program to test above functions*/
int main()
{
/* Start with the empty list */
struct Node* head = NULL;
push(&head, 7);
push(&head, 2);
push(&head, 3);
push(&head, 2);
push(&head, 8);
push(&head, 1);
push(&head, 2);
push(&head, 2);
int key = 2; // key to delete
cout<<("Created Linked List: ");
printList(head);
deleteKey(&head, key);
cout<<("\nLinked List after Deletion of all nodes with value
2: ");
printList(head);
return 0;
}

Kindly revert for any queries
Thanks.
I need help with C++. I want to create a function that will remove all target...
I want to use netbeans, can you help with the following? Create a structure called as a studentnode that has data and pointer to the next node Create a constructor to initialize the linked list Implement the destructor that should delete the linked list once the program finishes the execution Implement a function to add a new node into the list with value Write a method to print all the values
Hello, I need help with following question; "You want to search a list for a key and return the keys of the two elements that come before it and the keys of the two elements the come after it. Which would be the most appropriate linked list methods to implement this application? double linked list or circular linked list or with header and trailer nodes?
C++ ONLY PLEASE. CAN I GET SOME HELP WRITING THIS HEADER FILE? I MAINLY WANT TO KNOW HOW I WOULD WRITE IT WITH A TEMPLATE. PLEASE AND THANKS IN ADVANCE. **************LinkedList.h requirements************************ linked list Class EXTRA CREDIT OPPORTUNITY: Create the LinkedList class as a template class for 5 extra credit points!!! private memebers Create a structure called ListNode, which should hold a Dinosaur and a pointer to the next ListNode ListNode pointer called head – will eventually point to the...
I need help coding this in C •Your program should start by asking the user how many nodes will be in the network. Nodes should be implemented by a node struct and maintained in a Linked List. •Each node should maintain all packets that have been generated and are ready to be be transmitted (one at a time). Packets should be implemented by a packet struct and maintained in a Linked List.
Write a recursive method remove(int target, LLNode list) that removes all occurrences of target from list and returns a reference to the new list. For our example list the statement values = remove(6, values); would result in values referencing the list containing 3 9 12 15 18 19 19 and 20. If target is not contained in list then the list remains unchanged. Please also add a driver class to demonstrate that the method is working correctly. LLNode.java //---------------------------------------------------------------------------- //...
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...
* C PROGRAMMING* Outcomes: Demonstrate the ability to create and use linked lists in dynamic memory Demonstrate the ability to add nodes and remove nodes from a linked list of structs Program Specifications: Write a program that creates the following struct (you can give it whatever name you want): char name[100]; int age; float weight; Create the following menu system: Add a Record Display All Records Quit When the user selects (1) you will prompt them for a name, age,...
Please help me on all the questions !!!!!!!! Really need help! Will give a thumb up for helping. True/False (13) Chapter 14 - A List Implementation that Links Data Adding a node to an empty chain is the same as adding a node to the beginning of a chain. Adding a node at the end of a chain of n nodes is the same as adding a node at position n. You need a temporary variable to reference nodes as...
I need help with a Java question... A) Create the tree map that should store following strings. Hello Today Is Monday Once you stored all the data in the tree map, then loop thru the tree map and remove things B) Then, Create a set that stores the folling strings. -This -Class -is -good -We -have -learned -lot -of -things. Once you stored all the data in the set/map, then loop thru the set using iterator and remove all the...
I need help with a c++ code, i am new learner on stack, please help me write Stack.cpp according to Stack.h provided, thanks(Notes: That data structure is a singly linked list in which pushed items are placed at the tail of the linked list. Similarly, popped items will be removed from the tail of the list.) Actually,I can write a regular one, but i'm not sure how to use the tail in the question. class Stack { private: // Desc:...