Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Circular Linked list/chandan
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

54 changes: 54 additions & 0 deletions Circular Linked list/circularlist.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include<stdio.h>
#include<stdlib.h>
struct node{
int data;
struct node* next;
};
struct node* last;
void create(int);
void display();
int main()
{
last=NULL;
int m,n,i;
printf("enter the number of node to be inserted");
scanf("%d",&m);
for(i=0; i<m; i++)
{
printf("enter the data");
scanf("%d",&n);
create(n);}
display();

return 0;
}

void create(int value)
{
struct node* temp;
temp=(struct node*)malloc(sizeof(struct node));
temp->data=value;
if((last==NULL))
{
last=temp;
last->next=temp;
}
else
{
temp->next=last;
last->next=temp;
last=temp;
}
}

void display()
{
struct node* p;
p=last->next;
while(p!=last)
{
printf(" %d ",p->data);
p=p->next;
}
printf(" %d ",last->data);
}
56 changes: 56 additions & 0 deletions Circular Linked list/circularlistatbeg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include<stdio.h>
#include<stdlib.h>
struct node{
int data;
struct node* next;
};
struct node* last;
void create(int);
void display();
int main()
{
last=NULL;
int m,n,i;
printf("enter the number nodes to be inserted\n");
scanf("%d",&m);
for(i=0; i<m; i++)
{
printf("enter the data\n");
scanf("%d",&n);
create(n);
}
display();
return 0;
}

void create(int n)
{
struct node* temp;
temp=(struct node*)malloc(sizeof(struct node));
temp->data=n;
if(last==NULL)
{
last=temp;
last->next=temp;
}
else
{
temp->next=last;
last->next=temp;
last=temp;
}
}


void display()
{
struct node* p;
p=last->next;
while(p!=last)
{
printf(" %d ",p->data);
p=p->next;
printf(" %d ",last->data);
}
}

74 changes: 74 additions & 0 deletions Circular Linked list/circularlistdeleteatbeg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include<stdio.h>
#include<stdlib.h>
struct node{
int data;
struct node* next;
};
struct node* last;
void create(int);
void display();
void deleteatbeg();
int main()
{
last=NULL;
int m,n,i;
printf("enter the number of node to be inserted");
scanf("%d",&m);
for(i=0; i<m; i++)
{
printf("enter the data");
scanf("%d",&n);
create(n);}
deleteatbeg();
display();

return 0;
}

void create(int value)
{
struct node* temp;
temp=(struct node*)malloc(sizeof(struct node));
temp->data=value;
if((last==NULL))
{
last=temp;
last->next=temp;
}
else
{
temp->next=last;
last->next=temp;
last=temp;
}
}

void display()
{
struct node* p;
p=last->next;
while(p!=last)
{
printf(" %d ",p->data);
p=p->next;
}
printf(" %d ",last->data);
}

void deleteatbeg()
{
struct node* p;
int m;
printf("enter the element to be deleted");
scanf("%d",&m);
p=last->next;
if(p->data==m)
{
last->next=p->next;
free(p);
return;
}
}



71 changes: 71 additions & 0 deletions Circular Linked list/circularlistinsertatbeg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include<stdio.h>
#include<stdlib.h>
struct node{
int data;
struct node* next;
};
struct node* last;
void create(int);
void display();
void insertatbeg();
int main()
{
last=NULL;
int m,n,i;
printf("enter the number of node to be inserted");
scanf("%d",&m);
for(i=0; i<m; i++)
{
printf("enter the data");
scanf("%d",&n);
create(n);}
insertatbeg();
display();

return 0;
}

void create(int value)
{
struct node* temp;
temp=(struct node*)malloc(sizeof(struct node));
temp->data=value;
if((last==NULL))
{
last=temp;
last->next=temp;
}
else
{
temp->next=last;
last->next=temp;
last=temp;
}
}

void display()
{
struct node* p;
p=last->next;
while(p!=last)
{
printf(" %d ",p->data);
p=p->next;
}
printf(" %d ",last->data);
}

void insertatbeg()
{
struct node* p;
struct node* temp;
int val;
printf("enter the data to be inserted");
scanf("%d",&val);
temp=(struct node*)malloc(sizeof(struct node));
temp->data=val;
p=last->next;
temp->next=p;
last->next=temp;
p=temp;
}
88 changes: 88 additions & 0 deletions Circular Linked list/circularlistinsertatnpos.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#include<stdio.h>
#include<stdlib.h>
struct node{
int data;
struct node* next;
};
struct node* last;
void create(int);
void display();
void insertatnpos();
int main()
{
last=NULL;
int m,n,i;
printf("enter the number of node to be inserted");
scanf("%d",&m);
for(i=0; i<m; i++)
{
printf("enter the data");
scanf("%d",&n);
create(n);}
insertatnpos();
display();

return 0;
}

void create(int value)
{
struct node* temp;
temp=(struct node*)malloc(sizeof(struct node));
temp->data=value;
if((last==NULL))
{
last=temp;
last->next=temp;
}
else
{
temp->next=last;
last->next=temp;
last=temp;
}
}

void display()
{
struct node* p;
p=last->next;
while(p!=last)
{
printf(" %d ",p->data);
p=p->next;
}
printf(" %d ",last->data);
}


void insertatnpos()
{
int value,position,i;
printf("enter the position at which we have to insert the node");
scanf("%d",&position);
printf("enter the data to be inserted");
scanf("%d",&value);
struct node* temp;
struct node* p;
temp=(struct node*)malloc(sizeof(struct node));
temp->data=value;
p=last->next;
for(i=1; i<position-1; i++)
{
p=p->next;
}
if(p==last)
{
temp->next=p->next;
p->next=temp;
}
if(p==last)
{
temp->next=p->next;
p->next=temp;
p=temp;
}
}


32 changes: 32 additions & 0 deletions SORTING ALGORITHMS/bublesort.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include<stdio.h>
int main()
{
int a[100],i,n,j;
printf("enter the number of element we want to sort\n");
scanf("%d",&n);
printf("enter those values\n");
for(i=0; i<n; i++)
{
scanf("%d",&a[i]);
}

for(i=0; i<n-1; i++)
{
for(j=0; j<n-1-i; j++)
{
if(a[j]>a[j+1])
{
int temp;
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf("after sorting \n");
for(i=0; i<n; i++)
{
printf(" %d ",a[i]);
}
return 0;
}
1 change: 1 addition & 0 deletions SORTING ALGORITHMS/chandan
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading