Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
prog_exam_05
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
boris.stefanov
prog_exam_05
Commits
8e7bbea2
Commit
8e7bbea2
authored
3 years ago
by
Boris Stefanovic
Browse files
Options
Downloads
Patches
Plain Diff
save
parent
e782027f
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ex4/ex4.c
+100
-0
100 additions, 0 deletions
ex4/ex4.c
with
100 additions
and
0 deletions
ex4/ex4.c
+
100
−
0
View file @
8e7bbea2
#include
<stdbool.h>
#include
<stdio.h>
#include
<stdlib.h>
#define QUAD 4
#define SIDE 16
typedef
struct
node
{
int
value
;
struct
node
*
children
[
QUAD
];
}
node_t
;
node_t
*
node_create
(
const
int
value
)
{
node_t
*
node
=
malloc
(
sizeof
(
node_t
));
node
->
value
=
value
;
for
(
int
i
=
0
;
i
<
QUAD
;
++
i
)
node
->
children
[
i
]
=
NULL
;
return
node
;
}
bool
is_leaf
(
node_t
*
node
)
{
return
node
->
children
[
0
]
=
NULL
;
}
void
mat_to_qtr
(
const
int
**
a
,
const
int
x1
,
const
int
x2
,
const
int
y1
,
const
int
y2
,
node_t
*
node
)
{
if
(
x2
-
x1
!=
y2
-
y1
)
printf
(
"PROBLEM!
\n
"
);
const
int
size
=
x2
-
x1
;
switch
(
size
)
{
case
1
:
node
->
value
=
a
[
y1
][
x1
];
return
;
default:
for
(
int
i
=
0
;
i
<
QUAD
;
++
i
)
node
->
children
[
i
]
=
node_create
(
0
);
mat_to_qtr
(
a
,
x1
,
x1
+
(
x2
-
x1
)
/
2
,
y1
,
y1
+
(
y2
-
y1
)
/
2
,
node
->
children
[
0
]);
mat_to_qtr
(
a
,
x1
+
(
x2
-
x1
)
/
2
,
x2
,
y1
,
y1
+
(
y2
-
y1
)
/
2
,
node
->
children
[
1
]);
mat_to_qtr
(
a
,
x1
,
x1
+
(
x2
-
x1
)
/
2
,
y1
+
(
y2
-
y1
)
/
2
,
y2
,
node
->
children
[
2
]);
mat_to_qtr
(
a
,
x1
+
(
x2
-
x1
)
/
2
,
x2
,
y1
,
y1
+
(
y2
-
y1
)
/
2
,
node
->
children
[
3
]);
}
}
node_t
*
qtr_copy
(
node_t
*
node
)
{
if
(
node
==
NULL
)
return
NULL
;
node_t
*
dest
=
malloc
(
sizeof
(
node_t
));
dest
->
value
=
node
->
value
;
for
(
int
i
=
0
;
i
<
QUAD
;
++
i
)
{
dest
->
children
[
i
]
=
qtr_copy
(
node
->
children
[
i
]);
}
return
dest
;
}
const
int
initlist
[]
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
3
,
3
,
3
,
3
,
0
,
0
,
7
,
7
,
7
,
7
,
0
,
0
,
11
,
11
,
11
,
0
,
3
,
0
,
0
,
0
,
0
,
0
,
7
,
0
,
0
,
0
,
0
,
0
,
11
,
0
,
0
,
0
,
3
,
3
,
3
,
0
,
0
,
0
,
7
,
7
,
7
,
0
,
0
,
0
,
11
,
11
,
11
,
0
,
3
,
0
,
0
,
0
,
0
,
0
,
7
,
0
,
0
,
0
,
0
,
0
,
11
,
0
,
0
,
0
,
3
,
0
,
0
,
0
,
0
,
0
,
7
,
7
,
7
,
7
,
0
,
0
,
11
,
11
,
11
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
3
,
3
,
3
,
3
,
0
,
0
,
7
,
7
,
7
,
7
,
0
,
0
,
11
,
11
,
11
,
0
,
3
,
0
,
0
,
0
,
0
,
0
,
7
,
0
,
0
,
0
,
0
,
0
,
11
,
0
,
0
,
0
,
3
,
3
,
3
,
0
,
0
,
0
,
7
,
7
,
7
,
0
,
0
,
0
,
11
,
11
,
11
,
0
,
3
,
0
,
0
,
0
,
0
,
0
,
7
,
0
,
0
,
0
,
0
,
0
,
11
,
0
,
0
,
0
,
3
,
0
,
0
,
0
,
0
,
0
,
7
,
7
,
7
,
7
,
0
,
0
,
11
,
11
,
11
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
3
,
3
,
3
,
3
,
0
,
0
,
7
,
7
,
7
,
7
,
0
,
0
,
11
,
11
,
11
};
int
main
()
{
int
a
[
16
][
16
];
for
(
int
y
=
0
;
y
<
16
;
++
y
)
for
(
int
x
=
0
;
x
<
16
;
++
x
)
a
[
y
][
x
]
=
initlist
[
16
*
y
+
x
];
node_t
*
root
=
malloc
(
sizeof
(
node_t
));
mat_to_qtr
(
a
,
0
,
16
,
0
,
16
,
root
);
node_t
*
copy
=
qtr_copy
(
root
);
return
EXIT_SUCCESS
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment