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

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

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