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

/* * a node in our linked-list of web addresses */ struct listNode{ char addr[MA

ID: 3590254 • Letter: #

Question

/*
* a node in our linked-list of web addresses
*/
struct listNode{
char addr[MAX_ADDR_LENGTH];

struct listNode *next;
};

Complete the following methods:

/*
* returns 1 if the list starting at pNode contains the address addr,
* and returns 0 otherwise
*/
int contains(const struct listNode *pNode, const char *addr){
//TODO: complete this

}

/*
* inserts the address addr as a new listNode at the end of
* the list
*/
void insertBack(struct listNode *pNode, const char *addr){
//TODO: complete this

}

/*
* prints the addresses from pNode to the end of the list,
* one on each line
*/
void printAddresses(const struct listNode *pNode){

}

/*
* frees the memory associated with this node and all subsequent nodes
*/
void destroyList(struct listNode *pNode){

}

Explanation / Answer

int contains(const struct node *pNode, const char *addr){

struct node *temp=pNode;

while (temp->next!=null){

    if(strcmp(temp.addr,addr)==0)

        return 1;

    temp=temp->next;

  }

return 0;

}

void insertBack(struct listNode *pNode, const char *addr){

struct node *temp=pNode;

while(temp->next!=null)

    temp=temp->next;

struct node *p;

p=(struct node *)malloc(sizeof(struct node));

p->addr=addr;

temp->next=p;

p->next=null;

}

void printAddresses(const struct listNode *pNode){

struct node *p;

while(p!=null){

    printf("%s",p->addr);

    p=p->addr;

  }

}

void destroyList(struct listNode *pNode){

struct node *p=pNode, tmp;

while(p!=null){

    tmp=p;

    p=p->link;

    free(tmp);

  }

}

Do comment if you dont understand any of the code.