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

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) __________. 
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 information from the statements below sothat the entire code block fulfills...
Fill in the missing information from the statements below so that the entire code block fulfills the program requirements from the last step and prints the desired output. You only need to supply the parts of each statement that are not shown below.Fill in the Blanks — Fill in the blanksnumber1 = int(_________ ("Enter the first number: "))number2 = __________ (input("Enter the second number: "))the_sum = _________print(  )_____________
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
In the following chart, fill in the missing cells for each of the following independent scenarios....
In the following chart, fill in the missing cells for each of the following independent scenarios. Do not enter dollar signs or commas in the input boxes. Round all answers to the nearest whole number, except for the CM Ratio. Round the CM Ratio to 2 decimal places. Scenario Revenue Variable Costs Fixed Costs Total Costs Operating Income CM Ratio Contribution Margin 1 $610 $Answer $490 $630 $-20 Answer% $Answer 2 $1,800 $Answer $Answer $1,600 $Answer 55.00% $Answer 3 $Answer...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT