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

PROGRAM MUST BE IN C PROGRAMMING AND PLEASE COMPLETE ALL AS WELL AS SEND SCREENS

ID: 3865590 • Letter: P

Question

PROGRAM MUST BE IN C PROGRAMMING AND PLEASE COMPLETE ALL AS WELL AS SEND SCREENSHOT OF OUTPUT FOR THE THUMBS UP! SRC files are given below!

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

Am providing you with both the TODO methods. Its your duty to place them in their proper c file.


ElemType* lst_to_array(List* a, int *n) {
   *n = 0;
   NODE *tmp = l->front;
   while (tmp!=NULL) {
       (*n)++;
       tmp = tmp->next;
   }
   ElemType *arr = malloc(sizeof(ElemType) * n);
   tmp = l->front;
   *n = 0;
   while (tmp!=NULL) {
       arr[n] = tmp->val;
       (*n)++;
       tmp = tmp->next;
   }
}

LIST *lst_clone(LIST *l) {
   LIST *list = malloc(sizeod(LIST));
   NODE *tmp = l->front;
   NODE *new;
   while (tmp!=NULL) {
       new = malloc(sizeof(NODE));
       new -> val = tmp.val;
       new -> next = NULL;
       if (list->back == NULL) {
           list->front = list->back = new;
       }
       else {
           list->back->next = new;
           list->back = new;
       }
       tmp = tmp->next;
   }
    return list;
}
      

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