Question

PROGRAMMING 1. The LinkList class that we discussed in class is implemented using pointer t constructed with a list of nodes, and the first node pointer points to the front I a) (10 pts) Complete the following class declaration which is similar to Linklist class ecter class (Write only the prototypes and the private data field; definitions will follow the class declaration) template stypenane T> olass Linkedveoter t private olass Node publie T info Node next typedet Node *nodePtr publie LinkedVector ) bool emptyo //constructor //determine if the LinkedVector is empty void Push back(T stem) //add an item at the back //returns the front item T Frontt) T Back( int Length) //returns the back item //returns the number of items in the object //copy constructor //overloaded assignment operator //destructor //At (int n) function, which returns the element at position n in //the LinkedVector. The parameter is the position of an element //in the LinkedVector. The return value is the element at the //specified position in the LinkedVector. // Pop_ back) function, which removes the last item of the // Linkedvector private: // node pointer which points to the front (first node)
media%2F3ce%2F3ce45b15-5e89-46fa-bb61-45
0 0
Add a comment Improve this question Transcribed image text
Answer #1

(A)

public:

    // copy constructor

    LinkedVector( const LinkedVector& ob );

    // overload assignment operator

    LinkedVector& operator=(const LinkedVector& ob);

    // destructor

    ~LinkedVector();

    T At( int n );

    // remove the last node in the list

    void pop_back();

private:

   

    // point to the first node

    Node *front;

(B)

T At(int n)

{

    // if entered position is invalid

    if( n <= 0 || n >= length )

        return NULL;

   

    // point trav to the first node

    Node *trav = this->first;

   

    int i = 1;

   

    // traverse the list

    while( !trav )

    {

        // if the current node is the required node

        if( i == n )

            return trav->info;

       

        // go to next node

        trav = trav->next;

    }

   

    return NULL;

}

int Length()

{

    // point trav to the first node

    Node *trav = this->first;

   

    // store the length of list

    int i = 0;

   

    // traverse the list

    while( !trav )

    {

        i++;

       

        // go to next node

        trav = trav->next;

    }

   

    return i;

}

void Push_back(T item)

{

    // create a new node

    Node *new_node = new Node();

   

    // set the value of node

    new_node->info = item;

   

    new_node->next = this->front;

   

    // make new_node as the new front of the list

    this->front = new_node;

}

(C)

template<typename T>

void split(LinkedVector<T> aVec, LinkedVector<T> &v1, LinkedVector<T> &v2, T pivotal)

{

    int i;

   

    // traverse aVec

    for( i = 1 ; i <= aVec.Length() ; i++ )

    {

        // get the elemeny at position i

        T x = aVec.At( i );

       

        if( x < pivotal )

            v1.Push_back( x );

        else

            v2.Push_back( x );

    }

}

Add a comment
Know the answer?
Add Answer to:
PROGRAMMING 1. The LinkList class that we discussed in class is implemented using pointer t constructed...
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
  • IntList Recursion Assignment Specifications: You will add some additional recursive functions to your IntList class as...

    IntList Recursion Assignment Specifications: You will add some additional recursive functions to your IntList class as well as make sure the Big 3 are defined. IntNode class I am providing the IntNode class you are required to use. Place this class definition within the IntList.h file exactly as is. Make sure you place it above the definition of your IntList class. Notice that you will not code an implementation file for the IntNode class. The IntNode constructor has been defined...

  • Design and implement your own linked list class to hold a sorted list of integers in ascending order. The class should h...

    Design and implement your own linked list class to hold a sorted list of integers in ascending order. The class should have member function for inserting an item in the list, deleting an item from the list, and searching the list for an item. Note: the search function should return the position of the item in the list (first item at position 0) and -1 if not found. In addition, it should member functions to display the list, check if...

  • Design and implement your own linked list class to hold a sorted list of integers in...

    Design and implement your own linked list class to hold a sorted list of integers in ascending order. The class should have member function for inserting an item in the list, deleting an item from the list, and searching the list for an item. Note: the search function should return the position of the item in the list (first item at position 0) and -1 if not found. In addition, it should member functions to display the list, check if...

  • 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...

  • // thanks for helping // C++ homework // The homework is to complete below in the...

    // thanks for helping // C++ homework // The homework is to complete below in the stack.h : // 1. the copy constructor // 2. the assignment operator // 3. the destructor // 4. Write a test program (mytest.cpp) to test copy and assignment // 5. Verify destructor by running the test program in Valgrind // This is the main.cpp #include <iostream> #include "stack.h" using namespace std; int main() { Stack<int> intStack; cout << "\nPush integers on stack and dump...

  • C++ Create a class that implements a sorted, doubly-linked list: Start with a copy of the...

    C++ Create a class that implements a sorted, doubly-linked list: Start with a copy of the sortedList class. Call your new class doublyLinkedList. Convert the baseline code into a doubly linkedlist, and thoroughly test all existing operations (make sure to check all edge conditions), and then implement the new operations below. The class should have the following additional class methods: • A reverse method: this method will reverse the order of the doubly linked list. This method takes no parameters,...

  • C++ problem to use dynamic memory allocation (of arrays) and pointer manipulation in order to implement...

    C++ problem to use dynamic memory allocation (of arrays) and pointer manipulation in order to implement the Inner and Outer classes (Circular Buffer of circular buffers using Queues). No need of any classes from the Standard Template Library (STL), not even vector. Add the member functions of those classes by following the codes of InnerCB.h and CBofCB.h below: // file: InnerCB.h // Header file for Inner Circular Buffer. // See project description for details. // #ifndef _INNERCB_H_ #define _INNERCB_H_ class...

  • 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...

  • Derive a class called Stack from the linked list described in Assignment 2 (list of Dates)....

    Derive a class called Stack from the linked list described in Assignment 2 (list of Dates). This means the Stack class will inherit all the properties (data and functions) of the linked list. But, since a stack only allows pushing and popping at the front of the list only, you will need to prevent the operations at the back. To do this, derive the Stack class in such a way that the base class (LinkedList) functions become private in the...

  • How do i write a destructor for this class? #ifndef NODE_H #define NODE_H #include <iostream> using...

    How do i write a destructor for this class? #ifndef NODE_H #define NODE_H #include <iostream> using namespace std; class Node{ public: // Constructor // Preconditions: None // Postconditions: None Node(); // Destructor // Preconditions: None // Postconditions: Frees dynamically allocated memory ~Node(); // Overloaded Constructor // Preconditions: None // Postconditions: Initializes member variable with given argument Node(bool value); // ReplaceValue - Replaces m_value with opposite (if true then false or if false then true) // Preconditions: None // Postconditions: m_value...

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