Question
16 and 18 C++
11. Given the dynamic linked implementation of a linked list shown below, write expressions that do the following, assuming t
c. Access the component member of the next element (the one that follows the current elemen d. Access the component member of
0 0
Add a comment Improve this question Transcribed image text
Answer #1

//16 CODE HAS BEEN IMPLEMENTED, DO CHECK ONCE BY YOUR OWN

/*
   struct NodeType{
       ComponentType component;
       NodePtr link;
   }
  
   NodePtr listPtr;
   NodePtr currPtr;
   NodePtr newNodePtr;
*/


void sortList(){
   if(listPtr == null){
       return;
   }
  
   NodePtr newListPtr = null;
   NodePtr newCurrPtr = null;
   NodePtr curr = listPtr;
   Nodeptr temp,prev;
  
   while(curr!=null){
       prev = null;
       temp = curr;
       while(curr->link){
           if( (temp->component) > (curr->link->component) ){
               temp = curr->link;
               prev=curr;
               curr=curr->link;
           }
       }
      
       //CREATE NODE --- THIS FOR CREATING NEW NODE
       /*
       struct NodePtr newNodePtr = (struct NodePtr) malloc(sizeof(struct NodeType));
       newNodePtr->component = temp->component;
       */
      
       if(newListPtr == null){
           newListPtr = temp;
           newCurrPtr = temp;
          
       }else{
           newCurrPtr->link=temp;
           newCurrPtr=temp;
       }
      
       //MOVE NODE
       if(prev == null){
           listPtr = listPtr->link;
           temp->link = null;
       }else{
           prev->link = temp->link;
           temp->link = null;
       }
      
       //REMOVE NODE --- THIS IS FOR DELETING NODE
       /*
       if(prev==null){
           listPtr = listPtr->link;
           free(temp);
       }else{
           prev->link = temp->link;
           free(temp);
       }*/
      
       curr = listPtr;
   }
  
   listPtr = newListPtr;
   currPtr = newListPtr;
}

Add a comment
Know the answer?
Add Answer to:
16 and 18 C++ 11. Given the dynamic linked implementation of a linked list shown below,...
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
  • 2) (10 pts) Write a function that takes in a pointer to a linked list of...

    2) (10 pts) Write a function that takes in a pointer to a linked list of nodes storing integers and a variable named value, and returns the number of nodes in the list storing that value. For example, if a list pointed to by listPtr stores 2, 6, 2, 3, 4, 2, 6, and 6 and value = 6, your function should return 3, since 6 appears in the list 3 times. Please use the struct and function prototype provided...

  • linked list operation /*************************************************************************************** This function creates a new node with the information give as a...

    linked list operation /*************************************************************************************** This function creates a new node with the information give as a parameter and looks for the right place to insert it in order to keep the list organized ****************************************************************************************/ void insertNode(string first_name, string last_name, string phoneNumber) { ContactNode *newNode; ContactNode *nodePtr; ContactNode *previousNode = nullptr; newNode = new ContactNode; /***** assign new contact info to the new node here *****/ if (!head) // head points to nullptr meaning list is empty { head = newNode;...

  • Programming in C: I am trying to modify this linked list to be doubly linked list....

    Programming in C: I am trying to modify this linked list to be doubly linked list. I’m also trying to add a print in reverse function. I’m really struggling with how to change the insert function to doubly link the nodes without effecting the alphabetical sorting mechanism. Example of desired output: Enter your choice: 1 to insert an element into the list. 2 to delete an element from the list. 3 to end. ? 1 Enter a character: a The...

  • () Given the following structure definition and typedef for a linked list of strings: typedef struct...

    () Given the following structure definition and typedef for a linked list of strings: typedef struct node st node; struct node st { char *word; /* a valid string pointer or NULL */ node *next; /* next node in the list or NULL */ }; Write a C function, free list(), that takes as an argument one of these lists, possibly NULL, and frees all the strings as well as the list itself. Write robust code. void free list(node *list){

  • Given the node structure and the head pointer (headptr) of a linked list write a code...

    Given the node structure and the head pointer (headptr) of a linked list write a code to move the last element to the head of the list. struct node {    int value;    struct node *next; };

  • PART 1 Implement a C++ class for an array representation of a list. The methods must...

    PART 1 Implement a C++ class for an array representation of a list. The methods must be based upon the pseudocode provided on the CS210 Algorithms below. Use the following declarations as a starting point for your implementation. const int MAX_LENGTH = some application-specific max value; typedef <some data type> DataType; class List { public:     methods go here private:     int p;     int length;     DataType a [MAX_LENGTH]; }; Note: Any other variable or constant declarations required would...

  • ***CODE MUST BE IN C++*** Using the linked list in "basic linked list" which has a...

    ***CODE MUST BE IN C++*** Using the linked list in "basic linked list" which has a STRUCTURE for each node, write FUNCTION which starts at the head and outputs the value for each node until the last node is reached. Note: your function should work with the structure that is in this program. Please do not use the example which is for a class, but this example canbe helkpful.  Also note that the function must work no matter how many nodes...

  • In C++, for the provided template linked list class create a derived class of it which...

    In C++, for the provided template linked list class create a derived class of it which adds the functionality to it to find the high and low value of any given data stored in the list. The derived class must be a template. LinkedList.h #pragma once #include <iostream> using namespace std; template <class T> class ListNode {    public:        T data;        ListNode<T>* next;        ListNode(T data)        {            this->data = data;...

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

  • C++ help 0.1. An ordered linked list of characters has been constructed using the array-based implementation....

    C++ help 0.1. An ordered linked list of characters has been constructed using the array-based implementation. The following diagram shows the current contents of the array that stores the elements in an alphabetical order in the linked list and an available pool of nodes. Node data next о е м и р first = 5 - п free = 6 о у 1) Write in order the contents (data) of the nodes of the linked list pointed to by first....

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