Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write a C program that generate 10 random numbers in the range [0..1000] and insert them in a ascending order into an empty linked list.

write a C program that generate 10 random numbers in the range [0..1000] and insert them in a ascending order into an empty linked list. Every time you generate a number you need to traverse the linked list and find a proper place for the number to be inserted.This means that you should not sort numbers before insertion. You should calculate the list length and print it together with the list after each number insertion. Please test your program with Valgrind to check for memory leaks, all the allocated memory must be free at the end.... use this command for valgrind (valgrind --leak-check=yes excautable name).

Detailed requirements for linked lists implementation:

You will need to write several functions.

0. To represent a node in a linked list you can use a structure

typedef struct Node {

SomeDataType data;

struct Node *next;

} ListNode;

where SomeDataType can be any C data type.

1. Write a function to make a new list. Your function should create a DUMMY head node to represent an empty list.

ListNode *newList(void) // returns a head of a new empty list

2. Write functions to insert elements into a list and to remove elements from a list

ListNode *insertNode(ListNode *prev, SomeDataType data)

// inserts a new node with data eld data after prev

3. Write functions to count the number of elements in a list without the head and to print

the list

int length(ListNode *head) // number of elements in the list

void printList(ListNode *head) // print the data elds for the entire list

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems An Application Oriented Approach Complete Version

Authors: Michael Kifer, Arthur Bernstein, Richard Lewis

2nd Edition

0321268458, 978-0321268457

More Books

Students also viewed these Databases questions

Question

1. How is the newspaper help to our daily life?

Answered: 1 week ago

Question

1. Prepare a short profile of Mikhail Zoshchenko ?

Answered: 1 week ago

Question

What is psychology disorder?

Answered: 1 week ago