Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream.h>
- #include<conio.h>
- #define null 0
- struct node
- {
- int data;
- struct node *ptr;
- };
- typedef struct node node;
- class linklist
- {
- node *head;
- public:void create(void);
- void display(void);
- };
- void linklist::create(void)
- {
- char choice;
- do
- {
- node *newnode,*temp;
- newnode=new node;
- cout<<"enter the data : \n";
- cin>>new node->data;
- newnode->ptr=null;
- if(head==null)
- {
- head=temp=newnode;
- }
- else
- {
- temp->ptr=newnode;
- temp=newnode;
- }
- cout<<"do you want to continue(y/n) :";
- cin>>choice;
- }while(choice=='y');
- }
- void linklist::display(void)
- {
- node *temp;
- temp=head;
- while(temp!=null)
- {
- cout<<temp->data;
- cout<<"->";
- temp=temp->ptr;
- }
- cout<<"null";
- }
- int main()
- {
- linklist li;
- clrscr();
- cout<<"\n creation";
- li.create();
- cout<<"\n display";
- li.display();
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement