Due 6/23/2017 (Fr) 11:59 PM date: Submission: C source file, Assgn10.c, on Black
ID: 3850990 • Letter: D
Question
Due 6/23/2017 (Fr) 11:59 PM date: Submission: C source file, Assgn10.c, on Blackboard: http://uml.umassonline.ne Description: Anode in a linked list is defined by kpedef struct node int value; info member struct node next; pointer to a node NODE A sorted linked list maintains nodes such values in the listare in order. It also includes a header which does not carry any value information but serves the purpose of providing a sentinel node to the list. When the list is pointed by sortL the head assures that never becomes NULL The following functions are to be written: Int is Empty.(N ODE sortL) The function isEmpty(sortW return 1 for true when the list is empty. Even when the list is empty, you still have the header node. void insert(NODE'sortL NODE newNode); To the exiting list pointed by ptr, save the newNode so that the values stored in the newNode keeps the list order in the ascending order. void NODE sortL); Print values in the list as they are traversed from the beginning of the list to the last. The insert function without the header node can be written as follows. This is just for your reference. NODE No ptr, NODE "newNode){ newNode: next E ptr; ptr pewNode: else if (ptr value newNode- value)l. DewNode: next ptr; ptr. pewNode; else EVENT prev, curr prey, m ptr curr ptr- next; while (curr la NULL && curr- value newNode: value)( curr curr- next; prev- next newNade newNode: next curr;Explanation / Answer
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
//-------------------------------------------------
struct node
{
int data;
struct node *next;
}*start=NULL;
//------------------------------------------------------------
void insert()
{
char ch;
do
{
struct node *new_node,*current;
struct node *new_node;
printf("The Linked List : n");
new_node=(struct node *)malloc(sizeof(struct node));
new_node->next=NULL;
if(start==NULL)
{
start=new_node;
current=new_node;
}
else
{
current->next=new_node;
current=new_node;
}
printf("nDo you want to creat another : ");
ch=getche();
}while(ch!='n');
}
//------------------------------------------------------------------
void traverse()
{
new_node=start;
while(new_node!=NULL)
{
printf("%d--->",new_node->data);
new_node=new_node->next;
}
printf("NULL");
}
//----------------------------------------------------
void main()
{
printf("nEnter the data : ");
scanf("%d",&new_node->data);
insert();
traverse();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.