Passing lists to functions
First of all i would like to greet the forum,i just registered.Hope someday to be able to help here too,like you.
My assignment is about implementing a linked stack and a linked queue and my program should be able to enqueue-dequeue/push-pop,show and retrieve data from them (seperate operations for each).i have created all this using global variables to avoid double and triple pointers, but professor wants it with pointers.we are learning C this semester together with data structures,so i have zero experience with pointers.it took me days to write these 360 lines and i want it to be as it must be.i have noone to cooperate with,since i am the only one that had managed to do it...
my problem is passing lists to functions.this is the small part of my program ( enqueue a node to a linked queue) that i am working on to solve the problem,but i do not know what goes wrong with the pointers:
Code:
#include <stdio.h>
#include <malloc.h>
struct node
{
int info;
struct node *next;
};
void enqueue(struct node **fro,struct node **rea,struct node **tmp,int *qs);
struct node newnode(int value);
main()
{
int value,qsize=0;
struct node *front=NULL,*rear=NULL,*temp;
do{
scanf("%d",&value);
*temp = newnode(value);
enqueue(&front,&rear,&temp,&qsize);
} while (value!=0);
}
struct node newnode(int item)
{
struct node *tmp;
tmp=(struct node *)malloc(sizeof(struct node));
tmp->info=item;
tmp->next=NULL;
return *tmp;
}
void enqueue(struct node **fro,struct node **rea,struct node **tmpe,int *qs)
{
if(rea == NULL)
{
rea = tmpe;
fro= rea;
*qs++;
}
else
{
(*rea)->next = *tmpe;
rea = tmpe;
*qs++;
}
}
Thanks in advance.I would really appreciate it ,if you could suggest me a book or give me a link that could help me.