Examine the files list.h and llist.c in the src directory where you found this h
ID: 3865596 • Letter: E
Question
Examine the files list.h and llist.c in the src directory where you found this handout.
You will discover that it is a partially implemented linked list “module”.
The lists store numeric values (the type of which can be changed by altering the typedef for ElemType in list.h).
As in previous projects, the .h file gives the interface for an ADT while the actual implementation is given in the .c file. The members of list_struct are also “hidden” in the .c file. The ADT defines many natural operations on lists -- some of these have already been implemented and will be used as motivating examples during lecture; others have not been implemented: It is your job to do the implementation! Look for TODO labels throughout the files.
A subtle detail: why did I decide to name the header file list.h (one ‘l’), but the implementation file llist.c (two ‘l’s)???
So… part I is completion of all of the TODO items specified.
Rules: you cannot change list.h (except maybe to experiment with different ElemTypes). All of your work is in llist.c (except testing code).
list.h
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
llist.c
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------MakeFile
llist.o: list.h llist.c
gcc -c llist.c
ll_tst: ll_tst.c llist.o
gcc -o ll_tst ll_tst.c llist.o
quad: quad.c
gcc -o quad quad.c
clean:
rm quad ll_tst llist.o
Explanation / Answer
{
int test_result=0; /* default test result */
while(l->next!=NULL) /* we need to chek upto last node */
{
if(l->val<(l->next)->val) /* to check if the current node and next node are in non-decending order */
{
l=l->next;
test_result=1; /*if the current node and next node are in non-decending order test is true and we have to move to */ /* next node */
}
else test_result=0;
}
return test_result;
}
/***************************************************************************************/
{
NODE *tempptr;
tempptr=&temp;
tempptr->next=NULL;
temp.val=x;
while(l->next!=NULL)
{
if((l->next)->val >x)
{
tempptr->next=l->next;
l->next=tempptr;
}
}
l->next=temptr;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.