I have written code for linked list. I want to make a function that can search any specific node in list
N3 -> N2 ->N1-> Null;
@WBahn
How to make a function to find node 1 in list ?
C:
//Linked list code
#include<stdio.h>
#include<stdlib.h>
//structure for node in list
struct node
{
int data; // first member of node in list
struct node *next; // second member of node in list
};
// Add node to front of List
void insert ( struct node **current, int value)
{
struct node *temp = malloc( sizeof( struct node));
{
if ( temp != NULL ) // Memory allocated successfully
{
temp -> data = value; // assign value to first member of node
temp -> next = *current; // this member point to previous node in list
*current = temp; // temporary node becomes current node in list
}
}
}
int main()
{
struct node *current = NULL; // empty list
insert(¤t, 1); // node 1 hold value 1 in list
printf("%d \n", current-> data);
insert(¤t, 2); // node 2 hold value 2 in list
printf("%d \n", current-> data);
insert(¤t, 3); // node 3 hold value 3 in list
printf("%d \n", current-> data);
return 0;
}
Code:
1
2
3
@WBahn
How to make a function to find node 1 in list ?