You are on page 1of 1

;// Linked list (Adding element to end)

#include<stdio.h>
#include<stdlib.h>

struct node
{
int data;
struct node* link;
};

void add_end(struct node* head,int d)


{
struct node* temp;
struct node* ptr;

ptr = head;

temp= (struct node*) malloc(sizeof(struct node));


temp->data= d;
temp->link= NULL;

while(ptr->link!=NULL) // Traversal till last node


{
ptr = ptr->link;
}

ptr->link= temp;
}

int main()
{
struct node* head = (struct node*) malloc(sizeof(struct node));

head-> data= 32;


head-> link = NULL;

add_end(head,64);
add_end(head,90);

while(head!=NULL)
{
printf("%d\n",head->data);
head = head->link;
}

return 0;
}

You might also like