Linked Lists

Im having some trouble with linked lists. I am supposed to create two linked lists that both contain eight nodes. The first list has a pointer called uno and the second list has a pointer duo. In each lists it will contain a name and age. I also have to sort them as I create them. Here is my code if someone could help thatd be great

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

void getdata(string& lastName, int& bAge);
const int nil = 0;
class node_type
{
public:
string name;
int age;
node_type *next;
};
void main(){
node_type *first, *uno, *q, *newnode;
int i, bAge;
string lastName;
first = new node_type;
uno = first;
getdata(lastName, bAge);
(*first).name = lastName;
(*first).age = bAge;
(*first).next = nil;

for (i = 0; i < 7; i++)
{
getdata(lastName, bAge);
newnode = new node_type;
(*newnode).name = lastName;
(*newnode).age = bAge;
(*newnode).next = nil;
(*uno).next = newnode;
uno = newnode;
}
q = first;
cout << "The list contains" << endl;
cout << "Name Age" << endl;
while (q != nil)
{

cout << (*q).name << " " << (*q).age << endl;
q = (*q).next;
}
}
void getdata(string& lastName, int& bAge)
{
cout << "enter last name" << endl;
cin >> lastName;
cout << "enter age" << endl;
cin >> bAge;
}
Topic archived. No new replies allowed.