هلا أم السوُس ... علي راي صاحبنا
هلا أم السوُس ... علي راي صاحبنا
#include"list.h"
node::node()
{
empName =" " ;
empId =0;
hiringDate= 0;
salary = 0;
depID = 0;
depName = " ";
next = NULL;
}
node::node(string name ,int ID , int hiDate , int salary , int dID , string dName , node *ptr)
{
empName = name ;
empId = ID;
hiringDate = hiDate;
salary = salary;
depID = dID ;
depName = dName;
next = ptr ;
}
int node::get_depID()
{
return depID;
}
string node::get_depName()
{
return depName;
}
int node::get_empId()
{
return empId;
}
string node::get_empName()
{
return empName;
}
int node::get_hiDate()
{
return hiringDate;
}
node * node::get_next()
{
return next;
}
int node::get_salary()
{
return salary ;
}
void node::set_depID(int y )
{
depID = y ;
}
void node::set_depName(string x )
{
depName = x ;
}
void node::set_empId(int x)
{
empId = x ;
}
void node::set_empName(string x )
{
empName = x ;
}
void node::set_hiDate(int x )
{
hiringDate= x ;
}
void node::set_next(node *ptr)
{
next = ptr ;
}
void node::set_salary(int x)
{
salary = x;
}
void list:perator =(list & right)
{
while(!empty())// deleteAtPo(n);
if(right.mySize ==0 )
return ;
node *me = first = new node(right.first->get_empName(),right.first->get_empId(),right.first->get_hiDate(),right.first->get_salary(),right.first->get_depID(),right.first->get_depName(),right.first->get_next());
node *copy= right.first ;
while(copy->get_next())
{
copy=copy->get_next();
me->set_next(new node(copy->get_empName(),copy->get_empId(),copy->get_hiDate(),copy->get_salary(),copy->get_empId(),copy->get_depName(),copy->get_next()));
me = me->get_next();
}
mySize = right.mySize;
}
bool list::empty()
{
if (mySize ==0)
return true;
else
return false ;
}
void list::insertAtPo(int pos)
{
if (pos<1||pos>mySize)
{
cout<<" Invalid Position !!!!!!"<<endl;
return;
}
if (pos==1)
{
node * newFirst = new node ;
newFirst->set_next(first);
cout<<"Enter employee name "<<endl;
string tempName;
cin >>tempName;
cout<<endl;
newFirst->set_empName(tempName);
cout<<"Enter employee ID "<<endl;
int tempID;
cin>>tempID;
cout<<endl;
newFirst->set_empId(tempID);
cout<<"Enter the hiring Date"<<endl;
int tempHi;
cin>>tempHi;
newFirst->set_hiDate(tempHi);
cout<<"Enter the employee salary "<<endl;
int tempSa;
cin>>tempSa;
cout<<endl;
newFirst->set_salary(tempSa);
cout<<"Enter the department id "<<endl;
int tempDid;
cin>>tempDid;
cout<<endl;
newFirst->set_depID(tempDid);
cout<<"Enter the department name "<<endl;
string tempDname;
cin>>tempDname;
cout<<endl;
newFirst->set_depName(tempDname);
if(newFirst==NULL) return;
mySize++;
first= newFirst ;
return;
}
if (pos== mySize+1)
{
node *newEnd = new node ;
cout<<"Enter employee name "<<endl;
string tempName;
cin >>tempName;
cout<<endl;
newEnd->set_empName(tempName);
cout<<"Enter employee ID "<<endl;
int tempID;
cin>>tempID;
cout<<endl;
newEnd->set_empId(tempID);
cout<<"Enter the hiring Date"<<endl;
int tempHi;
cin>>tempHi;
newEnd->set_hiDate(tempHi);
cout<<"Enter the employee salary "<<endl;
int tempSa;
cin>>tempSa;
cout<<endl;
newEnd->set_salary(tempSa);
cout<<"Enter the department id "<<endl;
int tempDid;
cin>>tempDid;
cout<<endl;
newEnd->set_depID(tempDid);
cout<<"Enter the department name "<<endl;
string tempDname;
cin>>tempDname;
cout<<endl;
newEnd->set_depName(tempDname);
if(newEnd==NULL) return;
mySize++;
if(first==NULL) first = newEnd;
else
{
node *temp =first;
while(temp->get_next()!=NULL) temp = temp->get_next();
temp->set_next(newEnd);
}
return;
}
node * currptr = first ;
for (int i =0; i<pos-1;i++)
currptr = currptr->get_next();
node *newNode = new node ;
newNode->set_next(currptr->get_next());
cout<<"Enter employee name "<<endl;
string tempName;
cin >>tempName;
cout<<endl;
newNode->set_empName(tempName);
cout<<"Enter employee ID "<<endl;
int tempID;
cin>>tempID;
cout<<endl;
newNode->set_empId(tempID);
cout<<"Enter the hiring Date"<<endl;
int tempHi;
cin>>tempHi;
newNode->set_hiDate(tempHi);
cout<<"Enter the employee salary "<<endl;
int tempSa;
cin>>tempSa;
cout<<endl;
newNode->set_salary(tempSa);
cout<<"Enter the department id "<<endl;
int tempDid;
cin>>tempDid;
cout<<endl;
newNode->set_depID(tempDid);
cout<<"Enter the department name "<<endl;
string tempDname;
cin>>tempDname;
cout<<endl;
newNode->set_depName(tempDname);
currptr->set_next(newNode);
mySize++;
}
void list::deleteAtPo(int n )
{
if(mySize==0)
return;
if(n>mySize ||n<1)
{
cout<<"Invalide position !!!!!"<<endl;
return;
}
if(mySize ==1)
{
delete first ;
first = NULL;
mySize = 0 ;
return ;
}
if(n=1)
{
node *todelete = first ;
first = first->get_next();
delete todelete ;
return ;
}
node *currptr= getFirst();
for (int i =0; i<n-1 ; i++)
currptr = currptr->get_next();
node *todelete = currptr->get_next();
currptr->set_next(todelete->get_next());
delete todelete ;
mySize -- ;
}
list::~list()
{
node *temp = first;
do
{
temp= temp->get_next();
delete first ;
first = temp ;
}while(temp);
}
void list::search(list list1)
{
cout <<"Enter the empolyee ID to search for "<<endl;
int tempID ;
cin >>tempID;
cout<<endl;
node *temptr = list1.getFirst();
for(int i=0 ;i<mySize; i++)
{
if(temptr->get_empId()==tempID)
{
cout<<"the empolyee data was found !!"<<endl;
cout<<"name:"<<temptr->get_empName()<<" "<<"ID : "<<temptr->get_empId()<<endl;
cout<<"department"<<temptr->get_depID()<<" "<<"Dep ID "<<temptr->get_depID()<<endl;
}
temptr= temptr->get_next();
}
}
void list::sort()
{
}
void list:rintAll()
{
node *temp = first ;
cout<<"Name "<<" "<<"ID "<<" "<<endl;
while(temp!=NULL)
{
cout<<temp->get_empName()<<" "<<temp->get_empId()<<" "<<temp->get_hiDate()<<" "<<temp->get_salary()<<" "<<temp->get_depName()<<" "<<temp->get_depID()<<endl;
temp=temp->get_next();
}
cout<<endl;
}
void list::changeDep(list list1)
{
}
list::list(list & orig)
{
if (orig.mySize==0)
{
first = NULL;
return;
}
node *me = first = new node(orig.first->get_empName(),orig.first->get_empId(),orig.first->get_hiDate(),orig.first->get_salary(),orig.first->get_depID(),orig.first->get_depName(),orig.first->get_next());
node *copy= orig.first ;
while(copy->get_next())
{
copy=copy->get_next();
me->set_next(new node(copy->get_empName(),copy->get_empId(),copy->get_hiDate(),copy->get_salary(),copy->get_empId(),copy->get_depName(),copy->get_next()));
me = me->get_next();
}
mySize = orig.mySize;
}
node *list::getFirst()
{
return first;
}
list::list()
{
first = NULL;
mySize = 0 ;
}
شو رايك هاد جهاد ولا لأ؟؟
أم بيسان
... مين جهاد ... عضو عنا بالمنتدى ...
قال جهاد ... هذا اسمه انتحار![]()
شكرا طوق الياسمين
الذين يشاهدون الموضوع الآن: 11 (0 من الأعضاء و 11 زائر)
مواقع النشر (المفضلة)