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

  Features of a database view

Does a view occupy space in the database? In other words, does a view contain any data

  Write an algorithm to count nodes in a linked list

storage pool and that there is a special null value. Write an algorithm to count the nodes in a linked list with first node pointed to by first."

  Which data is at the bottom of the heap

Which data is at the bottom of the heap - Now remove the 2, 3, and 4, from your heap in above question, then which data is at the root:?

  Using java, design and implement an api euclidean graph

Using Java, design and implement an API EuclideanGraph for graphs whose vertices are points in the plane that include coordinates.

  Calculate and display the cost per kilogram

You will need to design an application that will receive the weight of a parcel and calculate and display the cost per kilogram and the delivery charge for that parcel

  Solving information technology question

XYZ Corporation has a small office with eighty users in California. The office employs a file and print server that caters to user requests.

  Database design activities

Assume Ray wishes to start a DVD rental program at his stores that he plans to call Henry's DVD Club. He refers to each of his consumers as members.

  Create two function for converting between units of distance

It's often necessary to convert between units. In this exercise, you will create two functions for converting between units of distance. The first function will be called ConvertMilesToKilometers(), which will accept one parameter for the number o..

  Write down an algorithm draw a flow chart and write a java

write an algorithm draw a flow chart and write a java program to accept integer values from keyboard and will find and

  Create a presentation describing the data types

Create a 10-12 slide presentation describing the data types. Include the following in your presentation: Introductory slide AND Slide for each data type

  Algorithm to take input m constraints over n variables

For instance, the constraints x1 = x2, x2 = x3, x3 = x4, and x1 6= x4 cannot be satis fied. Give an efficient algorithm that takes as input m constraints over n variables and decides whether the constraints can be satis fied.

  Finding median by black-box worst-case linear-time algorithm

Given a black-box worst-case linear-time algorithm for ?nding median, create algorithm solving the selection problem for an arbitrary order statistic.

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