Create two linked lists each having eight nodesthe first lis

Create two linked lists each having eight nodes…..the first list has a pointer called UNO to the first node and the second list has a pointer called DUO to the first node. The lists are to be sorted as you create them. The data in the lists will consist of a last name and age (e.g. Pinto 39)..now don’t laugh!!! Print out each sorted list after you create them…..then delete all nodes from the FIRST list whose age is under 40…and delete all nodes from the second list whose age is over 50. Print out both Finally..merge the REMAINING nodes from both lists into one list..headed by first. Print out the final list.

Solution

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

void getdata(string& lastname,Int&age);
const int nil = 0;

class node_type
{
public:
string lname;
Int lage;
node_type *next;
};

void main()
{
   node_type *uno, *duo, *p, *r, *newnode, *newnode2;
   int i;
   int age_value;
   string lastname;

   uno = new node_type;
   p = uno;
   getdata(lastname,age_value);
   (*uno).lname = lastname;
   (*uno).lage = age_value;
   (*uno).next = nil;

   duo = new node_type;
   r = duo;
   (*duo).lname = lastname;
   (*duo).lage = age_value;
   (*duo).next = nil;
    for (i=0; i<=8;++i)
   {
   getdata(lastname,age_value);
       newnode = new node_type;
       newnode2 = new node_type;
       (*newnode).lname = lastname;
       (*newnode).lage = age_value;
       (*newnode).next = nil;
       (*newnode2).name = lastname;
       (*newnode2).lage = age_value;
       (*newnode2).next = nil;
       (*p).next = newnode;
       (*r).next = newnode2;
       p = newnode;
       r = newnode2;
   }
}

void getdata(string& lastname,float& age_value)
{
   cout << \"Enter last name \ \" ;
   cin >> lastname;
   cout << lastname << \"\ \";
   cout << \"Enter age \ \" ;
   cin >> age_value;
   cout << age_value << \"\ \";
}

int sort[5];
int temp,i,j;

clrscr();

printf(\"Enter list of array: \");

for(i=0;i<5;i++){
scanf(\"%d\",&sort[i]);
}
Now for sorting of the linked lists
/* Sorting for loop */

for(i=0;i<3;i++){
for(j=0;j<3;j++){

if(sort[i] > sort[j]){

temp=sort[j];
sort[j]=sort[i];
sort[i]=temp;

}
}

/* end of sorting */

for(i=0;i<5;i++){
printf(\"%d\",&sort[i]);
}

For merging the linked
       {
for(temp1 = uno; temp1->next!=NULL; temp1 = temp1->next);
           if ((*temp1).next = NULL)
           {
               (*temp1).next = duo;
           }
       }

That should leave temp1 pointing to the last node. Then assign
temp1->next = duo;

Create two linked lists each having eight nodes…..the first list has a pointer called UNO to the first node and the second list has a pointer called DUO to the
Create two linked lists each having eight nodes…..the first list has a pointer called UNO to the first node and the second list has a pointer called DUO to the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site