Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

//Gaurav Bharti , Section-F, Roll No.

-27
//Code for binary search tree.

#include <stdio.h>

void bin_search(int [], int, int, int);

void sort(int [], int);

int main()

int n, size, i;

int list[25];

printf("Enter size of a list: ");

scanf("%d", &size);

printf("Enter elements\n");

for(i = 0; i < size; i++)

scanf("%d",&list[i]);

sort(list, size);

printf("\n");

printf("Enter number to search\n");

scanf("%d", &n);

bin_search(list,0,size,n);

return 0;

void sort(int list[], int size)

int temp, i, j;
for (i = 0;i<size;i++)

for (j=i;j<size;j++)

if (list[i]>list[j])

temp = list[i];

list[i] = list[j];

list[j] = temp;

void bin_search(int list[], int l, int m, int n)

int mid;

if (l>m)

printf("Key not found\n");

return;

mid = (l+m) / 2;

if (list[mid]==n)

printf("Element found\n");

else if (list[mid]>n)

bin_search(list,l,mid-1,n);
}

else if (list[mid]<n)

bin_search(list,mid+1,m,n); }

}
//Code for multi processing environment
#include<stdio.h>

#include<stdlib.h>

typedef struct node{

int num, d;

struct node *next;

} nodetype ;

void insert( nodetype** , int, int );

void task(nodetype **, int, int );

void delete(nodetype **p);

void display(nodetype*);

int main(){

nodetype *l=NULL;

int time ,n,x ;

printf("Enter the processing unit in nanosecond : ");

scanf("%d", &time);

printf("Enter the number of processes : ");

scanf("%d", &n);

printf("*Enter all the processes*\n");

int i=0;

while(i<n){

printf("Enter the time of Process %d : ", i+1);

scanf("%d", &x);

insert(&l, x , i+1);

i++;

}
task(&l, time, n);

printf("\n**All processes completed successfully !!**");

return 0;

void insert ( nodetype **l, int d, int n){

nodetype *p=NULL;

p=(nodetype*)malloc(sizeof(nodetype));

if(p!=NULL){

p->num=n;

p->d=d;

if(*l==NULL){

*l = p;

(*l)->next = p;

return;

p->next=(*l)->next;

(*l)->next=p;

(*l)=p;

void delete(nodetype **p){

nodetype *q=*p , *r=NULL;

if(q->next==q)

free(q);

*p=NULL;

return;

r=q->next;
q->next=r->next;

free(r);

*p=q;

void task(nodetype **l, int time , int n){

nodetype *p = *l;

while(p!=NULL)

nodetype *f=p->next;

f->d=f->d-time;

if((f->d)<=0)

if(f==*l)

*l=p;

printf("\n**Process %d is Completed**", f->num );

delete(&p);

else

p=p->next;

display((*l)->next);

void display(nodetype *l)

nodetype *temp;

temp=l;

if(l==NULL)

printf("All processes are completed!!!");

else
{

printf("\nthe elements in the linked list are\n");

printf("%d\t",l->d);

temp=temp->next;

while(temp!=l)

printf("%d\t",temp->d);

temp=temp->next;

printf("\n");

You might also like