Data Structure
Data Structure
Else
Step 3: Stop.
Algorithm for Inserting A Node at Desire Location
Step 4: If (LOC=1)
Step 7: If (PTR=NULL)
Step 1: If (FIRST=NULL)
Else
Step8: Stop.
Program For Fibonacci Serise
#include "stdio.h"
#include "conio.h"
void main()
int a,b,c,i,n;
clrscr();
a=0;
b=1;
scanf("%d",&n);
printf("\nFIBONACCI SERIES\n");
printf(" %d %d",a,b);
for(i=0;i<n;i++)
c=a+b;
a=b;
b=c;
printf(" %d",c);
getch();
Output:
#include<stdio.h>
void stringCopy(char[],char[]);
int main(){
char str1[100],str2[100];
scanf("%s",str1);
stringCopy(str1,str2);
return 0;
int i=0;
while(str1[i]!='5'){
str2[i] = str1[i];
i++;
str2[i]='5';
Output:
After copying:abc
Program For Push and Pop Operation
# include<stdio.h>
# include<malloc.h>
struct node
int info;
} *top=NULL;
main()
int choice;
while(1)
printf("1.Push\n");
printf("2.Pop\n");
printf("3.Display\n");
printf("4.Quit\n");
scanf("%d", &choice);
switch(choice)
case 1:
push();
break;
case 2:
pop();
break;
case 3:
display();
break;
case 4:
exit(1);
default :
printf("Wrong choice\n");
push()
int pushed_item;
scanf("%d",&pushed_item);
temp->info=pushed_item;
temp->link=top;
top=temp;
}/*End of push()*/
pop()
if(top == NULL)
printf("Stack is empty\n");
else
temp=top;
top=top->link;
free(temp);
}/*End of pop()*/
display()
ptr=top;
if(top==NULL)
printf("Stack is empty\n");
else
while(ptr!= NULL)
printf("%d\n",ptr->info);
ptr = ptr->link;
}
Compare String
#include<stdio.h>
int stringCompare(char[],char[]);
int main(){
char str1[100],str2[100];
int compare;
scanf("%s",str1);
scanf("%s",str2);
compare = stringCompare(str1,str2);
if(compare == 1)
else
return 0;
int i=0,flag=0;
if(str1[i]!=str2[i]){
flag=1;
break;
i++;
}
if (flag==0 && str1[i]=='10' && str2[i]=='10')
return 1;
else
return 0;
Output:
#include<stdio.h>
main()
scanf("%d",&number);
scanf("%d",&array[c]);
scanf("%d",&search);
break;
if ( c == number )
return 0;
}
Bubble sort
#include <stdio.h>
int main()
scanf("%ld", &n);
scanf("%ld", &array[c]);
bubble_sort(array, n);
printf("%ld\n", array[c]);
return 0;
long c, d, t;
t = list[d];
list[d] = list[d+1];
list[d+1]= t;
}
Program:- To inserted an element in an array
#include<stdio.h>
#include<conio.h>
void main()
int a[100],k,item,n,j,I;
clrscr();
scanf(“%d,&n”);
for(i=0;i<n;i++)
scanf(“%d,&a[i]”);
scanf(“%d,&k”);
scanf(“%d,&item”);
j=n-1;
while(j>=k)
a[j+1]=a[j];
j--;
a[k]=item;
n++;
for(i=0;i<n;i++)
printf(“%4d,a[i]”);
getch();
11 22 33 44 55
66
11 22 33 66 44 55