queue program

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2007
Posts: 2
Reputation: boyhenyo is an unknown quantity at this point 
Solved Threads: 0
boyhenyo boyhenyo is offline Offline
Newbie Poster

queue program

 
0
  #1
Oct 11th, 2007
hi please help me....can you give me a code for queue program???
the flow look like this:
KEY FUNCTION
E Enqueue
D Dequeue
H Hide implementation
S Show implementation
R Bubble sort

*note 10 numbers to be inputed.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,348
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: queue program

 
0
  #2
Oct 11th, 2007
Originally Posted by boyhenyo View Post
hi please help me....can you give me a code for queue program???
No.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 647
Reputation: jaepi is an unknown quantity at this point 
Solved Threads: 4
jaepi's Avatar
jaepi jaepi is offline Offline
Practically a Master Poster

Re: queue program

 
0
  #3
Oct 11th, 2007
> hi please help me....can you give me a code for queue program???

Lol. Very funny.
Retreat!!!
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 14
Reputation: vincent551987vn is an unknown quantity at this point 
Solved Threads: 1
vincent551987vn's Avatar
vincent551987vn vincent551987vn is offline Offline
Newbie Poster

Re: queue program

 
0
  #4
Oct 11th, 2007
I can give you the pseudcode ^,...,^. You'd better implement...

Enqueue:

1 if (queue full)
1 return false
2 allocate (newPtr)
3 newPtr -> data = data
4 newPtr -> next = null
5 if (queue.count = 0)
Insert into null queue
1 queue.front = newPtr
6 else
Insert into queue with data
1 queue.rear -> next = newPtr
7 queue.rear = newPtr
8 queue.count = queue.count + 1
9 return true
End enqueue
Dequeue:

if (queue empty)
1 return false
2 dataOut = queue.front -> data
3 dltPtr = queue.front
4 if (queue.count = 1)
Delete data in queue with
only one item
1 queue.rear = null
5 queue.front = queue.front -> next
6 queue.count = queue.count - 1
7 recycle (dltPtr)
8 return true
End dequeue
Say It Like It Is.
Có sao nói vậy.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,625
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 716
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: queue program

 
0
  #5
Oct 11th, 2007
>can you give me a code for queue program???
I can do one better. I'll give you code for a queue and a stack program:
  1. #ifndef JDEQUE_H
  2. #define JDEQUE_H
  3.  
  4. /* Increment or decrement an index with wraparound */
  5. #define _wrap_decr(i,n) ( (i) = ( (i) == 0 ? n - 1 : (i) - 1 ) )
  6. #define _wrap_incr(i,n) ( (i) = ( (i) == n - 1 ? 0 : (i) + 1 ) )
  7.  
  8. #define _deque_ready(d) ( (d)._base != 0 )
  9.  
  10. #define _deque_full(d) ( (d)._fill == (d)._size )
  11. #define _deque_empty(d) ( (d)._fill == 0 )
  12.  
  13. /* Generic push and pop. Calling code defines the index and update logic */
  14. #define _deque_push(d,x,i,f) ( ++(d)._fill, (d)._base[(i)] = (x), f ( (i), (d)._size ) )
  15. #define _deque_pop(d,i,f) ( --(d)._fill, (d)._base[f ( (i), (d)._size )] )
  16.  
  17. /* Concrete push/pop front and push/pop back */
  18. #define _deque_pushf(d,x) ( _deque_push ( (d), (x), (d)._front, _wrap_decr ) )
  19. #define _deque_pushb(d,x) ( _deque_push ( (d), (x), (d)._back, _wrap_incr ) )
  20. #define _deque_popf(d) ( _deque_pop ( (d), (d)._front, _wrap_incr ) )
  21. #define _deque_popb(d) ( _deque_pop ( (d), (d)._back, _wrap_decr ) )
  22.  
  23. #define _deque_init(d,buf,n) do { \
  24. (d)._base = (buf); \
  25. (d)._size = (n); \
  26. (d)._fill = 0; \
  27. (d)._front = 0; \
  28. (d)._back = 1; \
  29. } while ( 0 )
  30.  
  31. struct _deque {
  32. char *_base;
  33. unsigned _size;
  34. unsigned _fill;
  35. unsigned _front;
  36. unsigned _back;
  37. };
  38.  
  39. #endif
Of course, you'll have to figure out how to use it.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 2
Reputation: boyhenyo is an unknown quantity at this point 
Solved Threads: 0
boyhenyo boyhenyo is offline Offline
Newbie Poster

Re: queue program

 
0
  #6
Oct 11th, 2007
heres my code.
i cant make a declaration for the keys for enqueue, dequeue,hide implementation, show implementation and sorting...

here:

#include <stdio.h>
#include <conio.h>

#define MAX 10

void addq ( int *, int, int *, int * ) ;
int delq ( int *, int *, int * ) ;

void main( )
{
int arr[MAX] ;
int front = -1, rear = -1, i ;

clrscr( ) ;

addq ( arr, 23, &front, &rear ) ;
addq ( arr, 9, &front, &rear ) ;
addq ( arr, 11, &front, &rear ) ;
addq ( arr, -10, &front, &rear ) ;
addq ( arr, 25, &front, &rear ) ;
addq ( arr, 16, &front, &rear ) ;
addq ( arr, 17, &front, &rear ) ;
addq ( arr, 22, &front, &rear ) ;
addq ( arr, 19, &front, &rear ) ;
addq ( arr, 30, &front, &rear ) ;
addq ( arr, 32, &front, &rear ) ;

i = delq ( arr, &front, &rear ) ;
printf ( "\nItem deleted: %d", i ) ;

i = delq ( arr, &front, &rear ) ;
printf ( "\nItem deleted: %d", i ) ;

i = delq ( arr, &front, &rear ) ;
printf ( "\nItem deleted: %d", i ) ;

getch( ) ;
}

/* adds an element to the queue */
void addq ( int *arr, int item, int *pfront, int *prear )
{
if ( *prear == MAX - 1 )
{
printf ( "\nQueue is full." ) ;
return ;
}

( *prear )++ ;
arr[*prear] = item ;

if ( *pfront == -1 )
*pfront = 0 ;
}

/* removes an element from the queue */
int delq ( int *arr, int *pfront, int *prear )
{
int data ;

if ( *pfront == -1 )
{
printf ( "\nQueue is Empty." ) ;
return NULL ;
}

data = arr[*pfront] ;
arr[*pfront] = 0 ;
if ( *pfront == *prear )
*pfront = *prear = -1 ;
else
( *pfront )++ ;

return data ;
}
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC