diff --git a/Circular Linked list/chandan b/Circular Linked list/chandan new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Circular Linked list/chandan @@ -0,0 +1 @@ + diff --git a/Circular Linked list/circularlist.c b/Circular Linked list/circularlist.c new file mode 100644 index 0000000..65614ec --- /dev/null +++ b/Circular Linked list/circularlist.c @@ -0,0 +1,54 @@ +#include +#include +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; idata=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); +} diff --git a/Circular Linked list/circularlistatbeg.c b/Circular Linked list/circularlistatbeg.c new file mode 100644 index 0000000..2824c6f --- /dev/null +++ b/Circular Linked list/circularlistatbeg.c @@ -0,0 +1,56 @@ +#include +#include +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; idata=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); +} +} + diff --git a/Circular Linked list/circularlistdeleteatbeg.c b/Circular Linked list/circularlistdeleteatbeg.c new file mode 100644 index 0000000..611ba8e --- /dev/null +++ b/Circular Linked list/circularlistdeleteatbeg.c @@ -0,0 +1,74 @@ +#include +#include +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; idata=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; +} +} + + + diff --git a/Circular Linked list/circularlistinsertatbeg.c b/Circular Linked list/circularlistinsertatbeg.c new file mode 100644 index 0000000..89007d8 --- /dev/null +++ b/Circular Linked list/circularlistinsertatbeg.c @@ -0,0 +1,71 @@ +#include +#include +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; idata=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; +} diff --git a/Circular Linked list/circularlistinsertatnpos.c b/Circular Linked list/circularlistinsertatnpos.c new file mode 100644 index 0000000..1403daf --- /dev/null +++ b/Circular Linked list/circularlistinsertatnpos.c @@ -0,0 +1,88 @@ +#include +#include +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; idata=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; inext; +} +if(p==last) +{ +temp->next=p->next; +p->next=temp; +} +if(p==last) +{ +temp->next=p->next; +p->next=temp; +p=temp; +} +} + + diff --git a/SORTING ALGORITHMS/bublesort.c b/SORTING ALGORITHMS/bublesort.c new file mode 100644 index 0000000..346333b --- /dev/null +++ b/SORTING ALGORITHMS/bublesort.c @@ -0,0 +1,32 @@ +#include +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; ia[j+1]) +{ +int temp; +temp=a[j]; +a[j]=a[j+1]; +a[j+1]=temp; +} +} +} +printf("after sorting \n"); +for(i=0; i +int main() +{ +int a[100],i,j,temp,n; +printf("enter the number of element to be sorted\n"); +scanf("%d",&n); +printf("enter those element\n"); +for(i=0; i=0; j-- && temp +int main() +{ +int a[100],i,j,n,k,temp; +printf("enter the number of element yo want to sort\n"); +scanf("%d",&n); +printf("enter those elements\n"); +for(i=0; i +#include +#define max 15 +int a[max]; +int top=-1; +void push(); +void pop(); +void display(); +int main() +{ +int choice; +while(1) +{ +printf("enter 1 for push\n"); +printf("enter 2 for pop\n"); +printf("enter 3 to display\n"); +printf("enter 4 to exit\n"); + +printf("enter the operation which you want to exceute\n"); +scanf("%d",&choice); +switch(choice) +{ +case 1: +push(); +break; +case 2: +pop(); +break; +case 3: +display(); +break; +case 4: +exit(0); +break; +default: +printf("enterd choice is wrong"); +} +} +} + +void push() +{ +int item; +printf("enter the element to inserted"); +scanf("%d",&item); +if(top==max-1) +{ +printf("stack overflow"); +return; +} +top=top+1; +a[top]=item; +} + +void pop() +{ +if(top==-1) +{ +printf("stack underflow"); +return; +} +printf("poped element is\n"); +printf(" %d ",a[top]); +top=top-1; +} + +void display() +{ +int i; +if(top==-1) +{ +printf("no element is present in the stack"); +return; +} +for(i=top; i>=0; i++) +{ + +printf("element is \n"); +printf(" %d ",a[i]); + +} +} + diff --git a/linkedLists/deletionatNpos.c b/linkedLists/deletionatNpos.c new file mode 100644 index 0000000..576ae8e --- /dev/null +++ b/linkedLists/deletionatNpos.c @@ -0,0 +1,92 @@ +#include +#include +struct node{ +int data; +struct node* next; +}; +struct node* head; +void insert(int,int); +void delete(int); +void print(); +int main() +{ +struct node* head; +head=NULL; +insert(5,1); //*inserting the data and position +insert(19,2); +insert(2,3); +insert(4,4); +insert(34,5); +print(); +delete(3); +} +void insert(int data,int position) +{ +int i; +struct node* temp1; +temp1=(struct node*)malloc(sizeof(struct node)); +temp1->data=data; +temp1->next=NULL; +if(position==1) +{ +temp1->next=head; +head=temp1; +return; +} +struct node* temp2; +temp2=head; +for(i=0; inext; +} +temp1->next=temp2->next; +temp2->next=temp1; +} +void print() +{ +struct node* temp; +temp=head; +while(temp!=NULL) +{ +printf(" %d ",temp->data); +temp=temp->next; +} +printf("\n"); +} +void delete(int position) +{ +struct node* temp1; +temp1=(struct node*)malloc(sizeof(struct node)); +if(position==1) +{ +head=temp1->next; +free(temp1); +return; +} +for position; +for(position=0; inext; +} +struct node* temp2; +temp2=temp1->next; +temp1->next=temp2->next; +free(temp2); +} + + + + + + + + + + + + + + + + + diff --git a/linkedLists/insertatbegining.c b/linkedLists/insertatbegining.c new file mode 100644 index 0000000..c13dd32 --- /dev/null +++ b/linkedLists/insertatbegining.c @@ -0,0 +1,44 @@ +#include +struct node{ +int info; +struct node* link; +}; +struct node* head; +void insert(int); +void print(); +int main() +{ +head=NULL; +int i,n,x; +printf("enter the number of node to be inserted"); +scanf("%d",&n); +for(i=0; iinfo=x; +temp->link=head; +head=temp; +} +void print() +{ +struct node* temp; +temp=head; +printf("the node is: "); +while(temp!=NULL) +{ +printf(" %d ",temp->info); +temp=temp->link; +} +printf("\n"); +} + diff --git a/linkedLists/insertionatNpos.c b/linkedLists/insertionatNpos.c new file mode 100644 index 0000000..900a24f --- /dev/null +++ b/linkedLists/insertionatNpos.c @@ -0,0 +1,53 @@ +#include +#include +struct node{ +int data; +struct node* next; +}; +struct node* head; +void insert(int,int); +void print(); +int main() +{ +struct node* head; +head=NULL; +insert(5,1); //*inserting the data and position +insert(19,2); +insert(2,3); +insert(4,4); +insert(34,5); +print(); +} +void insert(int data,int position) +{ +int i; +struct node* temp1; +temp1=(struct node*)malloc(sizeof(struct node)); +temp1->data=data; +temp1->next=NULL; +if(position==1) +{ +temp1->next=head; +head=temp1; +return; +} +struct node* temp2; +temp2=head; +for(i=0; inext; +} +temp1->next=temp2->next; +temp2->next=temp1; +} +void print() +{ +struct node* temp; +temp=head; +while(temp!=NULL) +{ +printf(" %d ",temp->data); +temp=temp->next; +} +printf("\n"); +} diff --git a/linkedLists/insertionatNposuser.c b/linkedLists/insertionatNposuser.c new file mode 100644 index 0000000..f2973bf --- /dev/null +++ b/linkedLists/insertionatNposuser.c @@ -0,0 +1,63 @@ +#include +#include +struct node{ +int data; +struct node* next; +}; +struct node* head; +void insert(int,int); +void print(); +int main() +{ +struct node* head; +head=NULL; +int i; +int n; +int data,position; +printf("enter the number of nodes to be inserted\n"); +scanf("%d",&n); +for(i=0; idata=data; +temp1->next=NULL; +insert(data,position); +print(); +} +} +void insert(int data,int position) +{ +int i; +struct node* temp1; +temp1=(struct node*)malloc(sizeof(struct node)); +temp1->data=data; +temp1->next=NULL; +if(position==1) +{ +temp1->next=head; +head=temp1; +return; +} +struct node* temp2; +temp2=head; +for(i=0; inext; +} +temp1->next=temp2->next; +temp2->next=temp1; +} +void print() +{ +struct node* temp; +temp=head; +while(temp!=NULL) +{ +printf(" %d ",temp->data); +temp=temp->next; +} +printf("\n"); +} diff --git a/linkedLists/link1.c b/linkedLists/link1.c new file mode 100644 index 0000000..ee50761 --- /dev/null +++ b/linkedLists/link1.c @@ -0,0 +1,26 @@ +#include +struct node{ +int info; +struct node* link; +}; +struct node* head; +int main() +{ +int x,n,i; +printf("enter how many nodes you want to create"); +scanf("%d",&n); +head=NULL; +for(i=0; iinfo=x; +temp->link=NULL; +head=temp; +printf(" %d-> ",temp->info); +} +return 0; +} + diff --git a/linkedLists/linkcreation.c b/linkedLists/linkcreation.c new file mode 100644 index 0000000..7b9f3b5 --- /dev/null +++ b/linkedLists/linkcreation.c @@ -0,0 +1,26 @@ +#include +#include +struct node +{ +int info; +struct node *link; +}; +int main() +{ +struct node *p,*start,*temp; +int element; +/* +printf("enter the total number of node"); +scanf("%d",&n); +printf("enter the element part"); +scanf("%d",element); +*/ +temp=(struct node*)malloc(sizeof(struct node)); +printf("enter the element part"); +scanf("%d",element); +temp->info=element; +temp->link=NULL; +p=temp; +printf("node is %d",temp->info); +return 0; +} diff --git a/linkedLists/linklalit.c b/linkedLists/linklalit.c new file mode 100644 index 0000000..4beaf95 --- /dev/null +++ b/linkedLists/linklalit.c @@ -0,0 +1,58 @@ +#include +#include +struct node{ +int data; +struct node* next; +}; +struct node* head; +struct node* last; +void create(int); +void display(); +int main() +{ +head=NULL; +last=NULL; +int m,n,i; +printf("enter the number of nodes to be created"); +scanf("%d",&n); +for(i=0; idata=value; +temp->next=NULL; +if(head==NULL) +{ +head=temp; +last=temp; +} +else +{ +last->next=temp; +last=temp; +} +} +void display() +{ +struct node* p; +p=head; +if(head==NULL) +printf("list is empty"); +else +{ +while(p!=NULL) +{ +printf(" %d ",p->data); +p=p->next; +} +} +} diff --git a/linkedLists/linklalit1.c b/linkedLists/linklalit1.c new file mode 100644 index 0000000..ba69a43 --- /dev/null +++ b/linkedLists/linklalit1.c @@ -0,0 +1,51 @@ +#include +#include +struct node{ +int data; +struct node* next; +}; +struct node* head; +struct node* last; +void insertatstart(int); +void display(); +int main() +{ +head=NULL; +last=NULL; +int m,n,i; +printf("enter the number of node to be inserted"); +scanf("%d",&n); +for(i=0; idata=value; +temp->next=NULL; +temp->next=head; +head=temp; +} +void display() +{ +struct node* p; +p=head; +if(head==NULL) +printf("list is empty"); +else +{ +while(p!=NULL) +{ +printf(" %d ",p->data); +p=p->next; +} +} +} + diff --git a/linkedLists/linklalit2.c b/linkedLists/linklalit2.c new file mode 100644 index 0000000..959170b --- /dev/null +++ b/linkedLists/linklalit2.c @@ -0,0 +1,77 @@ +#include +#include +struct node{ +int data; +struct node* next; +}; +struct node* head; +struct node* last; +void insertatpos(int,int); +void display(); +void create(int); +int main() +{ +head=NULL; +last=NULL; +int m,n,i,pos; +printf("enter the number of node to be inserted"); +scanf("%d",&n); +for(i=0; idata=value; +temp->next=NULL; +struct node* p; +p=head; +int i; +for(i=1; inext; +temp->next=p->next; +p->next=temp; +} +void display() +{ +struct node* p; +p=head; +if(head==NULL) +printf("list is empty"); +else +{ +while(p!=NULL) +{ +printf(" %d ",p->data); +p=p->next; +} +} +} +void create(int value) +{ +struct node* temp; +temp=(struct node*)malloc(sizeof(struct node)); +temp->data=value; +temp->next=NULL; +if(head==NULL) +{ +head=temp; +last=temp; +} +else +{ +last->next=temp; +last=temp; +} +} diff --git a/linkedLists/linklalit3.c b/linkedLists/linklalit3.c new file mode 100644 index 0000000..b189263 --- /dev/null +++ b/linkedLists/linklalit3.c @@ -0,0 +1,77 @@ +#include +#include +struct node{ +int data; +struct node* next; +}; +struct node* head; +struct node* last; +void create(int); +void display(); +void search(int); +int main() +{ +head=NULL; +last=NULL; +int m,n,i,tump; +printf("enter the number of node to be created"); +scanf("%d",&n); +for(i=0; idata=value; +temp->next=NULL; +if(head==NULL) +{ +head=temp; +last=temp; +} +else +{ +last->next=temp; +last=temp; +} +} +void display() +{ +struct node* p; +p=head; +if(head==NULL) +printf("list is empty"); +else +{ +while(p!=NULL) +{ +printf(" %d->",p->data); +p=p->next; +} +} +} +void search(int m) +{ +struct node* p; +p=head; +while(p!=NULL) +{ +if(p->data==m) +{ +printf("element is found\n"); +printf("element is %d ",p->data); +} +else +printf("element is not found"); +p=p->next; +} +} diff --git a/linkedLists/linklalit4.c b/linkedLists/linklalit4.c new file mode 100644 index 0000000..e362a23 --- /dev/null +++ b/linkedLists/linklalit4.c @@ -0,0 +1,85 @@ +#include +#include +struct node{ +int data; +struct node* next; +}; +struct node* head; +struct node* last; +void create(int); +void display(); +void deleteatpos(int); +int main() +{ +head=NULL; +last=NULL; +int m,n,i,pos; +printf("enter the number of nodes to be created"); +scanf("%d",&n); +for(i=0; idata=value; +temp->next=NULL; +if(head==NULL) +{ +head=temp; +last=temp; +} +else +{ +last->next=temp; +last=temp; +} +} +void display() +{ +struct node* p; +p=head; +if(head==NULL) +printf("list is empty"); +else +{ +while(p!=NULL) +{ +printf(" %d ",p->data); +p=p->next; +} +} +} + +void deleteatpos(int position) +{ +struct node* temp; +struct node* p; +p=head; +int i; +for(i=1; inext; +} +temp=p->next; +p->next=temp->next; +free(temp); +} + + + + + + + diff --git a/linkedLists/linklist1.c b/linkedLists/linklist1.c new file mode 100644 index 0000000..405feb1 --- /dev/null +++ b/linkedLists/linklist1.c @@ -0,0 +1,49 @@ +#include +#include +struct node +{ +int info; +struct node *link; +}; +struct node *start=NULL; +struct node *createnode(); +void createlink(); +int main() +{ +createnode(); +createlink(); +return 0; +} +struct node *createnode() +{ +struct node *n; +n=(struct node*)malloc(sizeof(struct node)); +return (n); +} +void createlink() +{ +struct node *temp; +int i,n; +temp=createnode(); +start=temp; +printf("enter the number of node to be created"); +scanf("%d",&n); +printf("enter the info part"); +scanf("%d",&temp->info); +temp->link=NULL; +printf(" %d ",temp->info); +for(i=1; i<=n; i++) +{ +if(ilink; +printf("enter the info part"); +scanf("%d",&temp->info); +printf(" %d ",temp->info); +} +else +temp->link=NULL; +} +} + + diff --git a/queue/queue.c b/queue/queue.c new file mode 100644 index 0000000..7934b60 --- /dev/null +++ b/queue/queue.c @@ -0,0 +1,92 @@ +#include +#include +struct node{ +int data; +struct node* next; +}; +struct node* front; +struct node* rear; +void insert(); +void delete(); +void display(); +int main() +{ +front=NULL; +rear=NULL; +int choice; +while(1) +{ +printf("enter 1 to insert\n"); +printf("enter 2 to delete\n"); +printf("enter 3 to display\n"); +printf("enter 4 to exit\n"); +printf("enter the choice\n"); +scanf("%d",&choice); +switch(choice) +{ +case 1: +insert(); +break; +case 2: +delete(); +break; +case 3: +display(); +break; +case 4: +exit(0); +break; +default: +printf("enterd choice is wrong"); +} +} +return 0; +} + +void insert() +{ +int item; +printf("enter the element"); +scanf("%d",&item); +struct node* temp; +temp=(struct node*)malloc(sizeof(struct node)); +temp->data=item; +temp->next=NULL; +if(front==NULL) +{ +front=temp; +rear=temp; +} +else +{ +rear->next=temp; +rear=temp; +} +} + +void delete() +{ +struct node* p; +if(front==NULL) +{ +printf("queue underflow"); +return; +} +p=front; +front=front->next; +printf("deleted element is \n"); +printf(" %d ",p->data); +free(p); +} + +void display() +{ +struct node* p; +p=front; +while(p!=NULL) +{ +printf(" %d ",p->data); +p=p->next; +} +} +