Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deepcodr patch 3 #11

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
62 changes: 62 additions & 0 deletions mergesort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//deepak s. patil
//merge sort

#include<stdio.h>
int mergepass(int A[],int N,int L,int B[]);
int mergesort(int A[],int N);
int merge(int A[],int L,int lb,int m[],int k,int C,int B[],int LB);


int main()
{
int N;

printf("enter the size of array :\n");
scanf("%d",&N);

int a[N],b[N],i,j,L;

return 0;
}
int mergesort(int A[],int N)
{
int L,i,B[N];
L=0;
for(i=0;i<N;i++)
{
mergepass(A,N,L,B);
mergepass(B,N,2*L,A);
L=4*L;
}
return 0;
}
int mergepass(int A[],int N,int L,int B[])
{
int q,s,r,j,lb;

q=(int)(N/(2*L));
s=2*L*q;
r=N-s;

for(j=0;j<N;j++)
{
lb=1+(2*j-2)*L;
merge(A,L,lb,A,L,lb+L,B,lb);
}
if(r<=L)
{
for(j=0;j<r;j++)
{
B[s+j]=A[s+j];
}
}
else
{
merge(A,L,s+1,A,r,L+s+1,B,s+1);
}
return 0;
}
int merge(int A[],int L,int lb,int m[],int k,int C,int B[],int LB)
{

}
100 changes: 100 additions & 0 deletions queue.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#include<stdio.h>
//queue
static int front=-1;
static int rear=-1;

void enque(int queue[],int size)
{
if(rear==size-1)
{
printf("Queue Overflow\n");
return;
}
else if(front==-1)
{
int item;
printf("Enter item\n");
scanf("%d",&item);

front++;
rear++;
queue[rear]=item;
printf("%d inserted successfully\n",item);
}
else
{
int item;
printf("Enter item\n");
scanf("%d",&item);

rear++;
queue[rear]=item;
printf("%d inserted successfully\n",item);
}
return;
}

void deque(int queue[])
{
if(front==-1 || front>rear)
{
printf("Queue Underflow\n");
return;
}
else
{
int item=queue[front];
front++;
printf("%d deque successful\n",item);
}
return;
}

void display(int queue[])
{
if(front==-1)
{
printf("Queue Empty\n");
return;
}
for(int i=front;i<=rear;i++)
{
printf("%d\t",queue[i]);
}
printf("\n");
}

int main()
{
int size;

printf("Enter size of queue\n");
scanf("%d",&size);

int queue[size];

int ch;
do{
printf("Enter Your choice\n");
printf("1.Enque\n2.Deque\n3.Display\n4.Exit\n");
scanf("%d",&ch);

switch(ch)
{
case 1:
enque(queue,size);
break;
case 2:
deque(queue);
break;
case 3:
display(queue);
break;
case 4:
break;
default:
printf("Enter a valid choice\n");
}
}while(ch!=4);
return 0;
}