data structure
-
Given following definition for singly linked list node and a pointer type:
struct Node {
int num; Node\* next; Node() = delete; Node(int num) : num{ num }, next{ nullptr } {}
};
typedef Node* NodePtr;
Use following prototype:
void quiz2(NodePtr& head1, NodePtr& target, NodePtr& head2)
to design a function that:
Takes in two linked lists, indicated by head1 and head2, and a NodePtr target
Searches target Node in linked list 1 (by comparing address, not by value):
If found, then connect the whole linked list 2 to the target node. In other words, use list 2 to replace nodes after target. Also update head2 to nullptr as the merged linked list should have only one entry point at head1.
If not found, then connect list 2 to the end of list 1, and set head2 to nullptr for the same above reason.For example,
list 1: 10->20->30->40, target is the address of node 20, list 2: 11->12->13, then after calling the function, list 1 should be 10->20->11->12->13.
list 1: 10->20->30->40, target is an address that cannot be found in list 1, list 2: 11->12->13, then after calling the function, list 1 should be 10->20->30->40->11->12->13.When merging, please take care of memory and do not let leak happen. You will be deducted by 10 points if memory leak happens. (Hint: in the first example, what should happen to nodes 30 and 40?)
Submit one .cpp file as your answer to Quiz 2.
Develop your own work and DO NOT CHEAT. Violator will be found, reported, and penalized with F grade for this course.
Attach FileNo file chosen
-
Given following definition for singly linked list node and a pointer type:
struct Node {
int num; Node\* next; Node() = delete; Node(int num) : num{ num }, next{ nullptr } {}
};
typedef Node* NodePtr;
Use following prototype:
void quiz2(NodePtr& head1, NodePtr& target, NodePtr& head2)
to design a function that:
Takes in two linked lists, indicated by head1 and head2, and a NodePtr target
Searches target Node in linked list 1 (by comparing address, not by value):
If found, then connect the whole linked list 2 to the target node. In other words, use list 2 to replace nodes after target. Also update head2 to nullptr as the merged linked list should have only one entry point at head1.
If not found, then connect list 2 to the end of list 1, and set head2 to nullptr for the same above reason.For example,
list 1: 10->20->30->40, target is the address of node 20, list 2: 11->12->13, then after calling the function, list 1 should be 10->20->11->12->13.
list 1: 10->20->30->40, target is an address that cannot be found in list 1, list 2: 11->12->13, then after calling the function, list 1 should be 10->20->30->40->11->12->13.When merging, please take care of memory and do not let leak happen. You will be deducted by 10 points if memory leak happens. (Hint: in the first example, what should happen to nodes 30 and 40?)
Submit one .cpp file as your answer to Quiz 2.
Develop your own work and DO NOT CHEAT. Violator will be found, reported, and penalized with F grade for this course.
Attach FileNo file chosen
Quote:
Develop your own work and DO NOT CHEAT. Violator will be found, reported, and penalized with F grade for this course.
What part of that statement did you not understand?
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
Given following definition for singly linked list node and a pointer type:
struct Node {
int num; Node\* next; Node() = delete; Node(int num) : num{ num }, next{ nullptr } {}
};
typedef Node* NodePtr;
Use following prototype:
void quiz2(NodePtr& head1, NodePtr& target, NodePtr& head2)
to design a function that:
Takes in two linked lists, indicated by head1 and head2, and a NodePtr target
Searches target Node in linked list 1 (by comparing address, not by value):
If found, then connect the whole linked list 2 to the target node. In other words, use list 2 to replace nodes after target. Also update head2 to nullptr as the merged linked list should have only one entry point at head1.
If not found, then connect list 2 to the end of list 1, and set head2 to nullptr for the same above reason.For example,
list 1: 10->20->30->40, target is the address of node 20, list 2: 11->12->13, then after calling the function, list 1 should be 10->20->11->12->13.
list 1: 10->20->30->40, target is an address that cannot be found in list 1, list 2: 11->12->13, then after calling the function, list 1 should be 10->20->30->40->11->12->13.When merging, please take care of memory and do not let leak happen. You will be deducted by 10 points if memory leak happens. (Hint: in the first example, what should happen to nodes 30 and 40?)
Submit one .cpp file as your answer to Quiz 2.
Develop your own work and DO NOT CHEAT. Violator will be found, reported, and penalized with F grade for this course.
Attach FileNo file chosen
wrote:
Develop your own work and DO NOT CHEAT. Violator will be found, reported, and penalized with F grade for this course.
LOL.
CI/CD = Continuous Impediment/Continuous Despair
-
Given following definition for singly linked list node and a pointer type:
struct Node {
int num; Node\* next; Node() = delete; Node(int num) : num{ num }, next{ nullptr } {}
};
typedef Node* NodePtr;
Use following prototype:
void quiz2(NodePtr& head1, NodePtr& target, NodePtr& head2)
to design a function that:
Takes in two linked lists, indicated by head1 and head2, and a NodePtr target
Searches target Node in linked list 1 (by comparing address, not by value):
If found, then connect the whole linked list 2 to the target node. In other words, use list 2 to replace nodes after target. Also update head2 to nullptr as the merged linked list should have only one entry point at head1.
If not found, then connect list 2 to the end of list 1, and set head2 to nullptr for the same above reason.For example,
list 1: 10->20->30->40, target is the address of node 20, list 2: 11->12->13, then after calling the function, list 1 should be 10->20->11->12->13.
list 1: 10->20->30->40, target is an address that cannot be found in list 1, list 2: 11->12->13, then after calling the function, list 1 should be 10->20->30->40->11->12->13.When merging, please take care of memory and do not let leak happen. You will be deducted by 10 points if memory leak happens. (Hint: in the first example, what should happen to nodes 30 and 40?)
Submit one .cpp file as your answer to Quiz 2.
Develop your own work and DO NOT CHEAT. Violator will be found, reported, and penalized with F grade for this course.
Attach FileNo file chosen
The question is: Do you seriously want to learn how to become an IT specialist, who can code, or are you more interested in the party type student life. The problems you want resolved are quite trivial, and I could easily write you the required lines. However, I will not! You seem to be early in your course. I have no doubt that your college provided you with the resources required where you can find out how to write this code. Read it, and Try it out, fail and Learn. Writing Code is about Trying and Learning, the whole time. You write the Code, Compile it. You get Compiling errors. That means that the Compiler does not understood what you wrote. Solve them, it Compiles. Now you have a running program or App. Does the App do what you want it to do! Very Often it does not. They call that Debugging! I learned C and CPP/MFC the hard way. By myself, trial and error. My University simply did not have a computer that students could work with in 1974. My first computer was a Commodore 64 in 1985, where I learned the beginnings of Machine Code and ASM programming. A small PC with a C Compiler came as a godsend, and at the time I was in no doubt what compilers linkers, and debug/retail versions did and could do. You have an institution with resources behind you. Use those resourses and learn. Stop asking this forum to resolve your exam questions.
Bram van Kampen