I am not able to add elements to the end of a single Linked List. I have tried looking other questions but I am not able to find a solution.
The code is:
#include<stdio.h>
#include<stdlib.h>
struct node{
int data;
struct node* next;
};
void PushE(struct node** head,int data);
int main(){
struct node* a = NULL;
PushE(&a,3);
PushE(&a,4);
}
void PushE(struct node** headRef, int data){
struct node* current = *headRef;
struct node* nNode;
nNode = (struct node*)malloc(sizeof(struct node));
nNode->data = data;
nNode->next= NULL;
if(current == NULL)
current = nNode;
else{
while(current->next != NULL)
current = current->next;
current->next = nNode;
}
}
Can anyone help me implement this.