LAB #9 Practice C Writing Linked List Functions | Complete Solution
- ExpertT
- Rating : 109
- Grade : A+
- Questions : 1
- Solutions : 1026
- Blog : 0
- Earned : $53187.54
LAB #9
Practice C Writing Linked List Functions
Remember, if you need to get Lab #8 graded, you need to show your lab to the TAs within 10 minutes of getting to lab, and you and your partner will not receive lab credit if you do not get checked off before leaving each lab. Once you have a zero on a lab, then it cannot be changed because we have no way of know if you were there or not!!!
Reminder: All of our labs involve paired programming. You do not have to keep the same partner for each lab, but you MUST work with someone in each lab!!! First, find a
partner for this lab. It can be the same partner from the previous lab or a different partner.
Write the linked list functions you’ll need for Assignment #5. Use the following link
to help you understand linked lists and C:
(2 pts) Design pseudocode for linked list functions
Write the implementation for the following header file that will help you use your linked
list easily, i.e. list.c. You want to design a solution on paper first to help you know what
the code and pointers will look like. Here is the list.h file:
struct node {
int val;
struct node *next;
};
int length(struct node *);
void push(struct node **, int); //add to front of list
void append(struct node **, int); //add to rear of list
void print(struct node *, int);
(6 pts) Implement linked list functions
Now, use the code below to test your list.c implementation file with test_list.c. After
you copy it to your own file, compile it with your list.c file, i.e. gcc list.c test_list.c.
Do you see the values in your list printed in the order you entered them?
If not, are you getting a segmentation fault? What else might be the error?
What happens when you use append, rather than push?
#include "list.h"
#include <stdio.h>
#include <stdlib.h>
int main (){
char ans[2];
int num;
struct node *head = NULL;
do {
printf("Enter a number: ");
scanf("%d", &num);
push(&head, num); //Change push to append…
printf("Do you want another num (y or n): ");
scanf("%1s",ans);
} while(ans[0]=='y');
print(head, length(head));
return 0;
}
[Solved] LAB #9 Practice C Writing Linked List Functions | Complete Solution
- This Solution has been Purchased 1 time
- Submitted On 03 Jun, 2015 11:49:04
- ExpertT
- Rating : 109
- Grade : A+
- Questions : 1
- Solutions : 1026
- Blog : 0
- Earned : $53187.54