Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- typedef struct Person{
- double age;
- double height;
- Person *next;
- } PERSON;
- void display_list (PERSON *start);
- void create_person(PERSON *p);
- void add_to_list(PERSON *start);
- int main()
- {
- PERSON *p1 =new PERSON;
- PERSON *p2 =new PERSON;
- PERSON *p3 = new PERSON;
- p1 -> age=22;
- p1 -> height =180;
- p2 -> age =25;
- p2 -> height =170;
- p3 -> age = 33;
- p3 -> height = 168;
- p1->next = p2;
- p2-> next =p3;
- p3-> next = NULL;
- display_list(p1);
- for(int i=0; i<=100; i++) add_to_list(p1);
- cout<< endl;
- display_list(p1);
- return 0;
- }
- void add_to_list(PERSON *start){
- PERSON *p0 =start;
- while(1){
- if(p0->next== NULL) break;
- p0=p0->next;
- }
- PERSON *newperson =new PERSON;
- create_person(newperson);
- p0->next =newperson;
- newperson->next= NULL;
- }
- void create_person(PERSON *p){
- p->age = rand()%21+80;
- p->height=rand()%50+150;
- }
- void display_list (PERSON *start){
- PERSON *p0=start;
- while(1){
- cout<< " age " << p0-> age << "height " << p0->height<< endl;
- if (p0->next == NULL) break;
- p0=p0->next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement