943,711 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 9274
  • C++ RSS
Oct 11th, 2007
0

queue program

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
boyhenyo is offline Offline
2 posts
since Oct 2007
Oct 11th, 2007
0

Re: queue program

Click to Expand / Collapse  Quote originally posted by boyhenyo ...
hi please help me....can you give me a code for queue program???
No.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Oct 11th, 2007
0

Re: queue program

> hi please help me....can you give me a code for queue program???

Lol. Very funny.
Reputation Points: 32
Solved Threads: 4
Practically a Master Poster
jaepi is offline Offline
647 posts
since Jul 2006
Oct 11th, 2007
0

Re: queue program

I can give you the pseudcode ^,...,^. You'd better implement...

Enqueue:

Quote ...
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:

Quote ...
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
Reputation Points: 10
Solved Threads: 1
Newbie Poster
vincent551987vn is offline Offline
14 posts
since Oct 2007
Oct 11th, 2007
0

Re: queue program

>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:
C++ Syntax (Toggle Plain Text)
  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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Oct 11th, 2007
0

Re: queue program

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 ;
}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
boyhenyo is offline Offline
2 posts
since Oct 2007
Aug 28th, 2010
0
Re: queue program
I want a program in queue using classes in cpp
Reputation Points: 10
Solved Threads: 0
Newbie Poster
polisure is offline Offline
2 posts
since Aug 2010
Aug 28th, 2010
0
Re: queue program
program to write an object and read an object from file in cpp
program to copy contents of one file to another file in cpp
program to concatenate two files in cpp.
Last edited by polisure; Aug 28th, 2010 at 5:22 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
polisure is offline Offline
2 posts
since Aug 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Polymorphism puzzle
Next Thread in C++ Forum Timeline: Reading from registers





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC