Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This assignment involves searching and sorting. We will search a linked list and

ID: 3776730 • Letter: T

Question

This assignment involves searching and sorting. We will search a linked list and sort a contiguous list (it is easier).  

1) We want to build a linked list of 100 nodes, each containing a positive integer between 0 and 99 in reverse order (i.e., the first node will contain the number 99; the second 98; the third 97 and so on).   Write a program in C that a) builds the list; b) Ask the user what number she wishes to find in that list; c) search for that integer in the linked list you built under part a above; d) Return the position of the node in which you found the number requested. Assume the list is unordered (which of course, is not the case here), and search the entire linked list sequentially until the node containing the desired number is found.  If the number is not found (say the user enters 202), it should say that the search failed.  

Set up the user entry capability in a loop so that the user can enter numbers repeatedly if she wants. That is, when a number entered is found (or not found), it will give her an opportunity to enter a new number. If the user no longer wants to use the program, she should enter ?1.   

For output, print out a line stating that the value sought was found in the nth node.  For example:

Please enter the number to be sought in the list: >> 15

The number 15 was found in node #85

2) Write a program in C that:  

a. Builds a contiguous list of 100 cells.   

b. Populates the cells with random integers between 0 and 10,000.  

c. Prints out the list.  

d. Sorts the list in increasing order using the InsertSort algorithm.  

Here's the actual assignment

This assignment involves searching and sorting. We wi search a linked list and sort a contiguous list (it is easier). 1) (3 pts.) We want to build a linked list of 100 nodes, each containing a positive integer between 0 and 99 in reverse order (i.e., the first node will contain the number 99; the second 98; the third 97 and so on). Write a program in C that a) builds the list; b)Ask the user what number she wishes to find in that list; c) search for that integer in the linked list you built under part a above; d) Return the position of the node in which you found the number requested. Assume the list is unordered (which of course, is not the case here), and search the entire linked list sequentially until the node containing the desired number is found. If the number is not found (say the user enters 202), it should say that the search failed. Set up the user entry capability in a loop so that the user can enter numbers repeatedly if she wants. That is, when a number entered is found (or not found), it will give her an opportunity to enter a new number. If the user no longer wants to use the program, she should enter-1. For output, print out a line stating that the value sought was found in the nth node. For example: Please enter the number to be sought in the list: 15 The number 15 was found in node #85 2) (3 pts.) Write a program in C that a. Builds a contiguous list of 100 cells. b. Populates the cells with random integers between 0 and 10,000. c. Prints out the list. d. Sorts the list in increasing order using the Insertsort algorithm e. Prints out the list after sorting.

Explanation / Answer

/**
Program to make a linked list of size 100 containing values from 99 to 0
searching the node of the linked list containing the entered value.
*/
#include<stdio.h>
struct node
{
int info;
int count;
struct node *next;
};
struct node *start=NULL,*ptr;
void search(struct node*,int);
void display(struct node*);
void main()
{
int val=99,i=0,nodeCount=1;
clrscr();
do
{
   if(start==NULL)
   {
       start=(struct node*)malloc(sizeof(struct node));

       start->info=val;
       start->next=NULL;
       start->count=nodeCount;
       ptr=start;

   }
   else
   {
       ptr->next=(struct node*)malloc(sizeof(struct node));
       ptr=ptr->next;
       ptr->info=val;
       ptr->count=nodeCount;
       ptr->next=NULL;
   }
   i++;
   nodeCount++;
   val--;
   fflush(stdin);
}while(i<100);

display(start);

while(1) {
   printf(" enter value to search, -1 to exit:");
   scanf("%d",&val);
   if(val==-1)
       break;
   else
       search(start,val);
   }
getch();
}
void display(struct node *ptr)
{
   while(ptr!=NULL)
   {
       printf(" %d",ptr->info);
       ptr=ptr->next;
   }

}
//function to search the node containing the value entered by user
void search(struct node *ptr,int val)
{
   struct node *new_start=ptr;
   if(ptr->info==val)
   {
       printf("you searched: ");
       printf("%d ",ptr->info);
       printf("your node count is: ");
       printf("%d",ptr->count);
   }
   else
   {
       while(ptr->next->info!=val)
       {
       ptr=ptr->next;
       }
       printf("you searched: ");
       printf("%d ",ptr->next->info);
       printf("your node count is: ");
       printf("%d",ptr->next->count);

   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote