Question: #include #include #include struct node { int n; struct node *next; }; struct list { struct node *head; int count; }; void print(struct list *thislist){

 #include #include #include struct node { int n; struct node *next;

#include #include #include

struct node { int n; struct node *next; };

struct list { struct node *head; int count; };

void print(struct list *thislist){ struct node * current = thislist->head; while(current!=NULL){ printf("%d ", current->n); current=current->next; } printf(" "); }

void insert(struct list *thislist, int number){ //create a new node struct node *tmp = malloc(sizeof(struct node)); tmp->n = number; tmp->next = NULL;

printf("insert %d ", number);

struct node *current = thislist->head;

//if the list is empty //head points to the new node (the only node) if(current == NULL){ thislist->head = tmp; thislist->count = 1; return; }

//find the last node while(current->next!=NULL){ current = current->next; } thislist->count = thislist->count + 1;

//the last node -> next points to the new node current->next = tmp;

return;

}

int size(struct list *thislist){ int count = 0; struct node *current = thislist->head; while(current != NULL){ count++; current = current->next; } return count; }

void dequeue(struct list *thislist){

}

void pop(struct list *thislist){

}

void destroy (struct list *thislist){

}

void sort(struct list *thislist){

}

int main(int argc, char * argv[]){

struct list * mylist = malloc(sizeof(struct list));

mylist->head = NULL;

//DO NOT make any modifications bellow this line int i; for(i=1;i

}

dequeue(mylist);

pop(mylist); pop(mylist);

sort(mylist);

print(mylist);

printf("Size of the list is %d ",size(mylist));

destroy(mylist);

free(mylist);

return 0;

}

Once you are done with Part 1, the next step is to make your list work as a queue or a stack. Your job is to implement three functions: dequeue(), pop() and destroy(). dequeue() will remove a node from the front of the list pop() will remove a node from the end of the list. destroy() will remove all nodes from the list. Make sure dequeue(), pop() and destroy() can handle an empty list gracefully. The output of your program then should look like this: hb117@uxb4:-/class/cs410/p1$ gcc -Wall -o list.c list.c hb117@uxb4:-/class/c3410/p1$ ./list 12 99 37 8 65 12 64 insert 12 insert 99 insert 37 insert 8 insert 65 insert 12 insert 64 dequeue 12 pop 64 pop 12 99 37 8 65 Size of the list is 4 destroy 99 37 8 65

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 Databases Questions!