() 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){
void free_list(node *list) { if (list != NULL) { node *temp; while (list != NULL) { temp = list->next; free(list); list = temp; } } }
() Given the following structure definition and typedef for a linked list of strings: typedef struct...
Assume entries in a linked list are of type struct listrec: struct listrec { char value; struct listrec *next; }; Write a main() routine in which you create the following linked list: | a | --|----> | c | --|-----> | w | --|----> NULL Write a function called printlist that takes a pointer to the start of a linked list and prints out all the nodes in the list in sequence. The inferface of this function...
Consider a Linked List program with the following class: typedef int datatype; struct node { datatype data; node *tail; }; class LinkedList{ private: node *head; node *current;public: //constructors LinkedList(); LinkedList(int i); //destructor ~LinkedList(); bool start(); //sets list postion to header bool nextNode(); //increments to next node in list int getCurrent(); //returns data from current node void insertNode(int i); //inserts node after current node //then sets current node to new node bool deleteNode();//deletes currentnode void deleteAll(); //deletes all nodes };...
A linked list is constructed of nodes described by the following structure: struct node{ char data; struct node *next; }; Assume a linked list containing a sentinel node is constructed from the above nodes. Write a function named "count"-prototyped as int count(struct node*sent)- that accepts a pointer to the sentinel node; counts the number of data (non-sentinel) nodes containing the character 'A'; and returns that count as the function value.
Given the following linked list structure called node: struct node { int val; struct node * ptrNext; }; Assume we have a single list created from this structure with a head pointer called ptrFirst which is declared in the global scope. a. Write a complete C function called CountEven to count all the even values in this singly linked list of arbitrary number of nodes using an iterative (non-recursive) approach. The function takes as parameter the pointer to the starting...
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...
six options in the menu:Create a new dictionary.2. Add a word to a dictionary. 3. Delete a word from a dictionary. 4. Find a word in a dictionary. 5. Delete a dictionary. 6. Exit.each word represented by typedef struct Word { char** translations; struct Word* next; } Word;each dictionary represented bytypedef struct { char** languages; int numOfLanguages; Word* wordList; } Dictionary;languages will include a pointer to an array of strings so that the first word is the origin language and...
struct Node * new_11( void ) { // return a new node to be the list anchor struct Node * node = (struct Node *) malloc(sizeof(struct Node)); memset(node, o, sizeof(struct Node)); return node ; struct Node * find_l1(struct Node * anchor, char * word) { // given a pointer to the anchor of the list, and a word, search // the list for the word. return the pointer to the with the word, if found, 7/ or NULL if not...
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...
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...
Define a struct Node to represent a node in a double linked-list that stores a string as data. Write a function to insert a node to the head of the linked list. The function takes two arguments: a pointer to the first node in the double linked list and a string value. It should create a new node with the given value to the head of the double linked list.