#include<iostream>
using namespace std;
struct node
{
int data;
node*link;
};
class list
{
node*start;
node*current,*temp;
public:
list()
{
start= 0;
}
void add(int d)
{
if(start==0)
{
start=new node;
start->data=d;
start->link=0;
}
else
{
current=start;
while(current->link!=0)
current=current->link;
temp=new node;
temp->data=d;
temp->link=0;
current->link=temp;
}
}
void show()
{
node*temp;
temp=start;
cout<<"the_list_is_as_follows"<<endl;
while(temp->link!=NULL)
{
cout<<temp->data<<"
->";
temp=temp->link;
}
}
};
int main()
{list i;
i.add(25);
i.add(30);
i.add(35);
i.add(40);
i.add(20);
i.add(56);
i.add(34);
i.add(22);
i.show();
cout<<endl;
return 0;
}
No comments:
Post a Comment