0% found this document useful (0 votes)
71 views

Program Code - (Scan Algorithm With Decreasing Direction)

The document describes a scan algorithm with decreasing direction to sort data on either side of a disk head position. It includes functions to: 1) divide an array around the disk head position into left and right subarrays; 2) apply the scan sorting algorithm by scanning from high to low indices in the left array and low to high in the right array; and 3) initially sort the input array before division. The main function gets input, calls the sorting and division functions, and outputs the resulting scanned order.

Uploaded by

t1915095
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views

Program Code - (Scan Algorithm With Decreasing Direction)

The document describes a scan algorithm with decreasing direction to sort data on either side of a disk head position. It includes functions to: 1) divide an array around the disk head position into left and right subarrays; 2) apply the scan sorting algorithm by scanning from high to low indices in the left array and low to high in the right array; and 3) initially sort the input array before division. The main function gets input, calls the sorting and division functions, and outputs the resulting scanned order.

Uploaded by

t1915095
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Program code- (Scan Algorithm with decreasing direction)

#include<stdio.h>
#include<conio.h>

void scan_algorithm(int left[], int right[], int count, int limit)


{
int arr[20];
int x = count - 1, y = count + 1, c = 0, d = 0, j;
while(x > -1)
{
printf("\nX:\t%d", x);
printf("\nLeft[X]:\t%d", left[x]);
arr[d] = left[x];
x--;
d++;
}
arr[d] = 0;
while(y < limit + 1)
{
arr[y] = right[c];
c++;
y++;
}
printf("\n\nScanning Order:");
for(j = 0; j < limit + 1; j++)
{
printf("\n%d", arr[j]);
}
}

void division(int elements[], int limit, int disk_head)


{
int count = 0, p, q, m, x;
int left[20], right[20];
for(count = 0; count < limit; count++)
{
if(elements[count] > disk_head)
{
printf("\nBreak Position:\t%d\n", elements[count]);
break;
}
}
printf("\nValue:\t%d\n", count);
q = 1;
p = 0;
m = limit;
left[0] = elements[0];
printf("\nElement value:\t%d",elements[0]);
printf("\nLeft:\t%d", left[0]);
while(q < count)
{
printf("\nElement value:\t%d" , elements[q]);
left[q] = elements[q];
printf("\nLeft:\t%d", left[q]);
q++;
}
x = count;
while(x < m)
{
right[p] = elements[x];
printf("\nElement value:\t%d", elements[x]);
printf("\nRight:\t%d", right[p]);
p++;
x++;
}
scan_algorithm(left, right, count, limit);
}

void sorting(int elements[], int limit)


{
int location, count, j, temp, small;
for(count = 0; count < limit - 1; count++)
{
small = elements[count];
location = count;
for(j = count + 1; j < limit; j++)
{
if(small > elements[j])
{
small = elements[j];
location = j;
}
}
temp = elements[location];
elements[location] = elements[count];
elements[count] = temp;
}
}

int main()
{
int count, disk_head, elements[20], limit;
printf("Enter total number of locations in queue:\t");
scanf("%d", &limit);
printf("\nEnter position of disk head:\t");
scanf("%d", &disk_head);
printf("\nEnter elements of disk head queue\n");
for(count = 0; count < limit; count++)
{
printf("Element[%d]:\t", count + 1);
scanf("%d", &elements[count]);
}
sorting(elements, limit);
division(elements, limit, disk_head);
getch();
return 0;
}
Output-

You might also like