Write the code for an ordered linked list module

Assignment Help Computer Engineering
Reference no: EM13322512

Ordered Linked List Project

Overview

You are to write the code for an ordered linked list module. You will be supplied with three files: main.c, orderedList.h, orderedList.c and Makefile. You are not to modify the file orderedList.h. In the file orderedList.c, you are to supply the code for the three functions whose prototypes are in orderedList.h. The file main.c is used to test your implementation of these functions. It is not necessarily a complete test, so you may modify it to check other possible places where your functions might fail.

Submission

The only file that will be submitted is orderedList.h.

Using the Makefile

Select Makefile from the file list and hit Compile/Validate. This will compile ordereList.c and main.c, producing an executable named main. If you double click main, the program will execute and should produce the output shown in the example below.

Contents of orderedList.h

typedef struct node {

int data;

struct node *next;

} Node;

Node *orderedInsert(Node *p, int newval);

/* Allocates a new Node with data value newval and inserts into the ordered list with first node pointer p in such a way that the data values in the modified list are in nondecreasing order as the list is traversed.

*/

void printList(Node *p);

/* Prints the data values in the list with first node pointer p from first to last, with a space between successive values.

Prints a newline at the end of the list.

*/

void clearList(Node **p);

/* Deletes all the nodes in the list with first node pointer *p, resulting in *p having value NULL. Note that we are passing

a pointer by address so we can modify that pointer.*/

Design of orderedInsert function

Here is a step by step description of what you should do to insert a integer newval into an ordered linked list with first node pointer p:

1. Declare a Node pointer variable q, dynamically allocate a Node as the target of q and set the data value of the new node to newval.

2. If the list is empty or newval is less than or equal to the data value in the first node of the list, make the target node of q the first node of the list and return q.

3. Use a Node pointer tmp to traverse the list until it either reaches the last node or reaches a Node whose following node has data value greater than or equal to newval.

4. Insert the target of q after the target of tmp and return p (the original first node pointer).

Example

Suppose the following code (from main.c) is executed :

Node * p = NULL;

p = orderedInsert(p,2);

printList(p);

p = orderedInsert(p,0);

printList(p);

p = orderedInsert(p,3);

printList(p);

p = orderedInsert(p,3);

printList(p);

p = orderedInsert(p,5);

printList(p);

clearList(&p);

p = orderedInsert(p,6);

printList(p)

Then the output would be:

2

0 2

0 2 3

0 2 3 3

0 2

Reference no: EM13322512

Questions Cloud

Examine of water in a sediment sample at equilibrium : Analysis of water in a sediment sample at equilibrium at pH 7.00 showed [SO42-] = 2.00 x 10^-5 M and a partial pressure of H2S of 0.100 atm. Show with appropriate calculations if methane, CH4, would be expected in the sediment.
What is the speed of the block after the collision : A 0.45 caliber bullet (m = 10.7 g) is fired into a large block of wood (M = 0.750 kg) so that the bullet becomes lodged in the block. What is the speed of the block after the collision
Compute the work done by friction : A 10.0 kg block is to be projected across a rough horizontal floor by means of a compressed spring device. What is the work done by friction, in joules, as the block slides to a stop
Depict the structure(s) of all carbocations : Draw the structure(s) of all carbocations that could potentially form from the alkene and label each carbocation as primary, secondary or tertiary. 1-butene
Write the code for an ordered linked list module : Select Makefile from the file list and hit Compile/Validate. This will compile ordereList.c and main.c, producing an executable named main. If you double click main, the program will execute and should produce the output shown in the example below..
State the balanced overall chemical reaction : In some industrial processes, sulfite is added to remove dissolved O2 to prevent corrosion of pipes. Write the balanced overall chemical reaction for reduction of dissolved O2 by sulfite (SO32-).
How long is the organ pipe : An organ pipe is shown to resonate at 240 Hz, 320 Hz, and 400 Hz. It does not resonate at any other frequencies between 240 Hz and 400 Hz, How long is the organ pipe
Depict the structure of all carbocations : Draw the structure(s) of all carbocations that could potentially form from the alkene and label each carbocation as primary, secondary or tertiary. 2-methylpropene
Calculate the difference in pressure at point a and point b : Some distance downstream, the velocity profile can be (very) roughly approximated by a region inside the wake with u = U/2 and an exterior region with u = 3U/2.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Define what a cache is and what its purpose

define what a cache is and what its purpose is. Also describe what data gets placed into the cache, and when it is put there.

  Data planning and enterprise modelling

Describe the major differences between two approaches for data planning and enterprise modelling and examine the integration? Why do these two methodologies usually produce several results?

  Knowledge revolution and industrial revolution

What are your thought on this that would support notion that Knowledge Revolution was born from the Industrial Revolution?

  Discuss the impact the internet

How do you think the future changes of the Internet will impact the professional development of IT professionals?

  Which array types can hold object references

What is the default initialization value for a integer array.

  Build a code in preparation for creating a spell-checker

Write down a code in preparation for creating a spell-checker. For now don't worry about actually spell checking: Just write a program that can read in the dictionary word by word.

  Write down a public static method named chunk25

Write down a public static method named chunk25 that takes a double and returns an integer that represents the number of chunks of 25 in that number. A chunk of 25 is 25, or any part thereof

  Why computer''s activities is handling failure

why computer's activities is handling failure.

  Breaking the version of cipher

Assume an improved version of Vigen ere cipher in which in place of utilizing several shift ciphers, several mono-alphabetic substitution ciphers are utilized.Display how to break this version of the cipher.

  Find out whether the list is empty

Write down the functions (in C++) to perform these basic operations on Linked List.

  Assess the security risks

As part of your project in order to assess the security risks in order to compute the infrastructure, you have discovered that other managers often have several ideas on the severity and levels of the risk.

  Display comments and identified source codes

Write and manually assemble the following programs. All memory addresses include the starting and ending addreses. display comments and identified source codes.

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