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
11 changes: 11 additions & 0 deletions Arrays/1D Array/solution.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include<stdio.h>
main()
{
int n,i,m,j,a[100];

scanf("%d",&n);
for(i=0;i<n;++i)
scanf("%d",&a[i]);
for(i=n-1;i>=0;--i)
printf("%d\n",a[i]);
}
17 changes: 17 additions & 0 deletions Arrays/Multi-D Array/solution.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include<stdio.h>
main()
{
int n,i,m,j,a[10][10];

scanf("%d%d",&n,&m);
for(i=0;i<n;++i)
for(j=0;j<m;++j)
scanf("%d",&a[i][j]);
for(i=0;i<m;++i)
{


for(j=0;j<n;++j)
printf("%d ",a[j][i]);
printf("\n");
}}
20 changes: 20 additions & 0 deletions Hash Tables/Hash Tables/solution.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include<stdio.h>
#include<string.h>
main()
{
long int n,r,i,q,a[10000];
char s[26],h[101][26];
scanf("%ld",&n);
for(i=0;i<n;++i)
{
scanf("%ld%s",&r,s);
strcpy(h[r%101],s);
}
scanf("%ld",&q);
for(i=0;i<q;++i)

scanf("%ld",&a[i]);
for(i=0;i<q;++i)
puts(h[a[i]%101]);

}
60 changes: 60 additions & 0 deletions Queues/Queues/solution.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

#include<stdio.h>
main()
{
int i,n,h,a[100],e,j=-1,k=-1,r[100][2],f=0,fl=0;
char p;
scanf("%d",&n);
for(i=0;i<n;++i)
{
while((getchar())!='\n');

scanf("%c",&p);
if(p=='E')
{
scanf("%d",&e);

a[++j]=e;
r[++k][0]=j-f+1;
r[k][1]=-2;
fl=0;

}
else if(p=='D')
{
if(j!=-1 && fl!=1)
{
if(j==f)
fl=1;
h=a[f++];
r[++k][0]=h;
r[k][1]=j-f+1;

}
else{
r[++k][0]=1;
r[k][1]=0;

}
}


}


for(int i=0;i<n;++i)
{

for(int m=0;m<2;++m)
{
if(r[i][m]==-2)
break;
else
printf("%d ",r[i][m]);
}
printf("\n");
}



}
55 changes: 55 additions & 0 deletions Stacks/Stacks/solution.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

#include<stdio.h>
main()
{
int i,n,h,a[100],e,j=-1,r[10000],k=0,m=0;
char p;
scanf("%d",&n);
for(i=0;i<n;++i)
{
while((getchar())!='\n');

scanf("%c",&p);
if(p=='2')
{
scanf("%d",&e);

a[++j]=e;


}
else if(p=='1')
{
++m;
if(j!=-1)
{

h=a[j--];
r[k++]=h;


}
else{
r[k++]=-1;

}
}


}


for(int i=0;i<m;++i)
{

if(r[i]==-1)
printf("No food");
else
printf("%d ",r[i]);

printf("\n");
}



}
81 changes: 81 additions & 0 deletions Trees/Binary Search Tree/solution.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#include<stdio.h>
#include<stdlib.h>
struct bi
{
struct bi *l,*r;
int v;
}*b,*root,*p,*ptr;


void cre(int h)
{
b=(struct bi*)malloc(sizeof(struct bi));
b->r=b->l=NULL;
b->v=h;
p=root;
while(p!=NULL)
{
ptr=p;
if(p->v>h)
p=p->l;
else
p=p->r;

}
if(ptr->l==NULL && ptr->v>h)
ptr->l=b;
else if(ptr->r==NULL && ptr->v<h)
ptr->r=b;
}

void pre(struct bi *k)
{
if(k==NULL)
return;

printf("%d\n",k->v);
pre(k->l);

pre(k->r);

}
void trav(int q)
{
p=root;
while(p!=NULL)
{
if(p->v==q)
{ pre(p);
break;}
else if(p->v>q)
p=p->l;
else
p=p->r;

}


}



main()
{
int n,l,q;
scanf("%d",&n);
root=(struct bi*)malloc(sizeof(struct bi));
root->l=root->r=NULL;
root->v=-1;
scanf("%d",&l);
root->v=l;
for(int i=0;i<n-1;++i)
{
scanf("%d",&l);
cre(l);
}
scanf("%d",&q);
trav(q);

}