Write a sortedinsert function in c program that takes two


Assignment

Q1. Write a complete C++ program to create a table as shown below. User inputs the width of the table, after creating the shape your program should calculate the sum of the elements in a particular row entered by the user.

Example run:
Width of the shape? (Enter odd number only) 9
Enter row number to get sum 5
Answer:

1576_Shape.jpg

Sum of row 5 is 45

Q2. Write the following functions and then a complete C program, assuming the node type used is as follows:

struct node {
int data;
struct node* next;
};

and head is the head pointer of a list:

struct node* head;

a) Write a sortedInsert() function in C program that takes two parameters:

i. a list that is sorted in increasing order, and
ii. a single node,

which inserts the node into the correct sorted position in the list. You should use the following function header:

voidSortedInsert(struct node** headRef, struct node* newNode) {

// Your code...

b) Write another function named removeRedundant() which takes a list sorted in increasing order and deletes any duplicate nodes from the list. Ideally, the list should only be traversed once.

/* Remove duplicates from a sorted list. */

voidRemoveDuplicates(struct node* head) {

// Your code...

Q3. Create a linked list using C, print the linked list and then call a function to delete a specified node. In your delete function

i. check if the first node matches with the ‘key' value, if it matches delete the first node.
ii. if the key value doesn't match with the first node then call a find_node () function to find the location of the particular node that containing the item to be deleted.

Print your linked list after the deletion process.

551_Linked List.jpg

Q4. Write a complete C program, that Uses a one-dimension array to read 20 numbers, each of them is between 0 and 100, inclusive.

a. Uses a bubbleSort() function to sort the array in ascending order. Discuss the Big O of your sorting algorithm for the best case and worst case scenarios.

b. Write another function that improve the performance of your program by using another sorting algorithm (any algorithm learned in the lecture), discuss the Big O of the new algorithm used.

Request for Solution File

Ask an Expert for Answer!!
Data Structure & Algorithms: Write a sortedinsert function in c program that takes two
Reference No:- TGS01557292

Expected delivery within 24 Hours