Insert from front

#include<iostream>
#include<conio.h>
using namespace std;
struct node
{
int info;
node *next;
};
int main()
{
struct node n,*head, *ptr, *ctr;
int number;
cout<<"How many nodes you want?\n";
cin>>number;
cout<<"Enter element : ";
cin>>n.info;
head=&n;
ptr=head;
for(int i=1;i<=number-1;i++)
{
ctr=new node;
cout<<"Enter element : ";
cin>>ctr->info;
ctr->next=NULL;
ptr->next=ctr;
ptr=ctr;
}
cout<<"Elements you entered:- \n";
ctr=head;
while(ctr!=NULL)
{
cout<<ctr->info<<endl;
ctr=ctr->next;
}
getch();
return 0;
}

Popular posts from this blog

Shutdown Pc

Ellipse using OpenGl

Program to plot Quadrant strip