Question
I need help with this assignment because I am having a hard time understanding what it is asking. I am hoping someone adept with the
I need help with this assignment because I am having a hard time understanding what it is asking. I am hoping someone adept with the C language will better understand how to implement what the assignment is asking for. Thanks in advance!
Assignment (right click and select open in new tab to better view it):My incomplete code that doesn't work:
#include #include
#define RANGE 53
typedef struct olnode { int eventnr; int eventfq; struct olnode *next; } olnode;
int main(int argc, char **argv) { int a, i; a = atoi(argv[1]);
olnode *list[a];
// checking for sanity. if (a
for (i = 0; i
/* Print usage to stderr on command line errors and terminate */ void usage(char *progname) { fprintf(stderr, "usage: "./%s ", progname); exit(1); }
olnode createnode(void) { olnode temp; // declare a node temp = (olnode) malloc(sizeof(struct olnode)); // allocate memory using malloc() temp->next = NULL;// make next point to NULL return temp;//return the new node }
int nextevent(void) { return rand(0); }
int insertevent(olnode **list, int event) { olnode temp,p; // declare two nodes temp and p temp = createNode();//createNode will return a new node with data = value and next pointing to NULL. temp->eventnr = event; // add element's value to data part of node if(**list == NULL) { **list = temp; //when linked list is empty return 1; } else { p = list;//assign head to p while (p->next != NULL && p->next->eventnr eventnr) { p = p->next; } temp->next = p->next; p->next = temp; } return 1; }
/* Searches the list for xevent, current points to node containing xevent which is undefined if the search failed. Previous always points to the predecessor of current. It returns current and previous to the caller. */ void srchevent(olnode *list, int xevent, olnode **current, olnode **previous) { olnode p; p = list; while (p != NULL) { p = p->next; if(p->eventnr == xevent) { (*current)->eventnr = xevent; } } }
void displayevents(olnode *list) { while(list != NULL) { printf("%d : %d, ", list->eventnr, list->eventfq); } }
void freelist(olnode **list) { while(list != NULL) { free(list); list = (*list)->next; } }
Page 1 of 2 a2.txt Page 2 of 2 a2.txt CPS 340, Assignment #2, Points: 10 The algorithm is: Goal: to learn Linux programming environment and implementation of a singly linked ordered list and memory management. Constraints: - no header nodes for list no violation of specifications (function-id, or its interface) - no line wraps (wraparound in display) keep line length You must use Makefile to compile your program. (similar to one used for assignment 1) --- globals ---- Turn-in: Submit via BB tape archive file global-id>-a2.tar containing files a2/Makefile, a2/a2.c. #define RANGE 53 -------- Jump start code --- Print usage to stderr on command line errors and terminate typedef struct olnode { int eventnr: int event fq; struct olnode "next; } olnode: void usage(char *progname) fprintf(stderr, "usage: ".%sStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started