Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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):image text in transcribedMy 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: ".%s ", progname); exit(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 archevent(olnode list, int xevent, olnode *current, olnode **previous); The modules needed are place in file a2.c): 1. int main(int argc, char **argv): of course.. 2. void usage( char *progname); prints usage to stderr and terminates execution 3. int nextevent(void); returns next event generated (via rand()) 4. int insertevent folnode *ylist, int event): insert event in its proper place in list, returns 0 on failure and l on success 5. void srchevent(olnode "list, int xevent, olnode "current, olnode **previous): current points to node containing xevent on success, on failure current is undefined, previous always points to predecessor of current. Called by insertevent(). 6. void displayevents(olnode list); print list contents to stdout, as comma separated event frequency pairs (as many pairs as can fit on entire line of output) (Sample output: eeee ! ffff, eeee ! ffff, ... something like this ... *previous = NULL; *current = list; (current)->eventnr is event! (current)->eventfq is event frequency!! ("current) ->next is pointer to next node in list (can be NULL) etc. 9. void freelist(olnode list): returns the storage for list back to system, one node at a time, using freenode(), list is empty after this call. Others: Look at system calls and functions as needed (srand(), rand(). printf(), exit() etc.). Events to process are passed in command line argument. Print all error messages to stderr using fprintf(). Documenting and testing is an essential part of programming process (see handout on documenting a program and follow the style!!). Note: Do pay attention to details: . documentation and style (see documenting a program handout) including rules of English grammar and spellings, . keep line length

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions