LL study

#include <iostream>
#include <string>

using namespace std;

class EmailList{
private:
struct ContactNode{
string name;
string email;
ContactNode *next;
};
ContactNode *head;
public:
EmailList(){
head = NULL;
}
void appendNode(string Name, string Email){
ContactNode *newone = new ContactNode();
newone->name = Name;
newone->email = Email;
newone->next = NULL;
if(head == NULL){
head = newone;
}
else{
ContactNode *temp = head;
while(temp->next != NULL){
temp = temp->next;
}
temp->next = newone;
}
}
void display(){
cout << endl;
if(head == NULL){
cout << “Email List is empty” << endl;
}
else{
cout << “Email List is” << endl;
}
ContactNode *temp = head;
int count = 1;
while(temp != NULL){
cout << count << “):” << endl;
cout << “Name: ” << temp->name << endl;
cout << “Email: ” << temp->email << endl;
cout << endl;
temp = temp->next;
count++;
}
}
};

int main(){
EmailList EL;
string str;
string name, email;
while(true){
cout << “Do you want to input an entry(y or n)?: “;
cin >> str;
if(str == “n” || str == “N”){
break;
}
else{
cout << “Enter Name: “;
cin >> name;
cout << “Enter email id: “;
cin >> email;
EL.appendNode(name, email);
}
}
EL.display();
return 0;
}

Be the first to comment

Leave a Reply