Jump to content

Dynamic Data Structures problem

- - - - -

  • Please log in to reply
2 replies to this topic

#1
toto_7

toto_7

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 295 posts
Hello,

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

"Programming is like sex. One mistake and you have to support it for the rest of your life."

-Michael Sinz

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
I would change your declaration to:

Queue* queue_init ( ); /* return 0 on error */

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
toto_7

toto_7

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 295 posts
Thank you for response WingedPanther, I can't change header file.

"Programming is like sex. One mistake and you have to support it for the rest of your life."

-Michael Sinz




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users