#include #include #include #define MAXSEATTYPES 5 #define MAXVENUES 15 #define MINVEN 2 #define MAXEVENTS 20 #define MINEVENTS 6 struct address { int stnum; char street[100]; int aptno; char city[100]; char state[2]; int zip5; char country[100]; }; struct seating { char stype; int smount; float discperc; float regperc; }; struct venue { int vcode; char venname[40]; char vtype; double venuecost; int vkindsstg; struct seating venseating[MAXSEATTYPES]; struct venue *next; }; struct event { int eday,emo,eyr; int elength; char esetting; double efixed; char ename[40]; }; int printvenbycode(struct venue *read, int tcode); int printonevenue(struct venue *read); int printven(struct venue *read); int input(struct venue venarray[15], struct event earray[20], int tv, int te); struct venue * sortl2s(struct venue *head); int main(void) { int done = 0; int cntr = 0; struct venue *newven=NULL, *currven = NULL, *headven = NULL, *folven=NULL; while (!done) { cntr++; newven = (struct venue *) malloc (sizeof(struct venue)); //print messages and read data into newven i.e. newven->vcode etc. newven->vcode = fabs(rand())/10000; //test data newven->next = NULL; printf("\nNewven vcode is %d",newven->vcode); //created linked list sorted smallest to largest by vcode if (headven == NULL) { headven = newven; printf("\nStarted new linked list"); printven(headven); } else if (headven->vcode > newven->vcode) //new element goes at front before head { newven->next = headven; headven = newven; printf("\nPut new head element on list"); printven(headven); } else { while ((currven->next != NULL) && (currven->vcode < newven->vcode)) { folven = currven; currven = currven->next; printf("\n moving through list at code :"); printonevenue(currven); } if (currven->vcode > newven->vcode) //new element goes between two elements in list { newven->next = currven; folven->next = newven; printf("\nAdded element in middle of list"); printven(headven); } //new element goes at end of list else { currven->next = newven; printf("\nAdded new element to end of list"); printven(headven); } } currven = headven; printf("\n Stuff in linked list"); printf("\nAre you done? Enter 1 for yes and 0 for no : "); scanf("%d",&done); if ((done)&&(cntrnext; } printf("\n"); } int printvenbycode(struct venue *read, int tcode) { printf("\nPrinting venue matching code %d\n",tcode); while(read != NULL) { if (tcode == read->vcode) printonevenue(read); read = read->next; } printf("\n"); return 0; } int printonevenue(struct venue *read) { printf("\n Vcode is %d",read->vcode); } int input(struct venue venarray[15], struct event earray[20], int tv, int te) { int m; struct venue temp; for (m = 0; m < tv; m++) { printf("\nVenue %d has code %d and %d kinds of seating",m+1,venarray[m].vcode, venarray[m].vkindsstg); } temp = venarray[0]; printf("\n\nVenue temp has code %d and %d kinds of seating",temp.vcode, temp.vkindsstg); return 1; }