Trying to build a program where user should be able to add queues, add elements on specified queue, remove element, print the number of elements in a queue and print the whole queue. I'm completely lost!!! I'm new on this and 100% confused. Here is the header file I have:
/* file : queue .h
Definitions for queue manipulation routines .
*/
#ifndef QUEUE_DEFINED
#define QUEUE_DEFINED
typedef struct qitem {
struct qitem * next ;
char * data ;
} item ;
typedef struct queue {
item *front , * back ;
} Queue ;
int queue_init ( Queue *q); /* return -1 on error */
int queue_empty ( Queue *q); /* return 1 if empty ;else 0 */
int queue_put ( Queue *q, item * new_item ); /* return -1 on error */
item * queue_get ( Queue *q); /* return 0 if the queue is empty */
#endif
/* end file : queue .h */
I didn't understand how I will initialise an item in main function, what I will pass for *next; ? This is what I have until now
/*This is the queue.c file*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "queue.h"
/*Initialise the queue*/
int queue_init ( MyQueue *q){
MyQueue _q = (MyQueue)malloc(sizeof(struct queue));
_q->front = NULL;
_q->back = NULL;
*q = _q
if(_q)
return 0;
else
return -1;
}
/*Check if is empty*/
int queue_empty ( Queue *q){
}
/*Add an element in th queue*/
int queue_put ( Queue *q, item * new_item ){
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "queue.h"
int main(int argc, char * argv[]){
item qitem;
Queue myQueue;
char selection;
printf("Please make a selection,\n");
printf("Add(A), List(L), Remove(R), Exit(Q)\n\n");
scanf(" %c", &selection);
return 0;
}
Need help please
toto_7


Sign In
Create Account


Back to top









