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

  Multiplexer and decoder

A bus organized the CPU has 32 registers with 16 bits in each, an ALU and a destination decoder. Specify how many multiplexers are there within the bus, and specify the size of each multiplexer?

  How the adoption of the technology affects

Your mandate as VP of Technology is to keep the regular projects strong and growing, plan for TechnoSeniors, and overhaul the AllTechComm intranet. Your must make the intranet one in which volunteers could sign up and manage their schedules, profi..

  Feasibility analysis

What is meant by the feasibility analysis? Explain how that experience relates to one or more of feasibility tests for technical, operational, schedule, or economic feasibility.

  How to modify the product program to use a gui

create the product Program to use a GUI. The GUI should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price of each unit, and the value of the inventory of that..

  What is autonomic relational database management system

In regards to Autonomic RDBMS, is it important to utilize a user-centered design (UCD) approach when designing a database for a small to medium size company. Why or why not.

  Choose third-party control available for visual basic.net

choose a third-party control available for Visual Basic.NET. Discuss how this control is used in an application. What are the advantages and disadvantages of using third-party controls in your applications.

  Design a "hello world" program in java

Each of the threads must be able to communicate with other threads by sending messages to them. The communication should be purely distributed in the sense that no other shared object is available to threads besides of the Thread array workers.

  Advantages of frame delay-atm-ethernet mans

On the basis of the current offerings for frame delay, ATM, and Ethernet MANs, explain the relative advantages of each.

  Make a heading that contains the name of the software

discuss a specific virus software, its advantages and disadvantages. make a heading that contains the name of the software you are reviewing. It should be about half-page or less.

  Program requires to check the current disk drive and report

program requires to check the current disk drive and report.

  Give description on wireless communication

As an IT consultant, you have been tasked to implement wireless communication for a car company with about with 1500 associates. In four locations.

  An example of the complexities involved in the case

We know there are problems of understanding natural languages as opposed to formal programming languages. As an instance of the complexities involved in the case of natural languages, identify situations in which the question "Do you know what tim..

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