Consider the following structure definitions and fill in the blanks for the dequeue function:
typedef struct queue queue_t; typedef struct node node_t;
struct node { node_t *next; void *val; };
struct queue { node_t *head; node_t *tail;};
/* removes and returns the item at the head of the queue q, * or NULL if q is empty. */
void *dequeue (queue_t *q) { if (q->head == NULL) {
return NULL; }
void *val = __________________________; node_t *p = __________________________; q->head = __________________________; free(p);
if (q->head == NULL) { q->tail = NULL; }
return val; }
I would like to suggest some errors in the code. First of all, the dequeue functions return type is void. Therefore, it cannot return val.
The answer:
void *val = q->head;
node_t *p = q->head;
q->head = q->head->next;
Consider the following structure definitions and fill in the blanks for the dequeue function: typedef struct...
CODE IN C Objectives: Queue operations. Data structure: typedef struct { int width; int height; }Rect; typedef struct node { Rect* r; struct node* next; }Node; typedef struct { Node* head; Node* tail; }Queue; Specification: In this lab six Queue-related operation functions need to be implemented by using the given function prototypes and data structures. 1. List* createQueue(void); This function initializes an empty “Queue” with the “Queue” data structure and returns an empty queue. 2. int enQueue(List*); This function receives...
CODE IN C Objectives: Queue operations. Data structure: typedef struct { int width; int height; }Rect; typedef struct node { Rect* r; struct node* next; }Node; typedef struct { Node* head; Node* tail; }Queue; Specification: In this lab six Queue-related operation functions need to be implemented by using the given function prototypes and data structures. 1. List* createQueue(void); This function initializes an empty “Queue” with the “Queue” data structure and returns an empty queue. 2. int enQueue(List*); This function receives...
() Given the following structure definition and typedef for a linked list of strings: typedef struct node st node; struct node st { char *word; /* a valid string pointer or NULL */ node *next; /* next node in the list or NULL */ }; Write a C function, free list(), that takes as an argument one of these lists, possibly NULL, and frees all the strings as well as the list itself. Write robust code. void free list(node *list){
Raphael was very happy last week until his boss suddenly called him yesterday, asking him to rewrite his code. Despite being terribly upset about it, he has finished up writing part of the code below. However, same as his predicament from last week, he doesn't understand how to complete the code to include functions for a) searching for a person and b) deleting the person at the front. Please help him complete his .cpp file ABOVE by defining the two...
// =================== Support Code ================= // Queue // // // // - Implement each of the functions to create a working circular queue. // - Do not change any of the function declarations // - (i.e. queue_t* create_queue(unsigned int _capacity) should not have additional arguments) // - You should not have any 'printf' statements in your queue functions. // - (You may consider using these printf statements to debug, but they should be removed from your final version) // ==================================================...
In c, please implement the following 3 functions to the code below is_reachable(graph_t * g, int source, int dest) returns 0 if I can reach the destination from source, -1 otherwise ( using BFS) has_cycle(graph_t * g) returns 0 if there is a cycle in the graph, -1 otherwise (using BFS or DFS) print_path(graph_t * g, int source, int dest) prints any path from source to destination if there exists one (Choose either BFS or DFS, typically DFS is much...
PROBLEM: string CBQueue::dequeue( ) This method should remove and return the item at the front of the queue- please add comments EXISTING CODE: #include // this allows you to declare and use strings #include using namespace std; struct qNode { string data; qNode* next; qNode* prev; }; class CBQueue { public: CBQueue(); int CBQueue::getSize( ); bool CBQueue::isEmpty( ); private: qNode* front; qNode* rear; int size; }; #include "CBQueue.h" CBQueue::CBQueue() { front = NULL; rear = NULL; size = 0; }...
IN C Programming #include<stdio.h> #include<stdlib.h> typedef struct nodestruct { int item; struct nodestruct *next; } Node; typedef struct { int size; // Number of items on user’s list Node *head, *tail; } List; //In addition to creating an empty list, this function will also create two dummy nodes; one for the head, and the other for the tail. List* createList(); //This function creates a node containing the provided item, then inserts it into the list pointed by the provided list...
All the functions are written and work besides removeLinkedList and contains LinkedList. Please fill those out. 무#ifndef #define LINKEDLIST-H LINKEDLISTH define TYPE /*# define TYPE SIZE sizeof (TYPE) */ double typedef struct ListStack LinkedList; void initLinkedLǐst(LinkedList *1); void freeLinkedList (LinkedList *1) int İsEmptyLinkedList (LinkedList*1); void pushLinkedList (LinkedList #1, TYPE val); TYPE topLinkedList (LinkedList 1) void popLinkedList (LinkedList *1); /* Bag / void addLinkedList (LinkedList *1, TYPE val) ; int containsLinkedList (LinkedList *1, TYPE val) ; void removeLinkedList (LinkedList l, TYPE...
PROMPT: Consider a binary tree (not necessarily a binary search tree) with node structure. QUESTION: Prove that findMax works by mathematical induction. struct Node int val; struct Node * left; struct Node* right; The following function findMax returns the largest value 'val in the tree; and returns -1 if the tree is empty. You may assume that all the values 'val' in the tree are nonnegative. struct Node * findMax(struct Node root) if (rootNULL) return -1; maxval = root->val; maxval...