Question

In: Computer Science

ADT SORTED LIST Fill in the missing code in the following code segment.          void SortedType::PutItem(ItemType...

ADT SORTED LIST

Fill in the missing code in the following code segment.

        

void SortedType::PutItem(ItemType newItem)

{

            NodePtr newNode;                 // pointer to node being inserted

            NodePtr predLoc;                    // trailing pointer

            NodePtr location;                    // traveling pointer

            boolean moreToSearch;

            location = listData;

            predLoc = NULL;

            moreToSearch = (location != NULL);

            length++;

           

// Find insertion point

           

// Prepare node for insertion

           

// Insert node into list

}

Solutions

Expert Solution

Solution:

void SortedType::PutItem(ItemType newItem)

{

            NodePtr newNode;                 // pointer to node being inserted

            NodePtr predLoc;                    // trailing pointer

            NodePtr location;                    // traveling pointer

            boolean moreToSearch;

            location = listData;

            predLoc = NULL;

            moreToSearch = (location != NULL);

             

// Find insertion point.
  while (moreToSearch)
  {
    switch(newItem.ComparedTo(location->info))
    {
      case GREATER: predLoc = location;
                   location = location->next;
                    moreToSearch = (location != NULL);
                    break;
      case LESS:    moreToSearch = false;
                    break;
    }
    
  }

  

// Prepare node for insertion

  newNode = new NodePtr;
  newNode->info = newItem;
// Insert node into list.

  if (predLoc == NULL)         // Insert as first
  {
    newNode->next = listData;
    listData = newNode;
  }
  else
  {
    newNode->next = location;
    predLoc->next = newNode;
  }

   length++;

}

Please give thumbsup, if you like it. Thanks.


Related Solutions

List.h template class List { // List class ADT              public:    virtual void...
List.h template class List { // List class ADT              public:    virtual void clear() = 0; // Inserts an item into the list at position index    virtual bool insert(const ListItemType& newItem) = 0;    // Append "it" at the end of the list    // The client must ensure that the list's capacity is not exceeded    virtual bool append(const ListItemType& newItem) = 0;    // Deletes an item from the list at a given position...
In C++ write an implementation of the ADT sorted list that uses a resizable array (vector...
In C++ write an implementation of the ADT sorted list that uses a resizable array (vector class of C++ STL) to represent the list items.
Question: Write an implementation of the ADT sorted list that uses a resizable array (vector class...
Question: Write an implementation of the ADT sorted list that uses a resizable array (vector class of C++ STL) to represent the list items. Anytime the list becomes full, double the size of the array.
Fill in the blanks of the following segment of code, so that the output would be 1 3 4.
Fill in the blanks of the following segment of code, so that the output would be 1 3 4.int count = 0;do{++ count;if (count == 2)Blank;cout << count << " ";} while (count <= Blank);cout << endl;
Java The List ADT has an interface and a linked list implementation whose source code is...
Java The List ADT has an interface and a linked list implementation whose source code is given at the bottom of this programming lab description. You are to modify the List ADT's source code by adding the method corresponding to the following UML: +hasRepeats() : boolean hasRepeats() returns true if the list has a value that occurs more than once in the list hasRepeats() returns false if no value in the list occurs more than once in the list For...
Java The List ADT has an interface and a linked list implementation whose source code is...
Java The List ADT has an interface and a linked list implementation whose source code is given at the bottom of this programming lab description. You are to modify the List ADT's source code by adding the method corresponding to the following UML: +hasRepeats() : boolean hasRepeats() returns true if the list has a value that occurs more than once in the list hasRepeats() returns false if no value in the list occurs more than once in the list For...
Fill in the missing information.
Question Fill in the missing information.a. The vendor ships the inventory and sends a(n) __________ back to the purchaser.b. After approving all documents, the purchaser sends a(n) __________ to the vendor.c. When ordering merchandise inventory, the purchaser sends a(n) __________ to the vendor.d. The purchaser receives the inventory and prepares a(n) __________. 
In Java, write the method public static void insertUnique(List l, T e), user of the ADT...
In Java, write the method public static void insertUnique(List l, T e), user of the ADT List. The method takes a list l and an element e and inserts the element at the end of the list only if it is not already there. Example 0.2. If l : A → B → C, then after calling insertUnique(l, "C"), the list does not change. Calling insertUnique(l, "D") will make l be : A → B → C → D.
Overview: implement the ADT List in Java. This program is meant to the ADT List from...
Overview: implement the ADT List in Java. This program is meant to the ADT List from the ground up In the lecture, we learned how to implement an ADT like the ArrayList you have used in Project 1. With this project, you have the chance to implement an ADT called MyList, which is a simplified replacement for the full-blown ArrayList. Requirements You will implement the MyList ADT according to the following: 1. MyList must implement the List interface. It will...
Fill in the missing blanks in each of the following equations a) _______   → 85At217 +...
Fill in the missing blanks in each of the following equations a) _______   → 85At217 + 2He4 b) 94Pu241→95Am241 + ____________ c) 11Na19→10Ne19 +________ d) 34Se75+ _____ → 33As75 e) 95Am241 →93Np237 +____ f) ______ → 92U233 + -1e0 g) 93Np237 → ______ + 2He4 h) 35Br75 → ______ + +1e0
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT