Visit: https://financeclub.viden.io
#include<stdio.h>
#include<stdlib.h>
int np;
struct Node{
int data;
struct Node* next;
};
void value_key(struct Node** head_ref,int value)
{
int i;
struct Node* temp=*head_ref;
for(i=0;i<=value;i++)
{
if(i==value)
{
//printf("%d",i);
printf("\nvalue at provided posn is %d\n",temp->data);
np=temp->data;
}
else
temp=temp->next;
//printf("%d",main_key);
}
}
void delete1(struct Node **head_ref,int key)
{
struct Node* temp=*head_ref,*prev;
if(temp!=NULL && temp->data==key)
{
*head_ref=temp->next;
free(temp);
return;
}
while(temp!=NULL && temp->data!=key)
{
prev=temp;
temp=temp->next;
}
if(temp==NULL) //not in list
{
return;
}
prev->next=temp->next;
free(temp);
}
void push(struct Node **head_ref,int y)
{
struct Node *new1=(struct Node*)malloc(sizeof(struct Node));
new1->data=y;
new1->next=*head_ref;
*head_ref=new1;
}
int main()
{
struct Node *head=NULL;
push(&head,7);
push(&head,1);
push(&head,9);
push(&head,12);
value_key(&head,0);
// delete1(&head,1);
//struct Node *temp =head;
delete1(&head,np);
while(head!=NULL)
{
printf("%d\n",head->data);
head=head->next;
}
return 0;
}