I need help coding this in C
•Your program should start by asking the user how many nodes will be in the network. Nodes should be implemented by a node struct and maintained in a Linked List.
•Each node should maintain all packets that have been generated and are ready to be be transmitted (one at a time). Packets should be implemented by a packet struct and maintained in a Linked List.
#include<stdio.h> #include<stdlib.h> #include<stdbool.h> struct test_struct { int val; struct test_struct *next; }; struct test_struct *head = NULL; struct test_struct *curr = NULL; struct test_struct* create_list(int val) { printf("\n creating list with headnode as [%d]\n",val); struct test_struct *ptr = (struct test_struct*)malloc(sizeof(struct test_struct)); if(NULL == ptr) { printf("\n Node creation failed \n"); return NULL; } ptr->val = val; ptr->next = NULL; head = curr = ptr; return ptr; } struct test_struct* add_to_list(int val, bool add_to_end) { if(NULL == head) { return (create_list(val)); } if(add_to_end) printf("\n Adding node to end of list with value [%d]\n",val); else printf("\n Adding node to beginning of list with value [%d]\n",val); struct test_struct *ptr = (struct test_struct*)malloc(sizeof(struct test_struct)); if(NULL == ptr) { printf("\n Node creation failed \n"); return NULL; } ptr->val = val; ptr->next = NULL; if(add_to_end) { curr->next = ptr; curr = ptr; } else { ptr->next = head; head = ptr; } return ptr; } struct test_struct* search_in_list(int val, struct test_struct **prev) { struct test_struct *ptr = head; struct test_struct *tmp = NULL; bool found = false; printf("\n Searching the list for value [%d] \n",val); while(ptr != NULL) { if(ptr->val == val) { found = true; break; } else { tmp = ptr; ptr = ptr->next; } } if(true == found) { if(prev) *prev = tmp; return ptr; } else { return NULL; } } int delete_from_list(int val) { struct test_struct *prev = NULL; struct test_struct *del = NULL; printf("\n Deleting value [%d] from list\n",val); del = search_in_list(val,&prev); if(del == NULL) { return -1; } else { if(prev != NULL) prev->next = del->next; if(del == curr) { curr = prev; } else if(del == head) { head = del->next; } } free(del); del = NULL; return 0; } void print_list(void) { struct test_struct *ptr = head; printf("\n -------Printing list Start------- \n"); while(ptr != NULL) { printf("\n [%d] \n",ptr->val); ptr = ptr->next; } printf("\n -------Printing list End------- \n"); return; } int main(void) { int i = 0, ret = 0; struct test_struct *ptr = NULL; print_list(); for(i = 5; i<10; i++) add_to_list(i,true); print_list(); for(i = 4; i>0; i--) add_to_list(i,false); print_list(); for(i = 1; i<10; i += 4) { ptr = search_in_list(i, NULL); if(NULL == ptr) { printf("\n Search [val = %d] failed, no such element found\n",i); } else { printf("\n Search passed [val = %d]\n",ptr->val); } print_list(); ret = delete_from_list(i); if(ret != 0) { printf("\n delete [val = %d] failed, no such element found\n",i); } else { printf("\n delete [val = %d] passed \n",i); } print_list(); } return 0; }
I need help coding this in C •Your program should start by asking the user how...
(In C Programming) Your program should start by asking the user how many nodes will be in the network. Nodes should be implemented by a node struct and maintained in a Linked List. •Each node should maintain all packets that have been generated and are ready to be be transmitted (one at a time). Packets should be implemented by a packet struct and maintained in a Linked List. •The protocol you will implement should run for 100 rounds. The first...
Using C, I need help debugging this program. I have a few error messages that I'm not sure how to fix. Here is the code I have: /* * C Program to Print a Linked List in Reverse Order */ #include <stdio.h> #include <stdlib.h> struct node { int num; struct node *next; }; int main() { struct node *p = NULL; struct node_occur *head = NULL; int n; printf("Enter data into the list\n"); create(&p); printf("Displaying the nodes in the list:\n");...
I need this in C++. This is all
one question
Program 2: Linked List Class For this problem, let us take the linked list we wrote in a functional manner in a previous assignment and convert it into a Linked List class. For extra practice with pointers we'll expand its functionality and make it a doubly linked list with the ability to traverse in both directions. Since the list is doubly linked, each node will have the following structure: struct...
Must be written and C, and compile with MinGW. Thank
you!
am Specification For this assignment, you will write a multi-file C program to define, implement and use a dynamic linked lists. Please refer to Lab 07 for the definition of a basic linked list. In this assignment you will need to use the basic ideas of a node and of a linked list of nodes to implement a suit of functions which can be used to create and maintain...
C++ Compsci 165: For your twelfth programming assignment you will be implementing a program that uses a linked list.You will be implementing the following structure and functions: struct LinkedList { int value; LinkedList *next; }; Note that with a singly linked list, you need to maintain a head pointer (pointer to the beginning of the list). Typically a tail pointer (pointer to the end of the list) is not maintained in a singly linked list (because you can only iterate...
Programing C Just with #include <stdio.h> We will create a singly linked list of 7 nodes. Then, the user will tell us whether to print the “odd-placed” nodes or the “even-placed” nodes. For example, if I had a list of 5 nodes like below, and the user specifies for the odd nodes to be printed, my program would print the values in nodes nl and n3. If the user instead indicated for the even nodes to be printed, my program...
I need help with coding with c++. I need to make a lottery program where you enter in 5 numbers from 0-9 and the program will generate 5 random numbers 0-9 to represent the lottery numbers. I'm almost done, but the output isn't exactly what I want. It works fine, but the format should look like this: lottery array: 7 4 9 1 3 user array: 4 2 9 7 p.s. I also need to count how many matching numbers...
i need this in c program please Computing Factorials Lab #2 Name your program lab2.c Start by asking the user to enter a number between 1 and 15 Check if the user has complied. Keep asking the user for a number between 1 and 15 until the user complies. Then ask if recursion is desired or not. If recursion is not desired call a function to calculate N! (where N is the number entered) – If recursion is required call...
I need this code in C programming. Can anyone pls help me in
this?
Project 8, Program Design A hotel owner would like to maintain a list of laundry service requests by the guests. Each request was stored with the room number, the guest's first name, last name, and number of items. The program laundry_list.ccontains the struct request declaration, function prototypes, and the main function. Complete the function definitions so it uses a dynamically allocated linked list to store the...
Need this in C++ Goals: Your task is to implement a binary search tree of linked lists of movies. Tree nodes will contain a letter of the alphabet and a linked list. The linked list will be an alphabetically sorted list of movies which start with that letter. MovieTree() ➔ Constructor: Initialize any member variables of the class to default ~MovieTree() ➔ Destructor: Free all memory that was allocated void printMovieInventory() ➔ Print every movie in the data structure in...