-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14.c
More file actions
106 lines (102 loc) · 2.68 KB
/
14.c
File metadata and controls
106 lines (102 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#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("\nScanning Order:\n");
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("\nLeft:\t%d", left[0]);
while(q < count)
{
printf("\nElement[l] value:\t%d" , elements[q]);
left[q] = elements[q];
printf("\nLeft:\t%d", left[q]);
q++;
printf("\nl:\t%d", q);
}
x = count;
while(x < m)
{
right[p] = elements[x];
printf("\nRight:\t%d", right[p]);
printf("\nElement:\t%d", elements[x]);
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:\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;
}