Like Tree1Likes
  • 1 Post By Neo1

Help!!!! PLEASE! Stack, Vector, Queue, Templete, Binary Trees ...

This is a discussion on Help!!!! PLEASE! Stack, Vector, Queue, Templete, Binary Trees ... within the C++ Programming forums, part of the General Programming Boards category; My Lab assignment just corrupted and I hadn't finished debugging my errors. I last worked on it two days ago. ...

  1. #1
    Registered User
    Join Date
    Dec 2013
    Posts
    3

    Question Help!!!! PLEASE! Stack, Vector, Queue, Templete, Binary Trees ...

    My Lab assignment just corrupted and I hadn't finished debugging my errors. I last worked on it two days ago. I can't remember what I had after a week of debugging and tweaking. my assignment was due last night, but my professor gave me a extension for a few hours (that is almost up and I am nowhere! Its like my brain is fried for finals!) Any and all help .. please! here is the info....

    code given:
    Code:
    // Lab10a  Stacks and Queues
    
    #include <iostream>
    #include <string>
    #include <vector>
    #include <stack>
    #include <queue>
    
    using namespace std;
    
    template <class T>
    bool Same(vector <T> tVector);
    
    
    int main()
    {
        const int SIZE_INT = 8;
        const int SIZE_STRING = 6;
    
        
        int iTemp1[]= {1,1,2,3,3,2,1,1};
        int iTemp2[]= {1,1,2,3,2,3,1,1};
    
    
        vector <int> iVector1(iTemp1, iTemp1 + SIZE_INT);
        vector <int> iVector2(iTemp2, iTemp2+ SIZE_INT);
    
        string sTemp1[]= {"aa", "bb", "cc", "cc", "bb", "aa"};
        string sTemp2[]= {"aa", "bb", "cc", "bb", "cc", "aa"};
    
        vector <string> sVector1(sTemp1, sTemp1 + SIZE_STRING);
        vector <string> sVector2(sTemp2, sTemp2 + SIZE_STRING);
        
        if (Same(iVector1))
            cout << "iVector1 values are in the same order forwards and backwards\n";
        else
            cout << "iVector1 values are NOT in the same order forwards and backwards\n";
    
        if (Same(iVector2))
            cout << "iVector2 values are in the same order forwards and backwards\n";
        else
            cout << "iVector2 values are NOT in the same order forwards and backwards\n";
    
        if (Same(sVector1))
            cout << "sVector1 values are in the same order forwards and backwards\n";
        else
            cout << "sVector1 values are NOT in the same order forwards and backwards\n";
    
        if (Same(sVector2))
            cout << "sVector2 values are in the same order forwards and backwards\n";
        else
            cout << "sVector2 values are NOT in the same order forwards and backwards\n";
    
        system("pause");
        return 0;
    }
    
    template <class T>
    bool Same(vector <T> tVector)
    {
    
        /*Write the code for this function.  You must use one STL stack of 
        type T and one STL queue of type T.  You should not have more than 15 lines of
        code total.*/
        
    }
    and documentation
    [quote]Finish the code for Lab10a.cpp . You will write code for the Same function which will return
    true if the values of the elements of the vector that is passed to it are the same read both
    forwards and backwards. If they are not the same in both directions, it will return false.
    Donít change anything in the main function or add any additional functions to the program.

    Output should match iVector1 same order, iVector2 Not same order, sVector1 same, and sVector2 not in same order.



    and then the second part:
    Trees - Part B (25 points)
    Please complete the program below exactly as described. Donít add anything extra to it
    (methods, extra variables, features, etc.) and donít leave any features described below out.
    You are going to write a function that will use recursion to count the number of nodes in a tree. First
    use the code on page 1141-1142 to develop the IntBinaryTree class (For the member functions,
    you only need the code for the constructor and the insert member function). Your main program will
    call a public member function called numNodes. This function will then call a private member
    function, countNodes, that will use recursion to count the number of nodes in the entire tree:
    Code:
    int  IntBinaryTree::countNodes(TreeNode *nodePtr) 
    { 
     if (nodePtr == NULL) 
      //write only one line of code here 
     else 
      //write only one line of code here 
    } 
     
    int main() 
    { 
       IntBinaryTree tree; 
        
       tree.insertNode(14); 
       tree.insertNode(10); 
       tree.insertNode(8); 
       tree.insertNode(6); 
       tree.insertNode(5); 
       tree.insertNode(7); 
       tree.insertNode(9); 
       tree.insertNode(12); 
       tree.insertNode(11); 
       tree.insertNode(13); 
       tree.insertNode(22); 
       tree.insertNode(30); 
       tree.insertNode(32); 
       tree.insertNode(24); 
       tree.insertNode(20); 
       tree.insertNode(17); 
       tree.insertNode(15); 
       tree.insertNode(18); 
       tree.insertNode(21);    
     
       cout <<"The number of nodes in the tree is: " << tree.numNodes()<<endl; 
     
       return 0; 
    }
    Code from pages 1140-1142:

    InBinaryTree.h
    Code:
    // Specification file for the IntBinaryTree class
    #ifndef INTBINARYTREE_H
    #define INTBINARYTREE_H
    
    class IntBinaryTree
    {
    private:
       struct TreeNode
       {
          int value;         // The value in the node
          TreeNode *left;    // Pointer to left child node
          TreeNode *right;   // Pointer to right child node
       };
    
       TreeNode *root;       // Pointer to the root node
       
       // Private member functions
       void insert(TreeNode *&, TreeNode *&);
       void destroySubTree(TreeNode *);
       void deleteNode(int, TreeNode *&);
       void makeDeletion(TreeNode *&);
       void displayInOrder(TreeNode *) const;
       void displayPreOrder(TreeNode *) const;
       void displayPostOrder(TreeNode *) const;
       
    public:
       // Constructor
       IntBinaryTree()
          { root = NULL; }
          
       // Destructor
       ~IntBinaryTree()
          { destroySubTree(root); }
          
       // Binary tree operations
       void insertNode(int);
       bool searchNode(int);
       void remove(int);
       
       void displayInOrder() const
          {  displayInOrder(root); }
          
       void displayPreOrder() const
          {  displayPreOrder(root); }
          
       void displayPostOrder() const
          {  displayPostOrder(root); }
    };
    #endif
    Can Anyone help me!!!

  2. #2
    Registered User
    Join Date
    Dec 2013
    Posts
    3
    PLease! I am down to 1 hour until I fail this lab! I have been trying to finish this all day, but I cannot jog my memory. My brain is burned out... Please Anyone?

  3. #3
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    Quote Originally Posted by vcj2d View Post
    PLease! I am down to 1 hour until I fail this lab! I have been trying to finish this all day, but I cannot jog my memory. My brain is burned out... Please Anyone?
    Seems like you've put this off for too long then. Show us what you have so far for the assignments, then we can point you in the right direction.

    Edit:

    Also, if this is your finals, make sure that you are allowed to seek help from external sources such as this board. You know... academic integrity and all that jazz.
    Salem likes this.
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  4. #4
    Registered User
    Join Date
    Dec 2013
    Posts
    3
    No this isn't our final... it is our last lab assignment... I had almost finished it two days ago in class with professor... however, with work, taking 23 credit hours worth of classes doesnt leave alot of time to do anything... When I last worked on this, my professor said I had 2 lines to add, and 2 things to research on how they were formatted... but other then that, since I worked with him on almost the entire assignment, I am iffy about the whole thing..

    for part a: I have no clue, I have tried several things, to discover i still dont fully understand what is being done nor how...
    so I really don't have anythign solid to present here

    for part b i have to change only the code in the cpp and header files... in cpp its:
    Code:
    int  IntBinaryTree::numNodes(TreeNode *nodePtr) 
    { 
     if (nodePtr == NULL) // A nothing with no children: zero nodes here
      return 0;
     else // A node with 0, 1 or 2 children and further "offspring"
      return 1 + numNodes(nodePtr->leftChild) + numNodes(nodePtr->rightChild);
    }
    for the header file
    Code:
    // Specification file for the IntBinaryTree class
    #ifndef INTBINARYTREE_H
    #define INTBINARYTREE_H
    
    
    class IntBinaryTree
    {
    private:
       struct TreeNode
       {
          int value;         // The value in the node
          TreeNode *left;    // Pointer to left child node
          TreeNode *right;   // Pointer to right child node
       };
    
    
       TreeNode *root;       // Pointer to the root node
       
       // Private member functions
       void insert(TreeNode *&, TreeNode *&);
       void countNodes(TreeNode *); //still lost here
       
    public:
       // Constructor
       IntBinaryTree()
          { root = NULL; }
       // Binary tree operations
       void insertNode(int)
       {}
       void numNodes (int) 
       { countNodes(int);} ///but i dont think this is right
        
    
    
    };

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stack and Queue
    By audinue in forum C Programming
    Replies: 7
    Last Post: 07-04-2008, 12:28 PM
  2. Converting From Binary Tree to Threaded Binary Trees
    By elton_fan in forum C Programming
    Replies: 15
    Last Post: 11-08-2007, 10:41 PM
  3. Binary Trees MINI MAXING, probability trees
    By curlious in forum General AI Programming
    Replies: 3
    Last Post: 09-30-2005, 10:57 AM
  4. queue / stack
    By smd in forum C++ Programming
    Replies: 2
    Last Post: 07-26-2002, 01:30 PM
  5. traversing binary trees or partial trees
    By sballew in forum C Programming
    Replies: 4
    Last Post: 12-05-2001, 08:19 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21