#include<iostream>
#include<malloc.h>
using namespace std;
void Create();
void deleteNode(struct Node **, struct Node *);
void disp();
void disp1();
int flag=0;
struct Node
{
int data;
struct Node *link;
}*start;
void Create();
void del();
void disp();
int main()
{
int n,i,m;
start=NULL;
cin>>n;
for(i=0;i<n;i++)
{
Create();
}
cin>>m;
for(i=0;i<m;i++)
{
deleteNode(&start, start);
if(flag==1)
break;
}
if(flag==0)
disp();
return 0;
}
void Create()
{
struct Node *temp,*t;
temp=(struct Node*) malloc(sizeof(struct Node));
cin>>temp->data;
temp->link=NULL;
if(start==NULL)
{
start=temp;
}
else
{
t=start;
while(t->link!=NULL)
t=t->link;
t->link=temp;
}
}
void deleteNode(struct Node **head_ref, struct Node *n)
{
if(start == n)
{
if(start->link == NULL)
{
disp1();
return;
}
start->data = start->link->data;
n = start->link;
start->link = start->link->link;
free(n);
return;
}
}
void disp()
{
struct Node *t;
t=start;
cout<<"Linked List : ";
while(t!=NULL)
{
cout<<"->"<<t->data;
t=t->link;
}
}
void disp1()
{
struct Node *t;
t=start;
cout<<"Linked List : ";
while(t->link!=NULL)
{
cout<<"->"<<t->data;
t=t->link;
}
flag=1;
}
#include<malloc.h>
using namespace std;
void Create();
void deleteNode(struct Node **, struct Node *);
void disp();
void disp1();
int flag=0;
struct Node
{
int data;
struct Node *link;
}*start;
void Create();
void del();
void disp();
int main()
{
int n,i,m;
start=NULL;
cin>>n;
for(i=0;i<n;i++)
{
Create();
}
cin>>m;
for(i=0;i<m;i++)
{
deleteNode(&start, start);
if(flag==1)
break;
}
if(flag==0)
disp();
return 0;
}
void Create()
{
struct Node *temp,*t;
temp=(struct Node*) malloc(sizeof(struct Node));
cin>>temp->data;
temp->link=NULL;
if(start==NULL)
{
start=temp;
}
else
{
t=start;
while(t->link!=NULL)
t=t->link;
t->link=temp;
}
}
void deleteNode(struct Node **head_ref, struct Node *n)
{
if(start == n)
{
if(start->link == NULL)
{
disp1();
return;
}
start->data = start->link->data;
n = start->link;
start->link = start->link->link;
free(n);
return;
}
}
void disp()
{
struct Node *t;
t=start;
cout<<"Linked List : ";
while(t!=NULL)
{
cout<<"->"<<t->data;
t=t->link;
}
}
void disp1()
{
struct Node *t;
t=start;
cout<<"Linked List : ";
while(t->link!=NULL)
{
cout<<"->"<<t->data;
t=t->link;
}
flag=1;
}
it is evaluating only 83%
ReplyDeletecould you complete it
Change void Create to int Create
ReplyDeleteit working 100% succesful
Delete