
12-13-2009
|
 |
مدیر کل سایت  کوروش نعلینی
|
|
تاریخ عضویت: Jun 2007
محل سکونت: کرمانشاه
نوشته ها: 12,700
سپاسها: : 1,382
7,486 سپاس در 1,899 نوشته ایشان در یکماه اخیر
|
|
لیست پیوندی - جعفرنژاد قمی
این کلاس لیست پیوندی هست که من خودم ازش استفاده میکنم مال جعفر نژاد قمی هست
کد:
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class node {
friend class linkList;
char name[20];
int stno;
float ave;
node *next;
};
//************************************
class linkList{
public:
linkList();
~linkList();
void addNode();
void delNode(int &);
void display();
private:
node *first;
node *last;
};
//************************************
linkList::linkList()
{
first=last=NULL;
}
//*********************************
linkList::~linkList()
{
node *curPtr=first;
node *temp;
while(curPtr){
temp=curPtr;
curPtr=curPtr->next;
delete temp;
}
}
//************************************************88
void linkList::delNode(int &no)
{
node *curPtr=first,*nextPtr=first;
while(nextPtr){
if(no==nextPtr->stno)
if(nextPtr==first){
first=first->next;
delete nextPtr;
break;
}
else {
if(nextPtr==last)
last=curPtr;
curPtr->next=nextPtr->next;
delete nextPtr;
break;
}
else{
curPtr=nextPtr;
nextPtr=nextPtr->next;
}
}
}
//*******************************************************8
void linkList::addNode()
{
node *newPtr=new node;
if(!newPtr){cout<<"not allocation;",getch();}
newPtr->next=NULL;
clrscr();
cout<<"Name "<<"stno "<<" aver\n";
gotoxy(1,2);
cin>>newPtr->name;
gotoxy(20,2);
cin>>newPtr->stno;
gotoxy(30,2);
cin>>newPtr->ave;
if(first==NULL)
first=last=newPtr;
else{
last->next=newPtr;
last=newPtr;
}
}
void linkList::display()
{
int r=2;
clrscr();
cout<<"name "<<"sn "<<" avra\n";
node *curPtr=first;
while(curPtr){
gotoxy(1,r);
cout<<curPtr->name<<" ";
gotoxy(20,r);
cout<<curPtr->stno<<" ";
gotoxy(30,r);
cout<<curPtr->ave<<" ";
curPtr=curPtr->next;
r++;
}
}
//888888888888888888888888888888888888888888888888888888
int menu();
int main()
{
int no;
linkList testList;
for(;;){
clrscr();
switch(menu()){
case 1:testList.addNode();break;
case 2:
cout<<"enter stno to delet";
cin>>no;
testList.delNode(no);break;
case 3: testList.display();getch();break;
case 4: exit(1);
}
}
}
int menu()
{
int choice;
cout<<"1 enter a studn\n"
<<"2 delet \n"
<<"3 disp \n"
<<"4 end prog\n";
cout<<"\n enter your select (1-4)";
cin>>choice;
return choice;
}
__________________
مرا سر نهان گر شود زير سنگ -- از آن به كه نامم بر آيد به ننگ
به نام نكو گر بميــرم رواست -- مرا نام بايد كه تن مرگ راست
ویرایش توسط دانه کولانه : 12-13-2009 در ساعت 09:07 PM
|
جای تبلیغات شما اینجا خالیست با ما تماس بگیرید
|
|