Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include <iostream> using namespace std; struct nodeType { int info; nodeType *l

ID: 3791778 • Letter: #

Question

#include <iostream>

using namespace std;

struct nodeType

{

int info;

nodeType *link;

};

void createList(nodeType*& first, nodeType*& last);

void printList(nodeType*& first);

int main()

{

nodeType *first, *last;

int num;

createList(first, last);

printList(first);

system("PAUSE");

return 0;

}

void createList(nodeType*& first, nodeType*& last)

{

int number;

nodeType *newNode;

first = NULL;

last = NULL;

cout<<"Enter an integer (-999 to stop): ";

cin>>number;

cout<<endl;

while (number != -999)

{

newNode = new nodeType; // create new node

newNode->info = number;

newNode->link = NULL;

if (first == NULL)

{

first = newNode;

last = newNode;

}

else

{

last->link = newNode;

last = newNode;

}

cout<<"Enter an integer (-999 to stop): ";

cin>>number;

cout<<endl;

} // end of while-loop

} // end of build list function

void printList(nodeType*& first)

{

cout<<"Inside printList...printing linked list... "<<endl;

nodeType *current;

current = new nodeType;

current = first;

while (current != NULL)

{

cout << current->info<<endl;

current = current->link;

}

}   

OVER

Page 349-350 #4 and #5 Use the "Linked List lab" you have been working on in class and add the two functions the questions are asking you to develop: divideMid and divideAt. Be sure to include comments Use meaningful identifier names (constants where appropriate) Do not work together; no two people should have identical work!?!? Turn in .cpp file AND Turn in a print-screen' of your output (press print-screen' on keyboard, then 'paste' in MS-Word)

Explanation / Answer

void divideMid(nodeType*& first)

{

           // To find the mid value firstly you need to count no of nodes

           int count=1; // count variable
           nodeType *current,*temp;
           current = new nodeType;
           temp =new nodeType;
           current=first;
           while(current!=NULL)
           {
           count++;
           current = current->link;
           } // end of loop
           int mid = count/2;
           current = first;
           int i=0;
           while( i!=mid)
           {
           current=current->link; // moving current pointer to the middile node
           } // end of loop
           //printing the nodes before the mid
           temp=first;
           while(temp!=current->link)
           {
           cout<<temp->info<<endl; // printing value
           temp=temp->link; //moving forward , stop at middile node
           }
           printig the nodes after the middile node
           temp=current->link; //pointing temp the next node of middile node
           while(temp!=NULL)   
           {
           cout<<temp->info<<endl; // printing values
           temp=temp->link; //moving forwards till the end
           }
} // end of divideMid function


void divideAt(nodeType*& first, int split_point)
{


       nodeType *current;

           current = new nodeType;
           current=first;

           //printing the values before split point
           int i=0;

           while(i!=split_point)
           {
                   cout<<current->info; // printing value
                   current = current->link;
           }//End of loop
       // printing values after split point

           while(current!=NULL)
           {
               cout<<current->info; //printing values
               current=current->link; //moving forward till the end
           } // End of loop

}//End of divideAt function