Lab 5
Lab 5
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
struct list{
int data;
struct list* link;
};
if(ptr==NULL) {
return temp;
}
struct list* ptr2=ptr;
while(ptr2->link){
ptr2=ptr2->link;
}
ptr2->link=temp;
return ptr;
}
return ;
}
int main(){
clock_t start=clock();
OUTPUT:
// creating list 1->2->3->4->5
struct list* head=NULL;
int n;
printf("Enter the size of the list : ");
scanf("%d",&n);
printf("Enter the elements of the list : ");
for(int i=0;i<n;i++){
int a;
scanf("%d",&a);
head=add_at_end(head,a);
}
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
struct list{
int data;
struct list* link;
};
if(ptr==NULL) {
return temp;
}
struct list* ptr2=ptr;
while(ptr2->link){
ptr2=ptr2->link;
}
ptr2->link=temp;
return ptr;
}
int main(){
clock_t start=clock();
// creating list 1->2->3->4->5
struct list* head=NULL;
int n;
printf("Enter the size of the list : ");
scanf("%d",&n);
printf("Enter the elements of the list : ");
for(int i=0;i<n;i++){
int a;
scanf("%d",&a);
head=add_at_end(head,a);
}
clock_t end=clock();
double executiontime=(double)(end-start)/CLOCKS_PER_SEC;
printf("\nexection time : %f",executiontime);
return 0;
}
3. Write a program to create a circularly linked list of integers entered by user and insert a new
node:
a. At the beginning
b. At the end.
CODE:
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
struct node {
int data;
struct node* link;
};
ptr->link=tail->link;
tail->link=ptr;
tail=ptr;
return tail;
}
OUTPUT:
void print(struct node* tail){
struct node* ptr=tail;
do{
ptr=ptr->link;
printf("%d->",ptr->data);
}
while(ptr!=tail);
printf("repeats \n");
}
int main(){
clock_t start=clock();