Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
aim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Show more breadcrumbs
Martin Mareš
aim
Commits
8c246e53
Commit
8c246e53
authored
11 years ago
by
Ladislav Laska
Committed by
Ladislav Láska
10 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Lepsi generator sekvenci pro aim-sort.
parent
4c423c33
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
aim-sort/Makefile
+1
-1
1 addition, 1 deletion
aim-sort/Makefile
aim-sort/seq-gen.c
+63
-0
63 additions, 0 deletions
aim-sort/seq-gen.c
with
64 additions
and
1 deletion
aim-sort/Makefile
+
1
−
1
View file @
8c246e53
...
...
@@ -17,7 +17,7 @@ ITERS=20
all
:
aim-opt aim-dbg
random
:
random
.c
seq-gen
:
seq-gen
.c
$(
CC
)
$(
OPTCFLAGS
)
-o
$@
$^
$(
LDFLAGS
)
aim-opt
:
aim-run.c exercise.c
...
...
This diff is collapsed.
Click to expand it.
aim-sort/seq-gen.c
0 → 100644
+
63
−
0
View file @
8c246e53
#include
<stdio.h>
#include
<assert.h>
#include
<stdlib.h>
#include
<string.h>
#define swap(a,b) do { __typeof(a) t = a; a = b; b = t; } while (0);
void
qs
(
int
*
seq
,
int
l
,
int
r
){
if
(
l
<
r
){
int
p
=
l
;
for
(
int
i
=
l
+
1
;
i
<
r
;
i
++
){
if
(
seq
[
i
]
<
seq
[
l
]){
p
++
;
swap
(
seq
[
i
],
seq
[
p
]);
}
}
swap
(
seq
[
l
],
seq
[
p
]);
qs
(
seq
,
l
,
p
);
qs
(
seq
,
p
+
1
,
r
);
}
}
int
main
(
int
argc
,
char
**
argv
)
{
if
(
argc
<
3
||
argc
>
4
)
{
fprintf
(
stderr
,
"Usage: [random|sorted|reverse] %s count repeat
\n
"
,
argv
[
0
]);
exit
(
1
);
}
int
count
=
atoi
(
argv
[
2
]);
int
repeat
=
1
;
char
*
type
=
argv
[
1
];
if
(
argc
==
4
)
repeat
=
atoi
(
argv
[
3
]);
if
(
count
<=
0
)
{
fprintf
(
stderr
,
"Invalid count given: %i
\n
"
,
count
);
exit
(
2
);
}
if
(
repeat
<
1
)
{
fprintf
(
stderr
,
"Invalid repeat given: %i
\n
"
,
repeat
);
exit
(
2
);
}
int
*
data
=
malloc
(
sizeof
(
int
)
*
count
);
fprintf
(
stderr
,
"Generating %i %s sequences, each of size %i
\n
"
,
repeat
,
type
,
count
);
for
(
int
i
=
0
;
i
<
count
;
i
++
)
{
data
[
i
]
=
rand
();
}
if
((
!
strcmp
(
type
,
"sorted"
))
||
(
!
strcmp
(
type
,
"reverse"
)))
{
qs
(
data
,
0
,
count
);
if
(
!
strcmp
(
type
,
"reverse"
))
{
for
(
int
i
=
0
;
i
<
count
/
2
;
i
++
)
{
swap
(
data
[
i
],
data
[
count
-
i
-
1
]);
}
}
}
/* First, generate a random sequence */
printf
(
"%i
\n
"
,
count
*
repeat
);
for
(
int
r
=
0
;
r
<
repeat
;
r
++
)
{
for
(
int
i
=
0
;
i
<
count
;
i
++
)
{
printf
(
"%i
\n
"
,
data
[
i
]);
}
}
}
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