Program Code:-
#include<stdio.h>
#include<conio.h>
void main()
{
int arr[100],n,i,elements,pos,temps,temp; //Initializing variables and temp variables
printf("######Implementing Linked List Using Arrays########\n");
puts("how many elements you have to append\n");
scanf("%d",&n);//recieve inputs to insert in to list
for(i=0;i<=n;i++)
{
printf(" the element for position is %d\t",i);
scanf("%d",&arr[i]);//recieve inputs for positions
}
for(i=0;i<=n;i++)
{
printf(" the element for this %d position is %d \n",i,arr[i]); //Printing the elements with positions
}
printf("#######Implementing Search##########################\n");
printf("Enter the element to search \n ");
scanf("%d",&elements);
for(i=0;i<=n;i++)//Loop to search entire array
{
if(arr[i]==elements)
{
printf("this element %d was found at position %d",elements,i);
break;
}
else
{
//Do nothing
}
}
printf("#######Implementing Insertion by shifting##########################\n");
printf("Enter the element to insert \n ");
scanf("%d",&elements);
printf("Enter the position where to insert \n ");
scanf("%d",&pos);
for(i=10;i>=pos-1;i--)
{
arr[i+1]=arr[i];
arr[pos-1]=elements;
}
for(i=0;i<=n;i++)
{
printf(" the element for this %d position is %d \n",i,arr[i]);
}
}
If you want to delete an element in an array then you shift the positions in a way opposite to previous one so the element of an array is deleted .
sorting algorithm will be updated shortly..I believe not in mixing concepts and i follow divide and concur approach have a nice day guys...
#include<stdio.h>
#include<conio.h>
void main()
{
int arr[100],n,i,elements,pos,temps,temp; //Initializing variables and temp variables
printf("######Implementing Linked List Using Arrays########\n");
puts("how many elements you have to append\n");
scanf("%d",&n);//recieve inputs to insert in to list
for(i=0;i<=n;i++)
{
printf(" the element for position is %d\t",i);
scanf("%d",&arr[i]);//recieve inputs for positions
}
for(i=0;i<=n;i++)
{
printf(" the element for this %d position is %d \n",i,arr[i]); //Printing the elements with positions
}
printf("#######Implementing Search##########################\n");
printf("Enter the element to search \n ");
scanf("%d",&elements);
for(i=0;i<=n;i++)//Loop to search entire array
{
if(arr[i]==elements)
{
printf("this element %d was found at position %d",elements,i);
break;
}
else
{
//Do nothing
}
}
printf("#######Implementing Insertion by shifting##########################\n");
printf("Enter the element to insert \n ");
scanf("%d",&elements);
printf("Enter the position where to insert \n ");
scanf("%d",&pos);
for(i=10;i>=pos-1;i--)
{
arr[i+1]=arr[i];
arr[pos-1]=elements;
}
for(i=0;i<=n;i++)
{
printf(" the element for this %d position is %d \n",i,arr[i]);
}
}
If you want to delete an element in an array then you shift the positions in a way opposite to previous one so the element of an array is deleted .
sorting algorithm will be updated shortly..I believe not in mixing concepts and i follow divide and concur approach have a nice day guys...
Output:-
ReplyDeleteC:\Users\BlackMafiaBoyz\Desktop\CDataStructure>out.exe
######Implementing Linked List Using Arrays########
how many elements you have to append
3
the element for position is 0 1
the element for position is 1 2
the element for position is 2 3
the element for position is 3 4
the element for this 0 position is 1
the element for this 1 position is 2
the element for this 2 position is 3
the element for this 3 position is 4
#######Implementing Search##########################
Enter the element to search
1
this element 1 was found at position 0#######Implementing Insertion by shifting#
#########################
Enter the element to insert
3
Enter the position where to insert
3
the element for this 0 position is 1
the element for this 1 position is 2
the element for this 2 position is 3
the element for this 3 position is 3
C:\Users\BlackMafiaBoyz\Desktop\CDataStructure>