-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathYoungTableaus.cpp
More file actions
81 lines (67 loc) · 1.33 KB
/
Copy pathYoungTableaus.cpp
File metadata and controls
81 lines (67 loc) · 1.33 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
#include<iostream>
#include<cmath>
#include<algorithm>
#define INF 65535
void youngify(int i, int j);
int young[100][100] ;
int arr[100];
int m , n ;
using namespace std ;
int extract_min(){
int x = young[0][0] ;
young[0][0] = INT_MAX;
youngify( 0, 0);
}
void youngify(int i, int j)
{
int downVal = (i+1 < m)? young[i+1][j]: INF;
int rightVal = (j+1 < n)? young[i][j+1]: INF;
if (downVal==INF && rightVal==INF)
return;
if (downVal < rightVal)
{
young[i][j] = downVal;
young[i+1][j] = INF;
youngify(i+1, j);
}
else
{
young[i][j] = rightVal;
young[i][j+1] = INF;
youngify(i, j+1);
}
}
void initialize(){
int i , j, k;
k = m*n-1 ;
for(i = m-1; i>=0 ; i--){
for(j = n-1; j>=0; j--){
young[j][i] = arr[k--];
}
}
}
// Insertion
void insert_key(int i, int j){
}
int main()
{
int i, j ;
cin >> m >> n ;
for(i = 0 ; i<m*n ; i++){
cin >> arr[i];
}
sort(arr, arr+m*n) ;
cout << "After sorting\n" ;
for(i = 0 ; i<m*n ; i++)
cout << arr[i] << " ";
cout << endl ;
initialize();
youngify(m,n);
for(i = 0 ;i<m ; i++){
for(j = 0 ;j<n ; j++){
cout << young[i][j] << " " ;
}
cout <<endl ;
}
return 0 ;
}