Question

To solve real world problem, the programer uses ADT like list, stack, queue, set, map, ... etc. t...

To solve real world problem, the programer uses ADT like list, stack, queue, set, map, ... etc. to build our data model. In AS8, we pick and choose STL queue and stack to build a postfix calculator. In this assignment you are to Design your own linked-list, a series of integer nodes. The private attributes of this IntLinked Queue including a integer node struct and private control variables and methods: private: struct Node { int data; Node *next; }; Node *front; // -> first item Node *rear; // -> last item Node *p; // traversal position† Node *pp; // previous position int size; † The traversal and usage of position pointers is covered in above Section 2 item 4 video tutorial. The Integer Linked Queue, IntLinkedQueue class should have the following member functions: Constructor; Destructor; // return all dynamically allocated nodes bool isEmpty(); int getSize(); // size of the Queue void clear(int); string toString(); // return a string of a comma(,) delimited items e.g. "1, 2, 3, 4" Front and Rear port access: the following 4 methods return operation success or failure as True/False, and pass the item value In/Out as a reference. bool add(int &); // Front add bool append(int &) // Rear append bool fremove(int &); // Front Remove bool rremove(int &); // rear remove

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Test Code

Use the following source code for test menu and bulk entry command 'n':

int main()
{
        bool stay = true;

        // create one instance for each of the test classes
        cout << "\nInstanciate an object of Queue\n";
        string catchVar; // To hold values popped off the Queue
        IntLinkedQueue q;

        cout << "\nFirst, test with hard-wired data sets!\n"
                 << "For example, \nyou may use one set of tokens for all test classes: \n";
        string choice; // user input for choices
        string str; // user input for list, delimiter, ...
        int s[] = {1, 3, 5, 7, 9};
        vector input(s, end(s));

        // show the initial item list
        int input_size = input.size();
        for (auto item : input ) {
                cout << item << ((input_size <= 1) ? " " : ", ");
                input_size--;
        }
        cout << endl;

        // initialize the Queue class instances
        for (auto i: input) q.add( i );
        cout << "\nUse menu to test a Queue class instance.\n";
        menu();
        // main menu while
        while(stay) {  // main menu while starts
                cout << "\n       Enter your command: ";
                stay = true;
                cin >> choice;
                cin.ignore();
                int pos;
                string input;
                string token;
                int item;
                stringstream sst;
                stringstream ss;
                int Queue_size; 

                if(choice.size() == 1) {
                        char ch = choice[0];
                        vector dump;
                        string value;
                        switch(ch) {  // main menu switch starts
                                case 'N':
                                case 'n':
                                {
                                    if(!q.isEmpty()) q.clear();
                                    cout << "Enter a line of comma (,) delmited data set: ";
                                    getline (cin, input);                       // user input -> string
                                    ss << input;                  // string -> stream
                                    while ( getline(ss, token, ',') ) { // stream -> string token
                                                stringstream sst(token);
                                                sst >> item;
                                                q.add(item);
                                    }

                                    break;

Sample Test Run

Running /home/ubuntu/workspace/comsc-200SP19/m09-IntLinkeQ/testIntLinkedQueue.cpp

Instanciate an object of Queue

First, test with hard-wired data sets!
For example, 
you may use one set of tokens for all test classes: 
1, 3, 5, 7, 9 

Use menu to test a Queue class instance.

--- AS9 Integer LinkedQueue Test Menu ---
        N - to bulk create New Queue
        I - Index access
        D - to Display
        E - is Empty?
        A - to Add ~ push front
        a - to append ~ push back
        R - to Remove ~ pop front
        r - to Remove ~ pop back
        L - Length of Queue?
        C - to Clear
        Q - to Q this program
        H - this menu

        Enter your command: d
1, 3, 5, 7, 9
        Enter your command: a
                Enter a number: 11
                You have entered: 11
                Queue: 1, 3, 5, 7, 9, 11

        Enter your command: R
        removed 1
                Queue: 3, 5, 7, 9, 11

        Enter your command: I
                Enter the 0-based index: 3
                The Queue[3] is 9
                To modify y/n? y
                What is the new number? 8

        Enter your command: D
3, 5, 7, 8, 11
        Enter your command: L
                Number of Entries in Queue: 5

        Enter your command: C
                Queue is cleared.

        Enter your command: L
                Number of Entries in Queue: 0

        Enter your command: Q
Program exit
Add a comment
Know the answer?
Add Answer to:
To solve real world problem, the programer uses ADT like list, stack, queue, set, map, ... etc. t...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hello, I have some errors in my C++ code when I try to debug it. I...

    Hello, I have some errors in my C++ code when I try to debug it. I tried to follow the requirements stated below: Code: // Linked.h #ifndef INTLINKEDQUEUE #define INTLINKEDQUEUE #include <iostream> usingnamespace std; class IntLinkedQueue { private: struct Node { int data; Node *next; }; Node *front; // -> first item Node *rear; // -> last item Node *p; // traversal position Node *pp ; // previous position int size; // number of elements in the queue public: IntLinkedQueue();...

  • Are based on the following Queue class code segment class QueueFull {/* Empty exception class */};...

    Are based on the following Queue class code segment class QueueFull {/* Empty exception class */}; Class Queue Empty {/* Empty exception class */}; struct Node//Node structure int data;//Holds an integer Node* next;//Pointer to next node in the queue}; Class Queue//Linked node implementation of Queue ADT {Private: Node* front;//Pointer to front node of queue Node* rear;//pointer to last node of queue Public: Queue ()://default constructor initializes queue to be empty -Queue ();//Deallocates all nodes in the queue Void Add (int...

  • PROBLEM: string CBQueue::dequeue( ) This method should remove and return the item at the front of...

    PROBLEM: string CBQueue::dequeue( ) This method should remove and return the item at the front of the queue- please add comments EXISTING CODE: #include // this allows you to declare and use strings #include using namespace std; struct qNode {   string data;   qNode* next;   qNode* prev; }; class CBQueue {   public:     CBQueue(); int CBQueue::getSize( ); bool CBQueue::isEmpty( );   private:     qNode* front;     qNode* rear;     int size; }; #include "CBQueue.h" CBQueue::CBQueue() { front = NULL; rear = NULL; size = 0; }...

  • PROBLEM- void CBQueue::printF2B( ) If the queue is empty, the method should print “Queue is empty”,...

    PROBLEM- void CBQueue::printF2B( ) If the queue is empty, the method should print “Queue is empty”, otherwise, this method should print the items in the queue starting at the front of the queue and proceeding to the rear of the queue. The items should be printed one per line. Now that this method is written, you can do a more thorough job of testing enqueue( ). You will want to call printF2B( ) and printB2F( ) after implementing each method...

  • // Java Queue LinkedList Assignment // A queue is implemented using a singly linked list. //...

    // Java Queue LinkedList Assignment // A queue is implemented using a singly linked list. // the variable: back "points" at the first node in the linked list // new elements ( enqueued) are added at the back // the variable: front "points" at the last node in the linked list. // elements are removed (dequeued) from the front // // Several queue instance methods are provided for you; do not change these // Other instance methods are left for...

  • e. public class Queue { // Uses the correct Stack class from ME2 Ex 19 private Stack mStack; public Queue() { setStack(new Stack()); } public Queue enqueue(E pData) { getStack().push(pData); return t...

    e. public class Queue { // Uses the correct Stack class from ME2 Ex 19 private Stack mStack; public Queue() { setStack(new Stack()); } public Queue enqueue(E pData) { getStack().push(pData); return this; } public E dequeue() { return getStack().pop(); } public E peek() { return getStack.peek(); } private Stack getStack() { return mStack; } private void setStack(Stack pStack) { mStack = pStack; } } f. public class Queue extends Stack { // Uses the correct Stack class from ME2 Ex...

  • Implement the stack queue data structure with a linked list implementation to get the given test...

    Implement the stack queue data structure with a linked list implementation to get the given test code in driver.cpp to work properly: driver.cpp code: #include <iostream> #include "stackLL.h" using namespace std; int main() { /////////////Test code for stack /////////////// stackLL stk; stk.push(5); stk.push(13); stk.push(7); stk.push(3); stk.push(2); stk.push(11); cout << "Popping: " << stk.pop() << endl; cout << "Popping: " << stk.pop() << endl; stk.push(17); stk.push(19); stk.push(23); while( ! stk.empty() ) { cout << "Popping: " << stk.pop() << endl; }...

  • Using the provided table interface table.h and the sample linked list code linkedList.c, complete an implementation...

    Using the provided table interface table.h and the sample linked list code linkedList.c, complete an implementation of the Table ADT. Make sure that you apply the concepts of design by contract (DbC) to your implementation. Once you have fully implemented the table, create a main.c file that implements a testing framework for your table. Your table implementation must ensure that values inserted are unique, and internally sorted within a linked list. table.h #ifndef _TABLE_H #define _TABLE_H //----------------------------------------------------------------------------- // CONSTANTS AND...

  • JAVA Implement a MyQueue class which implements a queue using two stacks. private int maxCapacity...

    JAVA Implement a MyQueue class which implements a queue using two stacks. private int maxCapacity = 4; private Stack stack1; private Stack stack2; Note: You can use library Stack but you are not allowed to use library Queue and any of its methods Your Queue should not accept null or empty String or space as an input You need to implement the following methods using two stacks (stack1 & stack2) and also you can add more methods as well: public...

  • I need help fixing my code.   My output should be the following. Hello, world! : false...

    I need help fixing my code.   My output should be the following. Hello, world! : false A dog, a panic in a pagoda : true A dog, a plan, a canal, pagoda : true Aman, a plan, a canal--Panama! : true civic : true If I had a hi-fi : true Do geese see God? : true Madam, I’m Adam. : true Madam, in Eden, I’m Adam. : true Neil, a trap! Sid is part alien! : true Never odd...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT