How to create node in Linked list using c++

#include<iostream>
using namespace std;

class node
{
int data;
node * next;
public:
node* create(node *head);
void display(node *);
};



node* node:: create(node *head)
{
head=new node;                                //first create memory for it 
cout<<"\nEnter data\n";
cin>>head->data;                            // data field
head->next=NULL;                // address field
return head;
}

void node:: display(node *head)
{
cout<<head->data;
}


int main()
{
node obj;
node *head;  // init. ptr vari./obj
head=obj.create(head);
obj.display(head);
}



/*********Output****************
Enter data
21
21
/*******************************

Post a Comment

0 Comments