
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN: 9781337102087
Author: D. S. Malik
Publisher: Cengage Learning
expand_more
expand_more
format_list_bulleted
Question
C++ Thanks!
Example:
"apple"->NULL
return "apple"->NULL
"apple"->"apple"->NULL
return "apple"->NULL
"green"->"green"->"blue"->"red"->"green"->NULL
return "green"->"blue"->"red"->"green"->NULL

Transcribed Image Text:LinkedCompress
Editor
1 node compressCnode* head)
//fill in code here
Problem Statement
4
This problem has you modify a linked lists composed of node objects
chained together via node pointers. Each node has a next pointer which
points to the next node in the chain. The last node is identified by having
a NULL next pointer.
The linked lists for this lab store string data. Some of the strings in the
linked lists repeat, and we'd like to eliminate this repetition. Specifically, if
a string repeats, we want to eliminate the duplicates so that the resulting
linked list only has one copy of a string in a row. (The string can repeat
later in the linked list, as long as some other string occurs in between.)
Create a function compress, which takes in a pointer to the head of the
linked list, and returns a pointer to the head of a linked list in which
repetition has been eliminated
The linked list for this problem uses the following class declaration
class node
public:
string data;
node* next;
d:
Notes and Constraints
The linked list starting at head contains between 1 and 25 nodes,
inclusive
Test
Submit
Expert Solution

Trending nowThis is a popular solution!
Step by stepSolved in 5 steps with 1 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
Complete the following function where a node is perculated through a MaxHeap when given the value of the parent node (through the use of a linked list)
void BinMaxHeap::percolateUp(BHNode *p) {
}
arrow_forward
Linked list. Complete the function that takes as a parameter the head of a linked list and prints the linked list in reverse order. If the linked list had the contents: of,the,and,on,a,an,ok. Then the correct output would be: ok,an,a,on,and,the,of.
Given:
struct node { char word[31];
struct node *prev, next;
};
void print_reverse(struct node *head) {
}
arrow_forward
Use the following node definition for this problem.struct NodeInt32{int32_t value; NodeInt32* next;
}
Write a function which concatenates two non-empty linked lists. Its exact signature should be: void concat(NodeInt32* headA, NodeInt32* headB); After execution, the tail of headA should point to headB.
The skeleton file is below
arrow_forward
Part2: LinkedList implementation
1. Create a linked list of type String Not Object and name it as StudentName.
2. Add the following values to linked list above Jack Omar Jason.
3. Use addFirst to add the student Mary.
4. Use addLast to add the student Emily.
5. Print linked list using System.out.println().
6. Print the size of the linked list.
7. Use removeLast.
8. Print the linked list using for loop for (String anobject: StudentName){…..}
9. Print the linked list using Iterator class.
10. Does linked list hava capacity function?
11. Create another linked list of type String Not Object and name it as TransferStudent.
12. Add the following values to TransferStudent linked list Sara Walter.
13. Add the content of linked list TransferStudent to the end of the linked list StudentName
14. Print StudentName.
15. Print TransferStudent.
16. What is the shortcoming of using Linked List?
arrow_forward
8.14 LAB: Mileage tracker for a runner
Given the MileageTrackerNode class, complete main() to insert nodes into a linked list (using the InsertAfter() function). The first user-input value is the number of nodes in the linked list. Use the PrintNodeData() function to print the entire linked list. DO NOT print the dummy head node.
Ex. If the input is:
3 2.2 7/2/18 3.2 7/7/18 4.5 7/16/18
the output is:
2.2, 7/2/18 3.2, 7/7/18 4.5, 7/16/18
Main.cpp:
#include "MileageTrackerNode.h"#include <string>#include <iostream>using namespace std;
int main (int argc, char* argv[]) {// References for MileageTrackerNode objectsMileageTrackerNode* headNode;MileageTrackerNode* currNode;MileageTrackerNode* lastNode;
double miles;string date;int i;
// Front of nodes listheadNode = new MileageTrackerNode();lastNode = headNode;
// TODO: Read in the number of nodes
// TODO: For the read in number of nodes, read// in data and insert into the linked list
// TODO: Call the PrintNodeData()…
arrow_forward
8.14 LAB: Mileage tracker for a runner
Given the MileageTrackerNode class, complete main() to insert nodes into a linked list (using the InsertAfter() function). The first user-input value is the number of nodes in the linked list. Use the PrintNodeData() function to print the entire linked list. DO NOT print the dummy head node.
Ex. If the input is:
3 2.2 7/2/18 3.2 7/7/18 4.5 7/16/18
the output is:
2.2, 7/2/18 3.2, 7/7/18 4.5, 7/16/18
Main.cpp:
#include "MileageTrackerNode.h"#include <string>#include <iostream>using namespace std;
int main (int argc, char* argv[]) {// References for MileageTrackerNode objectsMileageTrackerNode* headNode;MileageTrackerNode* currNode;MileageTrackerNode* lastNode;
double miles;string date;int i;
// Front of nodes listheadNode = new MileageTrackerNode();lastNode = headNode;
// TODO: Read in the number of nodes
// TODO: For the read in number of nodes, read// in data and insert into the linked list
// TODO: Call the PrintNodeData()…
arrow_forward
8.14 LAB: Mileage tracker for a runner
Given the MileageTrackerNode class, complete main() to insert nodes into a linked list (using the InsertAfter() function). The first user-input value is the number of nodes in the linked list. Use the PrintNodeData() function to print the entire linked list. DO NOT print the dummy head node.
Ex. If the input is:
3
2.2
7/2/18
3.2
7/7/18
4.5
7/16/18
the output is:
2.2, 7/2/18
3.2, 7/7/18
4.5, 7/16/18
Main.cpp
#include "MileageTrackerNode.h"#include <string>#include <iostream>using namespace std;
int main (int argc, char* argv[]) {// References for MileageTrackerNode objectsMileageTrackerNode* headNode;MileageTrackerNode* currNode;MileageTrackerNode* lastNode;
double miles;string date;int i;
// Front of nodes listheadNode = new MileageTrackerNode();lastNode = headNode;
// TODO: Read in the number of nodes
// TODO: For the read in number of nodes, read// in data and insert into the linked list
// TODO: Call the PrintNodeData()…
arrow_forward
8.14 LAB: Mileage tracker for a runner
Given the MileageTrackerNode class, complete main() to insert nodes into a linked list (using the InsertAfter() function). The first user-input value is the number of nodes in the linked list. Use the PrintNodeData() function to print the entire linked list. DO NOT print the dummy head node.
Ex. If the input is:
3
2.2
7/2/18
3.2
7/7/18
4.5
7/16/18
the output is:
2.2, 7/2/18
3.2, 7/7/18
4.5, 7/16/18
Main.cpp
#include "MileageTrackerNode.h"#include <string>#include <iostream>using namespace std;
int main (int argc, char* argv[]) {// References for MileageTrackerNode objectsMileageTrackerNode* headNode;MileageTrackerNode* currNode;MileageTrackerNode* lastNode;
double miles;string date;int i;
// Front of nodes listheadNode = new MileageTrackerNode();lastNode = headNode;
// TODO: Read in the number of nodes
// TODO: For the read in number of nodes, read// in data and insert into the linked list
// TODO: Call the PrintNodeData()…
arrow_forward
Think about the following example: A computer program builds and modifies a linked list like follows:Normally, the program would keep tabs on two unique nodes, which are as follows: An explanation of how to use the null reference in the linked list's node in two common circumstances
arrow_forward
Create a function that will perform the "Remove" operation of nodes in a Linked List.
arrow_forward
In a doubly linked list the first class is Node which we can create a new node with a given element. Its constructor also includes previous node reference prev and next node reference next.
make a node object for the new element. Check if the index >= 0.If index is 0, make new node as head; else, make a temp node and iterate to the node previous to the index.If the previous node is not null, adjust the prev and next references. Print a message when the previous node is null.
implement these 3 methods: insert_at_index(), delete_at_end(), display(). use these three functions above
use this to name the items
1. insert_to_empty_list()2. insert_to_end()3. insert_at_index()
4. delete_at_start()
5. delete_at_end() .
6. display()
let the output be
OUTPUT:
The list is emptyElement is: 3Element is: 10Element is: 20Element is: 30Element is: 35Element is: 38Element is: 40Element is: 50Element is: 60
Element is: 10Element is: 20Element is: 30Element is: 35Element is: 38Element is: 40Element…
arrow_forward
8.16 LAB: Mileage tracker for a runner C++
Given the MileageTrackerNode class, complete main() to insert nodes into a linked list (using the InsertAfter() function). The first user-input value is the number of nodes in the linked list. Use the PrintNodeData() function to print the entire linked list. DO NOT print the dummy head node.
Ex. If the input is:
3 2.2 7/2/18 3.2 7/7/18 4.5 7/16/18
the output is:
2.2, 7/2/18 3.2, 7/7/18 4.5, 7/16/18
Main.cpp
#include "MileageTrackerNode.h"#include <string>#include <iostream>using namespace std;
int main (int argc, char* argv[]) {// References for MileageTrackerNode objectsMileageTrackerNode* headNode;MileageTrackerNode* currNode;MileageTrackerNode* lastNode;
double miles;string date;int i;
// Front of nodes listheadNode = new MileageTrackerNode();lastNode = headNode;
// TODO: Read in the number of nodes
// TODO: For the read in number of nodes, read// in data and insert into the linked list
// TODO: Call the…
arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you

C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning

C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning