Untitled
3 years ago in Plain Text
#include <stdio.h>
#include <stdlib.h>
#include "function.h"
void deleteNode(Node ** nd, int data)
{
Node *node;
Node *put;
int i=1;
for(node=*nd; node!=NULL; node=node->next)
{
if(data==1 && node!=NULL)
{
put=node;
*nd=node->next;
free(put);
break;
}
if(i+1==data && node->next!=NULL)
{
put=node->next;
node->next=put->next;
free(put);
break;
}
i++;
}
}
Node* createList()
{
Node *head;
Node *a, *rem;
int data, f=0;
while(scanf("%d", &data))
{
if(data>-1)
{
a=(Node*)malloc(sizeof(Node)*1);
a->data=data;
if(f==0)
{
f=1;
head=a;
rem=a;
}
else
{
rem->next=a;
rem=a;
}
}
else
break;
}
rem->next=NULL;
return head;
}