need to get this source file to interact with my file with queue functions. Please Help !!
Here's the source file with queue functionsCode:/********************/ /* queue_main.c */ /********************/ #include <stdio.h> #include <stdlib.h> #include "stack.h" int count; main() { int number, choice; make_empty(); for( ; ; ) { printf("\nChoose one of the following.\n\n" "0 To end program\n" "1 To add a value to list (Push)\n" "2 To remove top value from list (Pop)\n" "3 To print list \n" "4 To list # of nodes\n\n"); printf("Enter your choice: "); scanf("%d", &choice); printf("\n"); switch(choice) { case 0: printf("You have ended the program.\n" "Good-bye !! \n\n"); exit(0); case 1: printf("Enter a number to push: "); scanf("%d", &number); push(number); break; case 2: number = pop(); printf("You just removed %d\n", number); break; case 3: print_list(); break; case 4: printf("You have %d nodes in your list\n",count); break; default: printf("Illegal choice.\n"); } } return 0; }
Code:/*************************/ /* queue.c */ /*************************/ #include <stdio.h> #include <stdlib.h> #define MAX_SIZE 6 struct node { int data; struct node * next; }; struct node *first; struct node *last; int count; void make_empty() { first = NULL; last = NULL; count = 0; } int is_empty(void) { return count == 0; } int is_full(void) { return count == MAX_SIZE; } void push(int insert_value) { last->data = insert_value; last->next = first; count++; } int pop(void) { int i; struct node *last, *ptr; last = malloc (sizeof(struct node)); ptr = malloc (sizeof (struct node)); if (last == NULL || ptr == NULL) { printf("\nThere was error in allocating memory.\n"); exit(EXIT_FAILURE); } if (is_empty()) { printf("Error in pop: stack is empty.\n"); exit (EXIT_FAILURE); } for (last = first ; last != NULL; last = last->next) { if (last->next != NULL) { ptr = last; } i = last->data; } ptr->next = NULL; free(last); count--; return i; } void print_list() { struct node *ptr; if (first == NULL) { printf("List is empty.\n\n"); } else { printf("\n\nHere is your list: \n"); for (ptr=first;ptr;ptr=ptr->next) printf("%d\n",ptr->data); return; } }



LinkBack URL
About LinkBacks



