Write a program in C that the add a node at the end of a singly
linked list [6]
b) Explain what is referred to as complexity of an
algorithm
[2]
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
};
//method to add node at the end of the singly linked list
void addAtEnd(struct node *head,int data)
{
struct node *temp=head;
if(head==NULL)//if list is empty
{
head = (struct
node*)malloc(sizeof(struct node));
head->data=data;
head->next=NULL;
}else
{
//traversing upto end to
insert
while(temp->next!=NULL)
{
temp=temp->next;
}
temp->next = (struct
node*)malloc(sizeof(struct node));
temp->data=data;
temp->next=NULL;
}
}
//b
//complexity is O(n)//n is number of nodes in list
int main()
{
return 0;
}