#include<iostream>
#include<conio.h>
#include<stdlib.h>
#include<malloc.h>
using namespace std;
struct node
{
int info;
struct node*link;
}*start;
void add(int data)
{
struct node*temp;
temp=(node*)malloc(sizeof(struct node));
temp->info=data;
temp->link=start;
start=temp;
}
void create_list(int data)
{
struct node*q, *temp;
temp=(node*) malloc(sizeof(struct node));
temp-> info=data;
temp-> link=NULL;
if(start==NULL)
start=temp;
else
{
q=start;
while(q-> link!=NULL)
q=q-> link;
q-> link=temp;
}
}
void display()
{
struct node *q;
if(start==NULL)
{
cout<<" we got an empty linked list";
return;
}
q=start;
cout<<endl;
cout<<"List is ";
while(q!=NULL)
{
cout<<q->info;
q=q->link;
}
}
int main()
{
int a;
cout<<" Please enter value SIR"<<endl;
start=NULL;
for(int i=0;i<10;i++)
{
cin>>a;
//a=10;
create_list(a);
}
display();
add(8);
display();
system("pause");
}
This post has been edited by jimblumberg: 10 October 2012 - 06:56 AM
Reason for edit:: Added missing Code Tags, Please learn to use them.

New Topic/Question
Reply



MultiQuote




|