Post on 07-Apr-2017
#include <stdio.h>
#include <stdlib.h>
typedef struct list{
int v;
struct list * n;
}h;
h*cr()
{
return (h*)malloc(sizeof(h));
}
void insert(h*t,int data){
while(t->n!=NULL)
{
t=t->n;
}
t->n=cr();
t->n->v=data;
t->n->n=NULL;
}
void dis(h*t)
{
while(t->n!=NULL)
{
printf("%d -> ",t->n->v);
t=t->n;
}
printf("NULL");
}
int search(h*t,int data)
{
int i=0;
while(t->n!=NULL)
{
i++;
if(data==t->n->v)
{
printf("\nvalue found.Location= %d\n",i);
return i;
}
t=t->n;
}
}
void inaf(h*t, int search, int data)
{
while(t->n != NULL)
{
if(t->n->v == search)
{
h *store = t->n->n;
t->n->n = cr();
t->n->n->v = data;
t->n->n->n = store;
}
t=t->n;
}
}
int del(h *t, int data)
{
while(t->n != NULL)
{
if(t->n->v == data)
{
t->n = t->n->n;
return 0;
}
t = t->n;
}
}
void countNode(h *t)
{
int count = 0;
while(t->n != NULL)
{
count++;
t = t->n ;
}
printf("\nTotal %d nodes found.\n", count);
}
int main()
{
h*f=cr();
f->n=NULL;
insert(f, 5);
insert(f, 9);
insert(f, 11);
insert(f, 9);
dis (f);c
countNode(f );
search(f, 9);
inaf (f, 11, 44);
del (f, 9);
dis(f);
}