Data Structure in C -.o0 Queue 0o.-

I

# include

queue is importnant in people live to organize the cocity, this code i
wnat to share with others
and recieve comment about, with all of my thanks
# include<stdio.h>
# define MAX 100

typedef int itemtype;

typedef struct queue{
itemtype item[MAX];
int f;
int r;
}Queue;


void clear(Queue *q)
{
q->r=0;
q->f=0;
}


void enq(Queue *q,itemtype x)
{
q->r=(q->r+1)%MAX;
q->item[q->r]=x;
}


void deq(Queue *q,itemtype *x)
{
q->f=(q->f+1)%MAX;
*x=q->item[q->f];
}


int empty(Queue *q)
{
return (q->r==q->f);
}


int full(Queue *q)
{
return ((q->r+1)%MAX==q->f);
}


main()
{
int i;
Queue q1;
clear(&q1);

for(i=0;i<10;i++)
if (!full(&q1)) enq(&q1,i);

while(!empty(&q1))
{
deq(&q1,&i);
printf("%d\n",i);
}

}
 
C

Carl R. Davies

# include said:
queue is importnant in people live to organize the cocity, this code i
wnat to share with others
and recieve comment about, with all of my thanks
<snip>lots of code</snip>

I try to read lots of C books to quickly learn new tricks, coding
standards, algorithms, etc. and I have to say I've seen much better
implementations of queues than yours. Sorry.

Even with my limited knowledge I'd have to say that as a library there
are issues here such as limiting the queue size and hardcoding the type
to int.

I'd suggest you read up on some implementations, I think "C Unleashed"
has a pretty decent implementation that uses a single linked list. I've
also seen one in "C How to program". Try grep'ing the best ideas out of
these books and see what you get.
 
V

Vladimir S. Oka

# include said:
queue is importnant in people live to organize the cocity, this code i
wnat to share with others
and recieve comment about, with all of my thanks

<snip... unreadable code>

Your code (and not just in this post) is unreadable and therefore of
low quality. It most likely suffers from other problems as well, but
being unreadable, it's difficult to say.

You could start improving your code by judicious use of whitespace...
 
U

Ulrich Eckhardt

# include said:
# define MAX 100

typedef int itemtype;

typedef struct queue{
itemtype item[MAX];
int f;
int r;
}Queue;

void clear(Queue *q)
{ assert(q);
q->r=0;
q->f=0;
}


void enq(Queue *q,itemtype x)
{ assert(q);
q->r=(q->r+1)%MAX;
q->item[q->r]=x;
}


void deq(Queue *q,itemtype *x)
{
assert(q);
assert(x);
q->f=(q->f+1)%MAX;
*x=q->item[q->f];
}


int empty(Queue *q)
int empty(Queue const* q)
bool empty(Queue const* q)
assert(q);
int full(Queue *q)
int full(Queue const* q)
bool full(Queue const* q)
assert(q);


int main()

Please read this group's FAQ.

Uli
 
N

Nelu

# include said:
queue is importnant in people live to organize the cocity, this code i
wnat to share with others
and recieve comment about, with all of my thanks

int main(void)

What is it that you want with that piece of code?
Do you want someone to validate the code?
A queue may be important but can be implemented in different ways. Not
everybody wants a circular array queue.
 
C

CBFalconer

Vladimir S. Oka said:
<snip... unreadable code>

Your code (and not just in this post) is unreadable and therefore
of low quality. It most likely suffers from other problems as
well, but being unreadable, it's difficult to say.

You could start improving your code by judicious use of whitespace...

Not to mention his atrocious choice of variable names. Next.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
 
D

Dave Thompson

queue is importnant in people live to organize the cocity, this code i
wnat to share with others
and recieve comment about, with all of my thanks

I'm sorry; I try hard not to post _solely_ with spellling/grammar
complaints (although I will include them in a more substantive
response) but I can't come up with anything even resembling a
plausible guess at what 'cocity' above was meant to be.

- David.Thompson1 at worldnet.att.net
 
V

Vladimir S. Oka

Dave Thompson opined:
I'm sorry; I try hard not to post _solely_ with spellling/grammar
complaints (although I will include them in a more substantive
response) but I can't come up with anything even resembling a
plausible guess at what 'cocity' above was meant to be.

Purely based on phonetics, and taking into account that these would be
fairly broken with OP as well, I submit the possibility that it's
actually supposed to be "society" [so-s-ai-tee]. ;-)

--
BR, Vladimir

"The pyramid is opening!"
"Which one?"
"The one with the ever-widening hole in it!"
 
S

santosh

# include said:
queue is importnant in people live to organize the cocity, this code i
wnat to share with others
and recieve comment about, with all of my thanks

I apologise if I'm wrong, but you sound awfully like
'RSolsCarlLiola'...
 
D

David Resnick

santosh said:
I apologise if I'm wrong, but you sound awfully like
'RSolsCarlLiola'...

He is missing some key RoSsIaCrIiLoIA hallmarks. For example,
he lacks the obfuscators typical of that particular troll, such as:

#define R return
#define W while

He also hasn't posted 4 or 5 followups to his own message, which
RoSsIaCrIiLoIA.

I think this is just a confused newby whose first language is clearly
not English.

-David
 
V

Vladimir S. Oka

David said:
He is missing some key RoSsIaCrIiLoIA hallmarks. For example,
he lacks the obfuscators typical of that particular troll, such as:

#define R return
#define W while

He also hasn't posted 4 or 5 followups to his own message, which
RoSsIaCrIiLoIA.

You've missed the propensity to post wades of assembly language. *That*
is the RoSsIaCrIiLoIA we all love and PLONK.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,947
Members
47,498
Latest member
log5Sshell/alfa5

Latest Threads

Top