Question: Problem 1 : Exercise 8 . 1 8 ( with one change as mentioned below ) Instead of having a return type of void, your

Problem 1: Exercise 8.18(with one change as mentioned below)
Instead of having a return type of void, your zip should return an integer: 0 if execution is successful and -1 for malformed/error input. What would constitute a malformed input for this problem? For starters, it is an error to call zip with a nonempty list as third argument. It is also an error to call zip with one of the input lists the same as the output list. (For instance, zip(ll1,ll2,ll1). Can you see the problem such a call would cause?). On the other hand, it's OK to call zip with empty ll1 or ll2(or both). Finally, passing NULL pointers for some or all of the lists in not allowed either (but you already knew that from previous assignments). Your zip function should check all of these error conditions and return -1 if any of them are true.
Problem 2: Exercise 8.19(with one change just like in the above problem: return 0 if execution is successful and -1 for malformed input).
What would constitute a malformed input for this problem? Use similar ideas as mentioned above in Problem 1. this is llist.c #include
#include
#include "llist.h"
/* Private node ADT. */
typedef struct _node node;
struct _node {
node * next;
void * e;
};
static node * newNode(void * e){
node * n = malloc(sizeof(node));
if (!n) return NULL;
n->next = NULL;
n->e = e;
return n;
}
static void deleteNode(node * n){
free(n);
}
/* Linked list library. */
struct _llist {
node * head;
};
llist * newLList(void){
llist * ll = malloc(sizeof(llist));
if (!ll) return NULL;
ll->head = NULL;
return ll;
}
void deleteLList(llist * ll){
if (!ll) return;
node * n = ll->head;
while (n){
node * next = n->next;
deleteNode(n);
n = next;
}
free(ll);
}
int isEmptyLList(llist const * ll){
if (!ll) return 0;
return(ll->head == NULL);
}
int putLList(llist * ll, void * e){
node * n;
if (!ll) return -1;
n = newNode(e);
if (!n) return -1;
n->next = ll->head;
ll->head = n;
return 0;
}
int getLList(llist * ll, void ** e){
node * n;
if (!ll ||!e) return -1;
if (ll->head == NULL){/* nothing to get */
*e = NULL;
return -2;
}
n = ll->head;
*e = n->e; /* write element */
ll->head = n->next;
deleteNode(n);
return 0;
}
int peekLList(llist const * ll, void ** e){
if (!ll ||!e) return -1;
if (ll->head == NULL){
/* Nothing to get. */
*e = NULL;
return -2;
}
*e = ll->head->e; /* write element */
return 0;
}
int printLList(llist const * ll, printFn f){
node * n;
int cnt;
if (!ll ||!f) return -1;
cnt =0;
for (n = ll->head; n != NULL; n = n->next){
/* Print the index of the element. */
cnt++;
printf("%d:", cnt);
/* Call user-provided f to print the element. */
f(n->e);
}
printf("
");
return 0;
}
int zip(llist * ll1, llist * ll2, llist * ll3){
/* Your code goes here. */
return 0;
}
int unzip(llist * ll1, llist * ll2, llist * ll3){
/* Your code goes here. */
return 0;
}
Problem 1 : Exercise 8 . 1 8 ( with one change as

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!