# include // #include // #include // #include // #include // #include // #include using namespace std; #define NN 1000 const int MAXHASH = 100000; class person { public: int ID; char name [25]; int age; char* address; int phone; person* next; person* prev; }; int myhash_function(char s[]){ int sum=0,i=0,v; // cout<<"\n hash("<0){ i++; v = s[i] * i*i; sum += v; // cout << " "<< i <<" "<< s[i-1]<<" "<next=NULL; f->prev=NULL; strcpy(f->name, somename); f->ID = 0; f->age=0; *head = f; return f; } person* e = *head; while (strcmp (e->name, somename) !=0){ //look for the word or for the end of the list if (e->next==NULL){ //create the new entry here, must return cout<<" GiveMeElement: name="<next=NULL; e->next=f; f->prev=e; strcpy(f->name, somename); f->ID = 0; f->age=0; return f; } e=e->next; } cout<<"\n GiveMeElement: name="<ID<<" name="<name<<" phone="<phone; cout<<" age="<age<<" address="<address<next; } } int main(){ person x; x.ID=1; x.age=35; strcpy(x.name, "Virgil"); //VERY WRONG, not allocated // strcpy(x.address,"Huntington Ave"); char add [] = "Huntington Ave"; x.address = add; x.phone = 123456789; cout<<"\n\nUSING STRUCTURES\n display first: "<age=22; strcpy(y->name, "John Smith"); char addy []= "Washington DC"; y->address = addy; y->phone = 1110002222; display_person_2 (y, "\ndisplay y with a pointer function:\n"); //return 0; ///////////////////// LINKED LISTS //////////////// cout<<"\n\n\n\n LINKED LISTS\n"; person *z = new person; z->ID=3; z->age=25; strcpy(z->name, "Alice Dee"); char addz []= "New York"; z->address = addz; z->phone = 999000333; display_person_2 (z, "\ndisplayed z with a pointer function:\n"); y->next=z; //manual z->prev=y; x.next=y; y->prev=&x; //return 0 ; person* listhead1 = &x; person* t = GiveMeElement ("Lisa Smith", &listhead1); t->age =39; t->ID=5; t->address = "San Francisco, CA"; //exercise: what happens here? t = GiveMeElement ("Terry Boyle", &listhead1); t->age =24; t->ID=7; t->address = "Miami, FL"; ListAllPeople(listhead1); cout<age = 80; t->ID=1; t->address = "London, UK"; t = GiveMeElement ("Tony Blair", &listhead1); t->age = 61; t->ID=2; t->address = "London, UK"; t = GiveMeElement ("Winston Churchill", &listhead2); t->age = 132; t->ID=3; t->address = "Woodstock UK"; ListAllPeople(listhead1); cout<