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

  Computing time complexity of procedure

What is the time complexity of the procedure? If A[l .. r] = [24, 30, 09, 46, 15, 19, 29, 86,78], what is the output?

  Coefficients of algorithm and negative coefficient mean

How could you utilize the larger grid size and longer time step? Write down the coefficients of your algorithm? What would negative coefficient mean?

  For what values of d is the tree t

For what values of d is the tree T of the previous exercise an order -d B-tree? HINT: The definition of an order- d  deals with the minimum and maximum number of children an internal node can have.

  What is the primary disadvantage of quick sort

What is the primary disadvantage of Quick Sort? How could this disadvantage be eliminated? What is an advantage of bubble sort over selection sort? What is an advantage of selection sort over bubble sort?

  What is the running time of quicksort

What is the running time of QUICKSORT when all elements of array A have the same value - Why do we analyze the expected running time of a randomized algorithm and not its worst-case running time?

  What is the minimum number of attendants

A nursing home employs attendants who are needed around the clock. Each attendant is paid the same, regardless of when his or her shift begins. Each shift is 8 consecutive hours.

  Sort the array 15 80 35 25 60 30 into descending order

The above algorithm has a fundamental flaw. As written, how does it change theArray?

  Find the minimum cost path from a designated node

Find the Minimum Cost Path from a designated start node to a designated destination node in a graph.

  Program method that track the true runtime of your algorithm

Program a method or class that will track the true runtime of your algorithm. Find the true runtime of your algorithm using arrays of varying sizes.

  Exact bounds for distributed graph colouring

Exact bounds for distributed graph colouring and Prepare an abstract for your final project - Emphasis is not on length but rather on quality of the final product.

  Find the minimum cost path from a designated start node to

find the minimum cost path from a designated start node to a designated destination node in a graph.assumptions bull

  Determining worst-case time complexity

The recent discovery of the following fragment of uncommented procedural C code in the Sunlab has caused a big scandal. What is the worst-case time complexity of foo(a,1,N,k), and for which inputsdoes it occur?

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