IT Community - Software Programming, Web Development and Technical Support

How would you implement a queue from a stack?

This is a discussion on How would you implement a queue from a stack? within the C and C++ Programming forums, part of the Software Development category; Hi, Any one Explain. Thanks, Sundar Raja...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C and C++ Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-21-2007, 12:33 AM
sundarraja sundarraja is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Posts: 174
sundarraja is on a distinguished road
Question How would you implement a queue from a stack?

Hi,

Any one Explain.

Thanks,
Sundar Raja
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-31-2007, 03:49 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Arrow Re: How would you implement a queue from a stack?

Stack* stack_init();
void push(Stack*, int);
int pop(Stack*);
void stack_free(Stack*);

struct Queue {
struct Stack* stack_;
}

Queue* queue_init()
{
Queue* queue = new Queue;
queue->stack_ = stack_init();
}

void inque(Queue* que, int newvalue)
{
Stack* temp = stack_init();
int value;
while((value = pop(que->stack_) != EOF){
push(temp, value);
}
push(que->stack_, newvalue);
while((value = pop(temp)) != EOF){
push(que->stack_, value);
}
}

int outque(Queue* que)
{
pop(que->stack_);
}

void queue_free(Queue* que)
{
stack_free(que->stack_);
delete que;
}
__________________
The KINGMAKER
Makes Every Thing Possible

Stuffs (My Blog)
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make a queue unavailable in SQL server Sundaram Database Support 1 03-13-2008 09:12 AM
Using Stack in C# SaravananJ C# Programming 1 03-12-2008 01:12 AM
Using Queue in C# SaravananJ C# Programming 2 12-29-2007 01:22 AM
What is the minimum number of queues needed to implement the priority queue? sundarraja C and C++ Programming 1 07-31-2007 02:34 AM
Local Delivery queue vigneshgets Operating Systems 1 07-18-2007 04:48 AM


All times are GMT -7. The time now is 03:52 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0