You are on page 1of 3

#include<iostream>

#include<stdio.h>

using namespace std;

struct link

int roll;

link* next;

};

link *prenode,*newnode,*start,*newlink,*endnode;

void create()

int n,i,value;

cout<<"Enter number of nodes to create:";

cin>>n;

newnode= new link;

start=prenode=newnode;

cout<<"Enter roll no. of student";

cin>>value;

newnode->roll=value;

prenode->next=NULL;

for(i=2;i<=n;i++)

newnode=new link;

cout<<"Enter roll no. of student";

cin>>value;

newnode->roll=value;

prenode->next=newnode;

prenode=newnode;

newnode->next=NULL;

}
}

void begin()

int value;

newlink = new link;

cout<<"Enter roll no. of student:";

cin>>value;

newlink->roll=value;

newlink->next=start;

start=newlink;

void end()

int value;

newlink=new link;

cout<<"Enter roll no. of student:";

cin>>value;

link *temp;

temp=start;

while(temp->next!=NULL)

temp=temp->next;

temp->next=newlink;

newlink->roll=value;

newlink->next=NULL;

void display()

prenode=start;
while(prenode!=NULL)

cout<<prenode->roll<<endl;

prenode=prenode->next;

int main()

int a,b,i;

cout<<"Program to create a linked list"<<endl;

create();

cout<<"Enter no of values to be inserted at beginning of the linked list:";

cin>>a;

for(i=0;i<a;i++)

begin();

cout<<"Enter no of values to be inserted at the end of the linked list:";

cin>>b;

for(i=0;i<b;i++)

end();

cout<<"Created.....Displaying now:"<<endl;

display();

return 0;

You might also like