Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- struct node
- {
- int data;
- struct node *next;
- };
- struct node *head=NULL,*temp;
- void display()
- {
- cout<<endl;
- temp=head;
- while(temp!=NULL)
- {
- cout<<temp->data<<endl;
- temp=temp->next;
- if(temp==head)
- {
- break;
- }
- }
- }
- int main()
- {
- struct node *n1,*n2,*n3;
- n1=(struct node*) malloc (sizeof(struct node));
- n2=(struct node*) malloc (sizeof(struct node));
- n3=(struct node*) malloc (sizeof(struct node));
- cin>>n1->data>>n2->data>>n3->data;
- head=n1;
- n1->next=n2;
- n2->next=n3;
- n3->next=n1;
- display();
- return 0;
- }
Add Comment
Please, Sign In to add comment