Create a node structure

Assignment Help Data Structure & Algorithms
Reference no: EM131145357

The task for this problem is:

1) Create a Node structure. Initialize the number variable to -1 and the nextNode pointer to nullptr.

2) Add the even numbers between 0 and 40 to the list. Your list will therefore have 20 numbers in it at that point.

3) Display the list by using the displayList() function. 4) Go through the list and insert the odd numbers into their appropriate places by using the insertAfter() function. 5) Display the list again. 6) Delete the list.

These are my functions for the task:

1) Node * addNodeToEnd (Node * lastNode, int num); This function will add a node to the end of the list and return a pointer to it. lastNode will hold a pointer to the current last node in the list. The new node should be dynamically allocated inside the function (which means, of course, that all nodes will have to be deleted later) and inserted after lastNode.

The variable number should be set to num. The nextNode pointer should be set to nullptr.

2) void displayList (Node * firstNode); This function will display the elements of the list, ten numbers per line, each one in a five byte field. It makes no change to the list.

3) int getNumOfElements (Node * firstNode); This function should traverse the list, count how many elements are in it, and return that number. (Note that the end of the list can be detected by the presence of the nullptr.) You should not count the dummy node at the beginning as an element in the list. (If the dummy node is all that is there, then the size of the list is 0.)

4) At least one of the following functions. Either one or both will suffice. You can choose as needed.

a) Node * getElemAtPos (int pos); This function should return a pointer to the element at position pos. The function should call the getNumOfElem() function before it accesses the list. If pos is out of range, it should print an error message and return nullptr. If pos is within range, the function should return a pointer to the correct element.

b) Node * getNodeWithValue (int value); This function should traverse the list and return a pointer to the first element that has the value value. If value is not in the list, it should return a nullptr.

5) Node * insertAfter (Node * currNode, int num); This function will insert a new node into the list immediately after the node pointed to by currNode.

The new node should be dynamically allocated. The function will set the number value of the next node to num and return a pointer to the new node. That pointer can be used for the next insertion.

6) void deleteList (Node * firstNode); This function will traverse the entire list, deleting each element in turn. It is an essential cleanup function that will be executed when everything else is done. function node is this: struct Node { int number; Node * nextNode; };

Reference no: EM131145357

Questions Cloud

Was there anything unethical about the presidents actions : Riverside Automotive Corp. is a medium-sized wholesaler of automotive parts. It has 10 stockholders who have been paid a total of $1 million in cash dividends for 8 consecutive years.
Describe how socioeconomic status affects health care : Socioeconomic status influences health and drives diversity in the context of health disparities. Based on readings provided, describe how socioeconomic status affects health care. Can diversity in the health care workforce promote better health c..
Importance of quality partnering and strategic alliances : Discuss the importance of quality partnering and strategic alliances. Discuss the various forms of quality partnering and strategic alliances. Discuss the importance of quality culture
How you would implement the planning process : Provide an example of a negotiation situation from the experience, where one of the four ways directly impacted the selection of your strategy. Analyze how you would implement the planning process into a negotiation situation to achieve your goals
Create a node structure : Create a Node structure. Initialize the number variable to -1 and the nextNode pointer to nullptr - Add the even numbers between 0 and 40 to the list. Your list will therefore have 20 numbers in it at that point.
Identify the current ideas about how diversity : Review studies of health disparities driven by socioeconomic status, as well as the module resources. Identify the current ideas about how diversity in socioeconomic status is measured, what the different predictors of health are, gaps in current ..
What is the expected value of a pull on the slots : Casinos advertise a 95% payback for their slot machines. This means that for a $1 stake, a gambler can expect to get 95 cents back. a) What does 95% payback mean in terms of the expected value of a play on the slot machines? i.e. What is the expected..
What happens to the expected real interest rate : What happens to the expected real interest rate? Explain why the subsequent path of the real exchange rate satisfies the real interest parity condition.
Identify the three most important consumer factors : Iidentify the three most important consumer factors you think are relevant to the customers of your product or service offering. Explain your choices.

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Write a program using bubble sorting

Question :-Write a program using bubble sorting.

  What are some likely future uses and enhancements

Describe a specific web or mobile application'spurpose. How is it used? What changes has it brought about to its users? What are some likely future uses and enhancements

  Compare network-based and host-based ids use in enterprise

Compare and contrast network-based and host-based IDS use in an enterprise. Determine the feasibility and necessity of utilizing one of these IDS implementations over the others.

  Analyze the time-space complexity of algorithms

How a vEB tree can be used to support these three operations and analyze the time/space complexity of your algorithms.

  Define a path between two vertices

Define a path between two vertices. What is a simple path? What is a cycle? What is a simple cycle? What is a complete graph? What is a self edge? What is a weighted graph? What are two differences between a directed graph and an undirected graph

  Create a flowchart to show the process that will allow the

1.create a flowchart to show the process that will allow the implementation of stack push and pop operations.2.create a

  Design the logic that merges the two files

Design the logic that merges the two files to produce one combined name-and-address file, which the office staff can use for addressing mailings of the practice's monthly Healthy Lifestyles newsletter

  Create a pda with 2 stacks

Create a PDA with 2 stacks. The first stack is preloaded with data (example below), the data input consists of 1 & 0 as well. Your PDA should process the input data, adding the binary string to the values in the first stack and storing the result in ..

  Why are data analysis skills and thinking so important

Why are data analysis skills and thinking so important to spend analysis. Can't software applications be used to generate the information needed automatically

  Determine complete list of nodes which ancestor

Let the following tree: tree a. Determine the children of Q? b. What is the complete list of nodes which have D as ancestor? c. Determine the height of this tree (as height is defined in text)?

  Implement iterative version of algorithm heapify

Using any programming language to implement iterative version of algorithm HEAPIFY. Show your algorithm by running it on the array that contain your name characters.

  Explain feasibility analysis for jobs of lrt algorithm

Study feasibility analysis for jobs of LRT algorithm when preemption is allowed. Which scheduling algorithm is best suited for high speed networks and why? Distinguish between static and dynamic systems.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd