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

Create a singly linked list to store a sorted list of ints. The first line in th

ID: 2839827 • Letter: C

Question

Create a singly linked list to store a sorted list of ints. The first line in the input file represents the number of elements to be stored in the singly linked list and the second line contains the values of the singly linked list as ints separated by a single space. Your program must use a structure for every node in the list. The node structure's members should be the value of the node and a pointer to another node. Your program must also use an insertion sort like method to insert the elements into the singly linked list one by one until every element has been added to The singly linked list. The result should be singly linked list where each node points to a node with a value greater than itself (sorted in ascending order). Read in a square NxN matrix from the file matrix txt where the first line in the file contains the number of rows and the number of columns since the matrix is a square. The subsequent lines contain the matrix values in the format where each line represents a row with every element in the row separated by a single space.

Explanation / Answer

link.h

# include <stdio.h>

# include stdlib.h>

struct node

{

char letter;
struct node* next

}*start;

************************************************************************

link.c

void enter(struct node** start, char data)
{
struct node *temp,*p;
temp=(struct node *)malloc(sizeof(struct node));
temp->letter=data;
if(*start==NULL)
{
temp->next=NULL;
*start=temp;
return;
}
p=*start;
while(p->next!=NULL)
{
p=p->next;
}
p->next=temp;
temp->next=NULL;
}
void display(struct node *start)
{
printf("Forward List is: ");
while(start!=NULL)
{
printf("%c ",start->letter);
start=start->next;
}
printf(" ");
}
void rev(struct node *start)
{
printf("Backward List is: ");
char s[10];
int i=-1;
while(start!=NULL)
{
//printf("%c ",start->letter);
s[++i]=start->letter;
start=start->next;
}
for(i=4;i>=0;i--)
printf("%c ",s[i]);
printf(" ");
}
int main()
{
struct node* node = NULL;
printf("Enter five Characters: ");
char c,a;
int i;
for(i=1;i<=5;i++)
{
scanf("%c",&c);
scanf("%c",&a);
enter(&node,c);
}
printf("Choose Option: ");
printf("1.Forward Direction: ");
printf("1.Backward Direction: ");
int o;
scanf("%d",&o);
if(o==1)
display(node);
else
rev(node);
return 0;
}

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