Posts

Showing posts from October, 2019

Bubble sort

Image
#include #include void swap(int *,int *); void main() { int i,n,j,a[30]; clrscr(); printf("enter the size of array\n"); scanf("%d",&n); printf("enter the elements\n"); for(i=0;i { scanf("%d",&a[i]); } for(i=0;i { printf("%d\t",a[i]); } for(i=0;i { for(j=0;j { if(a[j]>a[j+1]) { swap(&a[j],&a[j+1]); } }   } printf("\nsorted array\n"); for(i=0;i { printf("%d\t",a[i]); } getch(); } void swap(int *p,int *q) { int temp; temp=*p; *p=*q; *q=temp;   }

INSERTION

Image
#include #include void insertion(long int [],int);//protype int main() {       long int a[20]; int i,j,n; printf("Program of insertion\n"); printf("enter the size of array\n"); scanf("%d",&n); for(i=0;i { scanf("%ld",&a[i]); } printf("before sorted\n\n"); for(i=0;i printf("%ld\t",a[i]); insertion(a,n);//calling of insertion function printf("\nsorted array by insertion method\n"); for(i=0;i { printf("%ld\t",a[i]);   } getch(); return 0;   } void insertion(long int a[], int n) {       long int temp,i,j; for(i=1;i {       temp=a[i];//make a temperoray variable. for(j=i-1;j>=0 && temp        { a[j+1]=a[j]; }   a[j+1]=temp;   }   }

MALLOC PROGRAM

Image
#include #include #include void main() { int *ptr,*p,i,n,sum=0;//declare variables clrscr(); printf("============================================================\n"); printf("Malloc function Program\n"); printf("============================================================\n"); printf("\n\nEnter the size the of array\n"); scanf("%d",&n); printf("Enter the array Elements\n"); ptr=(int *)malloc(n*sizeof(int));//using malloc function p=ptr; for(i=0;i { scanf("%d",ptr); sum=sum+ *ptr; ptr++;   } printf("Array elements Entered by you\n"); for(i=0;i { printf("%d\n",*p); p++; } printf("sum of all elements= %d",sum); getch(); }

MERGING LINK LIST

Image
------------------------------------------------- #include #include #include #include struct node{ int data; struct node *link; }; void main() { struct node *head=NULL,*ptr,*temp,*head2=NULL,*temp2; int i,n; clrscr(); printf("====================================================\n"); printf("merging of link list program\n"); printf("enter the size of link list\n"); scanf("%d",&n); for(i=0;i {        temp=(struct node*)malloc(sizeof(struct node));        printf("enter the data in new node\n");        scanf("%d",&temp->data);        temp->link=NULL; if(head==NULL)   head=temp;   else   { ptr=head; while(ptr->link!=NULL) ptr=ptr->link; ptr->link=temp; }} printf("link list 1st\n ") ptr=head; while(ptr!=NULL) {        printf("\t%d",ptr->data);        ptr=ptr->link; } printf("\n======================

DYNAMICS STRUCTURE

Image
#include #include struct book{ int p; char name[20]; char author[20]; }; int main() {  struct book *s,*r; int i,n; printf("enter the size of structure\ndynamically structure\n"); scanf("%d",&n); s=(struct book *)malloc(n*sizeof(struct book)); for(i=0;i<=n-1;i++) { scanf("%d",&(s+i)->p);//address uses for integer in structure   fflush(stdin);   gets((s+i)->name);// not address uses in gets function so not given   fflush(stdin);   gets((s+i)->author); } for(i=0;i<=n-1;i++) { printf("%d\n",(s+i)->p);/*value of integer is accessible without using *   Because p is not address*/    printf("%s\n",(s+i)->name);    printf("%s",(s+i)->author);    } r=(struct book*)realloc(s,2*n*sizeof(struct book)); for(i=0;i<=2*(n);i++) { scanf("%d",&(s+i)->p);//address uses for integer in structure   fflush(stdin);   gets((s+i)->name);// not address uses in get

DELETION IN LINK LIST

Image
-------------------------------------------------------------------------------------------------------------------------- #include #include #include #include struct node{ int data; struct node *next; }; struct node * deleting(struct node *head ,int n); void main() { struct node *head=NULL,*ptr=NULL,*temp=NULL,*ptr2,*ptr3; int n,i; clrscr(); printf("enter the size of link list \n"); scanf("%d",&n); for(i=0;i        { temp=(struct node *)malloc(sizeof(struct node)); temp->next=NULL; printf("\nenter the data in temp variable"); scanf("%d",&temp->data); if(head==NULL) {     head=temp; } else { ptr=head; while(ptr->next!=NULL) ptr=ptr->next; ptr->next=temp; }} ptr3=head; while(ptr3!=NULL) { printf("%d ",ptr3->data); ptr3=ptr3->next; }      head=deleting(head,n);      printf("after deletingn\n");

STACK USING LINK LIST

Image
  #include<conio.h> #include<stdio.h> #include<iostream.h> #include<stdlib.h> struct node{ int data; struct node *next; }; void main() { struct node *head=NULL,*ptr=NULL,*temp=NULL,*top,*ptr2,*ptr3,*ptr4=NULL; int choice; clrscr(); while(1)        { printf("--------------------program of stack using link list-------------\n"); printf("press 1 for insertion\npress 2 for deletion\npress 3 for view the stack\npress 4 for source code\n"); scanf("%d",&choice); switch(choice) { case 1: temp=(struct node *)malloc(sizeof(struct node)); temp->next=NULL; printf("\nenter the data in temp variable"); scanf("%d",&temp->data); if(temp==NULL) {     printf("stack is overflow\n"); }        else if(head==NULL) {     head=temp; top=temp; }  else  {  ptr=head;  while(ptr->next!=NUL

Data redundancy

Image
#include<conio.h> #include<stdio.h> #include<string.h> #include<stdlib.h> struct node{ char data[20]; struct node *link; }; void main() { struct node *head=NULL,*ptr=NULL,*temp=NULL,*ptr2,*ptr3,*ptr4,*temp2; int i,n; clrscr(); printf("enter the number of nodes\n"); scanf("%d",&n); for(i=0;i<n;i++) {    temp=(struct node *)malloc(sizeof(struct node));   printf("enter the data in node part\n");    fflush (stdin);    gets(temp->data);   // scanf("%d",&temp->data);    temp->link=NULL;    if(head==NULL)      { head=temp;       }    else    {       ptr=head;       while(ptr->link!=NULL)        ptr=ptr->link; ptr->link=temp; } }       ptr=head;//sorting algorithm       while(ptr->link!=NULL)       { ptr2=ptr; ptr=ptr->link; ptr3=ptr; while(ptr3!=NULL) {       if(strcmp(ptr2->data,ptr3->data)>0)       {    strcpy

REVERSAL IN SINGLE LINK LIST:

Image
REVERSAL IN SINGLE LINK LIST: #include<conio.h> #include<stdio.h> #include<stdlib.h> struct node{ int data; struct node *link; }; void reversal(struct node *head); void main() { struct node *head=NULL,*ptr=NULL,*temp=NULL; int i,n; clrscr(); printf("enter the number of nodes\n"); scanf("%d",&n); for(i=0;i<n;i++) {    temp=(struct node *)malloc(sizeof(struct node));    printf("enter the data in node part\n");    scanf("%d",&temp->data);    temp->link=NULL;    if(head==NULL)      { head=temp;       }    else     ptr=head;     while(ptr->link!=NULL)        { ptr=ptr->link; } ptr->link=temp;       }       ptr=head;      printf("print link list\n");      while(ptr!=NULL)      { printf("\n%d",ptr->data);        ptr=ptr->link;        }   reversal(head); getch(); } void reversal(struct node *head) { struct node *prevnode=NULL,*currentnode=N

double link list complete//

Image
#include<conio.h> #include<stdio.h> #include<stdlib.h> struct node{ int data; struct node* link; }; int main() {        struct node *ptr3,*temp2 ,*head=NULL,*ptr=NULL,*front=NULL,*rear=NULL,*temp=NULL,*ptr2=NULL;//pointer declaration        int n;        printf("circular queue program is created by mine\n\n");        printf("===========================================================================\n");        while(1)        {        printf("press the key for doing operations in our program\n");        printf("1. enqueue\n2. dequeue\n3. view the queue\n4. exit\n");        scanf("%d",&n);        switch(n)        { case 1: temp=(struct node*)malloc(sizeof(struct node)); //memory allocated temp->link=NULL; printf("enter the value in new node\n"); scanf("%d",&temp->data); if(head==NULL)        { head=temp; front=head; rear=head;