#include <iostream>
#include<string>
using namespace std;
long int NN;
int x=0;
class node *temp, *temp2 ,*start;
class linked_list
{
public:
class node
{
public:
char name[20];
long int national_number;
char residance[25];
node *nxt;
};
//--------------------------------->
linked_list()
{
node *start;
start=new node;
cout<<"NAME : Hussam Adel Abu Lubbad"<<endl;
cout<<"nathiona number : 2007217345"<<endl;
cout<<"residance : jarash"<<endl;
}
//--------------------------------->
void insert_at_end()
{
node *temp, *temp2,*start;
temp = new node;
cout << "Please enter the name of the person: ";
cin >> temp->name;
cout << "Please enter the national number of the person : ";
cin >> temp->national_number;
cout << "Please enter the residance of the person : ";
cin >> temp->residance;
temp->nxt = NULL;
if (start == NULL)
start = temp;
else
{
temp2 = start;
while (temp2->nxt != NULL)
{
temp2 = temp2->nxt;
}
temp2->nxt = temp;
temp2->nxt=NULL;
}
}
//--------------------------------->
void print_all_list()
{
node *temp ,*start;
temp = start;
if (temp == NULL)
cout << "The list is empty" << endl;
else
{
while (temp != NULL)
{
cout << "Name : " << temp->name << " ";
cout << "national number : " << temp->national_number << " ";
cout << "residance : " << temp->residance;
temp = temp->nxt;
}
cout << "E.O.L" << endl;
}
}
//--------------------------------->
void print_irbid()
{
node *temp,*start;
temp = start;
if (temp == NULL)
cout << "The list is empty!" << endl;
else
{
while (temp != NULL)
{
if(temp->residance == "irbid")
{
cout << "Name : " << temp->name << " ";
cout << "national number : " << temp->national_number << " ";
cout << "residance : " << temp->residance;
temp=temp->nxt;
}
else
temp = temp->nxt;
}
cout << "E.O.L" << endl;
}
}
//--------------------------------->
void delete_the_first()
{
node *temp ,*start;
temp = start;
start = start->nxt;
delete temp;
}
//--------------------------------->
void delete_the_last_person()
{
node *temp, *temp2,*start;
if (start == NULL)
cout<< "it is empty"<<endl;
else
{
temp = start;
if (temp->nxt == NULL)
{
delete temp;
start = NULL;
}
else
{
while (temp->nxt != NULL)
{
temp2 = temp;
temp = temp->nxt;
}
delete temp;
temp2->nxt = NULL;
}
}
}
//--------------------------------->
void delete_this(long int NN)
{
node *temp, *temp2,*start;
cout<<"please enter the national # of the person to delete it form the list"<<endl;
cin>>NN;
if (start == NULL)
cout<< "it is empty"<<endl;
else
temp = start;
while (temp->nxt != NULL)
{
while(temp->national_number != NN)
{
temp2 = temp;
temp = temp->nxt;
}
temp2->nxt =temp->nxt;
delete temp;
}
cout<<"there is no national number match the one you have entered"<<endl;
}
//--------------------------------->
void cont_ali()
{
int cont=0;
node *temp ,*start;
temp = start;
if (temp == NULL)
cout << "The list is empty!" << endl;
else
{
while (temp != NULL)
{
if(temp->name == "ali")
{
cont++;
cout << "Name : " << temp->name << " ";
cout << "national number : " << temp->national_number << " ";
cout << "residance : " << temp->residance;
temp=temp->nxt;
}
else
temp = temp->nxt;
}
cout << "E.O.L" << endl;
cout<<"the # of persons with name Ali in this list is --->"<<cont<<endl;
}
}
//--------------------------------->
void insert_at_the_first()
{
node *temp, *temp2 ,*start ;
temp = new node;
cout << "Please enter the name of the person: ";
cin >> temp->name;
cout << "Please enter the national number of the person : ";
cin >> temp->national_number;
cout << "Please enter the residance of the person : ";
cin >> temp->residance;
temp->nxt = NULL;
if (start == NULL)
start = temp;
else
{
temp2 = start;
start=temp;
}
}
//--------------------------------->
};
void main()
{
linked_list::node *start;
start = NULL;
linked_list in;
do
{
void print_all_list();
cout << endl;
cout << "Please select an option : "<<endl;
cout << "0. Exit the program."<<endl;
cout << "1. Add a person to end of the list."<<endl;
cout << "2. print all list."<<endl;
cout << "3. print the persons who leave in irbid."<<endl;
cout << "4. delete the first person in the list."<<endl;
cout << "5. delete the last person on the list."<<endl;
cout << "6. cont how many persons in the list there name is ali ."<<endl;
cout << "7. delete by the national number."<<endl;
cout << "8. insert at the first of the list. "<<endl;
cin >> x;
switch (x)
{
case 1 : in.insert_at_end(); break;
case 2 : in.print_all_list(); break;
case 3 : in.print_irbid(); break;
case 4 : in.delete_the_first(); break;
case 5 : in.delete_the_last_person();break;
case 6 : in.cont_ali(); break;
case 7 : in.delete_this(NN); break;
case 8 : in.insert_at_the_first();
}
}
while (x != 0);
}
hussamo -3 Newbie Poster
Lerner 582 Nearly a Posting Maven
Salem commented: Well put +17
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
hussamo -3 Newbie Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.