Linked List Programs
Linked List Programs
#include<stdio.h>
#include<conio.h>
void main(){
int list[20],size,i,sElement;
printf("Enter the required list size: ");
scanf("%d",&size);
printf("Enter any %d numbers: ",size);
for(i = 0; i < size; i++)
scanf("%d",&list[i]);
printf("Enter the element you want to Search: ");
scanf("%d",&sElement);
// Linear Search Logic
for(i = 0; i < size; i++)
{
if(sElement == list[i])
{
printf("Searched Element is found at %d index", i);
break;
}
}
if(i == size)
printf("Searched element is not found in the list!!!");
getch();
}
Bubble sort
#include<stdio.h>
#include<conio.h>
void main()
{
int array[100],n,i,j,swap;
clrscr();
printf("Enter number of elements n : ");
scanf("%d",&n);
printf("Enter the elements);
for(i=0;i<n;i++)
scanf("%d",&array[i]);
for(i =0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++)
{
if(array[j]>array[j+1])
{
swap=array[j];
array[j]=array[j+1];
array[j+1]=swap;
}
}
}
printf("Sorted Array:n");
for(i=0;i<n;i++)
printf("%d",array[i]);
getch();
}
SELECTION SORT
#include<stdio.h>
#include<conio.h>
void main() {
int array[100], size, i, j, position, temp;
clrscr();
printf("Enter Number of Elements : ");
scanf("%d", &size);
printf("Enter %d Numbers : ", size);
for (i = 0; i < size; i++)
scanf("%d", &array[i]);
for (i = 0; i < (size - 1); i++) {
position = i;
for (j = i + 1; j < size; j++) {
if (array[position] > array[j])
position = j;
}
if (position != i) {
temp = array[i];
array[i] = array[position];
array[position] = temp;
}
}
printf("Sorted list in ascending order:\n");
for (i = 0; i < size; i++)
printf("%d\t", array[i]);
getch();
}
INSERTION SORT
#include<stdio.h>
int main() {
int a[100], n, i, j, element;
printf("\nEnter the total Number of Elements : ");
scanf("%d", &n);
printf("\nEnter the Array Elements : ");
for(i = 0; i < n; i++)
scanf("%d", &a[i]);
for(i = 1; i <= n - 1; i++) {
for(j = i; j > 0 && a[j - 1] > a[j]; j--) {
element = a[j];
a[j] = a[j - 1];
a[j - 1] = element;
}
}
printf("\n Insertion Sort Result : ");
for(i = 0; i < n; i++) {
printf(" %d \t", a[i]);
}
printf("\n");
return 0;
}
REVERSING OF ARRAY IN C
#include<stdio.h>
#include<conio.h>
void main()
{
int n, arr[50], i;
clrscr();
printf("Enter the size of the array: ");
scanf("%d", &n);
printf("Enter the elements: ");
for(i = 0; i < n; i++)
{
scanf("%d", &arr[i]);
}
printf("the array elements are ");
for(i = 0; i <n; i++)
{
printf("%d\t", arr[i]);
}
printf("The Reversed array: ");
for(i = n-1; i < =0; i--)
{
printf("%d\t ", arr[i]);
}
getch();
}