Ds Programs
Ds Programs
Ds Programs
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<alloc.h>
#define null 0
struct node
{
int info;
struct node *link;
}*start,*last;
void main()
{
int ch,n,m,position,i;
last=null;
clrscr();
while(1)
{
printf("\n1.enter elments \n2.addat starting \n3.add at position
\n4.delete \n5.display \n6.exit\n");
printf("enter ur choice:\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("enter no of elemnts u want to enter:\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter the element");
scanf("%d",&m);
create(m);
}
break;
case 2:
printf("enter the element");
scanf("%d",&m);
addat(m);
break;
case 3:
printf("enter the element");
create(int data)
{
struct node *q,*tmp;
tmp=(struct node *)malloc(sizeof(struct node));
tmp->info=data;
tmp->link=null;
if(last==null)
{
last=tmp;
tmp->link=last;
}
else
{
tmp->link=last->link;
last->link=tmp;
last=tmp;
}}
addat(int data)
tmp->info=data;
q->link=tmp;
if(q==last)
last=tmp;
}
del(int data)
{
struct node *tmp,*q;
if(last->link==last&&last->info==data)
{
tmp=last;
last=null;
free(tmp);
return;
}
q=last->link;
if(q->info==data)
{
tmp=q;
last->link=q->link;
free(tmp);
free(tmp);
printf("element %d is deleted",data);
}
if(q->link->info=data)
{
tmp=q->link;
q->link=last->link;
free(tmp);
last=q;
return;}
printf("element%d is not found",data);
}}
disp()
{
struct node *q;
if(last==null)
{
printf("list is empty");
return;
}q=last->link;
while(q!=last)
{
printf("%d",q->info);
q=q->link;
}
printf("%d",last->info);
}
1.enter elments
2.addat starting
3.add at position
4.delete
1.enter elments
2.addat starting
3.add at position
4.delete
5.display
6.exit
enter ur choice:
2
enter the element1
1.enter elments
2.addat starting
3.add at position
4.delete
5.display
6.exit
enter ur choice:
3
enter the element2
enter the position2
1.enter elments
2.addat starting
3.add at position
4.delete
5.display
6.exit
enter ur choice:
5
12753
1.enter elments
2.addat starting
3.add at position
4.delete
5.display
6.exit
1.enter elments
2.addat starting
3.add at position
4.delete
5.display
6.exit
enter ur choice:
5
1253
1.enter elments
2.addat starting
3.add at position
4.delete
5.display
6.exit
enter ur choice:
6
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
curr = curr->next;
if (pos > 1 )
{
Node *newnode = MakeNode(data);
newnode->prev = curr;
newnode->next = curr->next;
curr->next = newnode;
}
else if (curr==*start)
{
Node *newnode = MakeNode(data);
newnode->prev = curr->prev;
newnode->next = curr;
curr->prev = newnode;
*start = newnode;
}
else
{
Node *newnode = MakeNode(data);
newnode->prev = curr->prev;
newnode->next = curr;
curr->prev->next = newnode;
curr->prev = newnode;
}}}
temp = temp->next;
if (temp==NULL)
puts("Invalid position");
else
{
temp->prev->next = temp->next;
if (temp->next)
temp->next->prev = temp->prev;
free(temp);
}}}
x = x->next;
}}
int menu(void)
{
int choice;
puts("1-Insert data at end");
puts("2-Insert at beginning");
puts("3-Insert at position");
puts("4-Delete by position");
puts("5-Delete by element");
puts("6-Display");
puts("7-Display in reverse");
puts("8-Exit");
printf("Enter choice: ");
scanf("%d", &choice);
while (getchar()!='\n');
return choice;
}
int main(void)
{
Node *start = NULL;
char input[10];
int pos;
while(1)
{
switch(menu())
{
case 1:
Enter choice: 1
Enter numbers, blank line to stop
8
4
2
#include <stdio.h>
#include <stdlib.h>
#include<conio.h>
#define MAX 10
struct lnode
{
int number;
struct lnode *next;
};
int main(void)
{
struct lnode *new = NULL;
int i = 0;
clrscr();
return 0;
}
while(a != NULL){
c = b, b = a, a = a->next;
b->next = c;
}
*n = b;
}
printf("\n");
getch();
}
#include<stdio.h>
#include<conio.h>
#define MAX 11
main()
{
int top,bottom,middle,i,key;
int data[]={31,45,57,88,143,201,204,327,328,414,499};
printf("sorted list:\n");
for (i=0;i<MAX;i++) printf("%d\n",data[i]);
printf("Enter search key: ");
scanf("%d",&key);
sorted list:
31
45
57
88
143
201
204
327
328
414
499
Enter search key: 31
31 was found at location 0
#include<stdio.h>
#include<conio.h>
#include<string.h>
#define MAX 10
char name[MAX][15];
void sort(int n)
{
void main()
{
int n,i,j;
clrscr();
printf("Enter How Many Names : ");
scanf("%d",&n);
if(n>MAX)
printf("\n\t\tArray Size IS Only %d",MAX);
else
{
printf("\n\t\tEnter %d Names :\n",n);
for(i=1;i<=n;i++)
{
printf("\t\t");
scanf("%s",name[i]);
}
sort(n);
printf("\n\n\tSorted List ");
for(i=1;i<=n;i++)
printf("\n\t\t%s",name[i]);
}
getch();
}
Enter 5 Names :
ankur
rinku
nitesh
sarita
garima
Sorted List
ankur
garima
nitesh
#include <stdio.h>
#include <conio.h>
void main()
{
int a[100],n,i;
clrscr();
printf("\t\tHEAP SORT\n");
printf("\nEnter The Number Of Elements\t: ");
scanf("%d",&n);
printf("\nEnter Elements\n");
for(i=0;i< n;++i)
scanf("%d",&a[i]);
heapsort(a,n);
printf("\n\t\t\tSorted List\n");
for(i=0;i< n;++i)
printf("\t%d",a[i]);
getch();
}
Enter Elements
45
12
3
1
78
6
Sorted List
1 3 6 12 45 78
#include<stdio.h>
#include<conio.h>
void insertion(int a[],int n)
{int i,j,x,k;
for(i=1;i<=n-1;i++)
{
j=i;
x=a[i];
while(a[j-1]>x && j>0)
{a[j]=a[j-1];
j=j-1;
}
a[j]=x;
printf("\n\n The array after pass no.%d: ",i);
for(k=0;k<=n-1;k++)
printf("%4d",a[k]);}
}
void main()
{int a[1000],n,i;
clrscr();
printf("\n\nEnter an integer value for total no.s of elements to
be sorted: ");
scanf("%3d",&n);
for(i=0;i<=n-1;i++)
{
printf("\n\nEnter an integer value for element no.%d: ",i+1);
scanf("%4d",&a[i]);
}
insertion(a,n);
printf("\n\n\nFinally sorted array is : ");
for(i=0;i<=n-1;i++)
printf("%4d",a[i]);
}
#include<stdio.h>
#include<conio.h>
}
while(i<=high1)
b[k++]=a[i++];
while(j<=high2)
b[k++] =a[j++];
low1=high2+1;
}
i=low1;
while(k<n)
b[k++] =a[i++];
for(i=0;i<n;i++)
a[i]=b[i];
c=c*2;
}
}
main()
{
int a[20],i,n;
clrscr();
printf("\n\n");
Element 1 : 12
Element 2 : 54
Element 3 : 98
Element 4 : 65
Element 5 : 45
Element 6 : 12
Element 7 : 5
Element 8 : 1
Element 9 : 156
Element 10 : 21
for(k=1;k<=2;k++)
{
for(i=0;i<10;i++)
{
front[i]=-1;
rear[i]=-1;
}
while(first!=-1)
{
p=first;
first=node[first].next;
y=node[p].info;
exp=pow(10,k-1);
j=(y/exp)%10;
q=rear[j];
}
textcolor(YELLOW);
printf("\nDATA AFTER SORTING:");
for(i=0;i<n;i++)
printf("%d\n"a[i]);
}
#include<stdio.h>
#include<conio.h>
main()
{
int a[10],i,n;
clrscr();
Element 1 : 21
Element 2 : 36
Element 3 : 54
Element 4 : 2
Element 5 :10
main()
{
int a[10],b[10],i,n;
clrscr();
Element 1 : 21
Element 2 : 25
Element 3 : 63
Element 5 : 1
Element 6 : 147
Element 7 : 10
Element 8 : 78
Element 9 : 96
Element 10 : 5
Array Before Sorting : 21 25 63 45 1 147 10 78 96 5
Array After Sorting : 1 5 10 21 25 45 63 78 96 147
#include<stdio.h>
#include<conio.h>
main()
{
int a[20],p,q,i,n;
clrscr();
p=0;
q=n-1;
printf("\nArray Befor Sorting : ");
for(i=0;i<n;i++)
if(i< j)
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}}
while(i< j);
a[m] =a[j];
a[j] = v;
return j;
}
Element 1 : 12
Element 2 : 54
Element 3 : 98
Element 4 : 65
Element 5 : 45
Element 6 : 12
Element 7 : 5
Element 8 : 1
Element 9 : 156
Element 10 : 21
#include<stdio.h>
#include<conio.h>
int a[10],i,n,m,c=0;
clrscr();
scanf("%d",&n);
for(i=0;i<=n-1;i++){
scanf("%d",&a[i]);
for(i=0;i<=n-1;i++){
printf(" %d",a[i]);
scanf("%d",&m);
for(i=0;i<=n-1;i++)
if(a[i]==m)
c=1;
break;
else
getch();
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<dos.h>
#include<stdlib.h>
struct node
{
char data[15];
struct node *left,*right;
};
1. Enter
2. Delete
3. Search
4. Display
5. Exit
Enter Your Choice : 1
/****** Data Entry *******
1. Enter
2. Delete
3. Search
4. Display
5. Exit
Enter Your Choice : 4
1. Preorder
2. Inorder
3. Postorder
4. Non Recursion
5. Exit
Enter Your Choice : 1
Lionel Dylan Malcolm Cyril Daniel Jason
1. Preorder
2. Inorder
3. Postorder
4. Non Recursion
5. Exit
Enter Your Choice : 2
Malcolm Cyril Dylan Lionel Jason Daniel
1. Preorder
2. Inorder
3. Postorder
4. Non Recursion
5. Exit
Enter Your Choice : 3
Cyril Malcolm Dylan Lionel Jason Daniel
1. Preorder
2. Inorder
3. Postorder
4. Non Recursion
5. Exit
Enter Your Choice : 5
1. Enter
2. Delete
3. Search
4. Display
5. Exit
Enter Your Choice : 3
1. Enter
2. Delete
3. Search
4. Display
5. Exit
Enter Your Choice : 2
1. Enter
2. Delete
3. Search