Thread: Queue class algorith/code

  1. #1
    Registered User verbity's Avatar
    Join Date
    Nov 2006
    Posts
    101

    Question Queue class algorith/code

    Hello people!! I have a queue class that works just fine. But I need to have it spit out permutations of A B C. Like A , B, C, AA, AB, AC, BA, BB, BC, ..... CCC. I haven't the vaguest idea how to even get started on this part. My professor said something like print add add put in rear or something like that...but I didn't really understand.

    Here's my client class:

    Code:
    #include <iostream>
    #include <string>
    #include "queue.h"
    
    
    int main(void)
    {
    	Queue myLine; //myLine is a new queue object
    
    	char userans;
    	el_t eltoget, eltoadd;
    
    	cout << "Enter your choice Q to quit or something else";
    	cin >> userans;
    	
    	while((userans != 'Q') && (!myLine.isFull()))
    	{
    		cout << "Give me an element to add: ";
    		cin >> eltoadd;
    		myLine.add(eltoadd);
    
    		cout << "Enter your choice Q to quit or something else";
    		cin >> userans;
    	}
    
    	cout << "The Line has " << myLine.getSize() << " elements." << endl;
    	cout << "Now removing and displaying all elements..." << endl;
    	
    	while(!myLine.isEmpty())
    	{
    		myLine.remove(eltoget);
    		cout << eltoget << endl;
    	}
    
    	system("pause");
    	return 0;
    }

    I'm sure some smart person in here has done this type of thing...if you could just steer me in the right direction I could probably handle it from there....

    Thanks for any help!

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You'll have to decide whether you're trying to build permutations (as in shuffle), or the list of things that you had listed instead (all the one-, two-, and three-letter words from a three-letter alphabet?).

    I believe a permutation algorithm has been posted here on the boards a couple of times at least. On the other hand, it certainly didn't use a queue. I'm sure there's a data structure less useful in this situation than a queue, but I'm not sure what it could be. (Linked lists and stacks seem equally un-useful to me right now.)

  3. #3
    Registered User verbity's Avatar
    Join Date
    Nov 2006
    Posts
    101
    It has to be an unuseful list with a queue.

  4. #4
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    My professor said [...] I didn't really understand.
    myLine.remove(eltoget);
    It has to be an unuseful list with a queue.
    Your professor is a quack.

    Algorithms for generating permutations and combinations have nothing to do with the data structures you might use to store permutations and combinations.

    I'm sure there's a data [...] sure what it could be.
    Trie?

    Soma

  5. #5
    Registered User verbity's Avatar
    Join Date
    Nov 2006
    Posts
    101
    Your professor is a quack.
    This is very true...but I still need to do this stupid assignment. Actually I shouldn't call it stupid since I can't figure it out.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Fixing my program
    By Mcwaffle in forum C Programming
    Replies: 5
    Last Post: 11-05-2008, 03:55 AM
  2. Default class template problem
    By Elysia in forum C++ Programming
    Replies: 5
    Last Post: 07-11-2008, 08:44 AM
  3. Queue implementation
    By kolliash in forum C Programming
    Replies: 1
    Last Post: 06-01-2008, 08:25 AM
  4. Replies: 7
    Last Post: 05-26-2005, 10:48 AM
  5. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM