C++ struct Create a linked list with structure

Description

C++ struct Create a linked list with structure

#include <iostream>
#include <string>
using namespace std;
struct Employee//from  w  ww.ja va  2 s.  c  o m
{
   string name;
   string phoneNo;
   Employee *nextaddr;
};
int main()
{
   Employee t1 = {"A","(555) 888-8392"};
   Employee t2 = {"D","(555) 888-8104"};
   Employee t3 = {"L","(555) 888-8581"};
   Employee *first;     // create a pointer to a structure
   first = &t1;         // store t1's address in first
   t1.nextaddr = &t2;   // store t2's address in t1.nextaddr
   t2.nextaddr = &t3;   // store t3's address in t2.nextaddr
   t3.nextaddr = NULL;  // store a NULL address in t3.nextaddr
   cout << endl << first->name << endl << t1.nextaddr->name << endl << t2.nextaddr->name << endl;
   return 0;
}



PreviousNext

Related