I'm sure that I can solve any doubts in Turbo C ,Graphics Programing ,Mouse, Hardware Programming ,File System ,Interrupts, BIOS handling , TSR Programming , General Concepts in C Language, handling inline Assembly statements
I need you to please, teach me supposing i want to input these data into an array[5][2] without typing them in but using a simple code that asks me to input them. say this one:
int n=0;
int next;
while(scanf("%d", &next)==2){
array[][2]= next;
}
will this programme help me to keep inputing the values i need i mean exactly entering datas into the array by me being prompted?
Also, i recently read about the insertion sort algorithm.
sort(array, n , value)
what value am in supposed to enter into the sort, since i want to sort an entire array. using the array declared blow pls help me out by trying the insertion sort on the array.
int array[5]= {3,8,1,4,9};
here is the insertion code:
sort(int array[], int n, int value){
int pos;
for(pos=n; pos>0&&value<array[pos-1]; pos--)
{
[pos]= [pos-1];
[pos] = value;
}
pls write a small code that will use the insertion sort method to sort the array for me pls. i want to see how to use this insertion sort cuz am so confused about the value parameter.
can i also sort a 2x2 array? if yes, pls a small very minute code pls.use the shell sorting method pls.i just need to know how to use the various sorting method i have learnt. so far, the one i can properly use is the bubble sort.
Hope you will help me pls.
Henry
Answer HI Dear Henry !
Nice to meet you back with your question !
Of course its simple to read input to an two dimensional array lemme give you a code excerpt , will absolutely fit to the given two dimensional array
for( i = 0 ; i < 2 ; i++)
{
for ( j = 0 ;j < 4 ; j++)
{
scanf("%d" , &a[i][j]);
}
}
Presenting you a simple code to perform insertion sort !
void insertionSort(int numbers[], int array_size)
{
int i, j, index;
for (i=1; i < array_size; i++)
{
index = numbers[i];
j = i;
while ((j > 0) && (numbers[j-1] > index))
{
numbers[j] = numbers[j-1];
j = j - 1;
}
numbers[j] = index;
}
}
We can sort a two dimensional , but we should be clear that the array should be sorted in row major order or in column major order besides memorizing the algorithm its really meaningful to understand the algorithm