Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PfN-Projekt
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Löding, Donna
PfN-Projekt
Commits
b101ac4d
Commit
b101ac4d
authored
3 years ago
by
Löding, Donna
Browse files
Options
Downloads
Patches
Plain Diff
Delete distribution.c
parent
9a03c2b0
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
distribution.c
+0
-94
0 additions, 94 deletions
distribution.c
with
0 additions
and
94 deletions
distribution.c
deleted
100644 → 0
+
0
−
94
View file @
9a03c2b0
#include
<stdio.h>
#include
<stdlib.h>
#include
<stddef.h>
#include
<ctype.h>
#include
<string.h>
#include
<assert.h>
#include
"distribution.h"
unsigned
long
distribution_update
(
unsigned
long
*
dist
,
const
char
*
progname
,
const
char
*
filename
)
{
unsigned
int
currentCharacter
;
unsigned
long
filesize
=
0
;
FILE
*
file
=
fopen
(
filename
,
"rb"
);
if
(
file
==
NULL
)
{
fprintf
(
stderr
,
"%s cannot open file (dist) %s
\n
"
,
progname
,
filename
);
exit
(
EXIT_FAILURE
);
}
while
((
currentCharacter
=
fgetc
(
file
))
!=
EOF
)
{
dist
[
currentCharacter
]
++
;
filesize
++
;
}
fclose
(
file
);
return
filesize
;
}
/*void distribution_show(const unsigned long *dist)
{
int i;
for (i = 0; i <= UCHAR_MAX; i++)
{
if (dist[i] > 0)
{
if (iscntrl(i))
printf("\\%d: %lu\n",i,dist[i]);
else
printf("%c: %lu\n",(char) i,dist[i]);
}
}
}*/
const
unsigned
long
*
binarysearch
(
const
unsigned
long
*
leftptr
,
const
unsigned
long
*
rightptr
,
unsigned
long
key
)
{
const
unsigned
long
*
midptr
;
while
(
leftptr
<=
rightptr
)
{
midptr
=
leftptr
+
(
unsigned
long
)
(
rightptr
-
leftptr
)
/
2
;
if
(
key
<
*
midptr
)
{
rightptr
=
midptr
-
1
;
}
else
{
if
(
key
>
*
midptr
)
{
leftptr
=
midptr
+
1
;
}
else
if
(
key
==
*
midptr
)
{
while
(
*
(
midptr
-
1
)
==
key
)
{
midptr
--
;
}
return
midptr
;
}
}
}
if
(
key
<
*
midptr
)
return
midptr
;
return
NULL
;
}
int
main
(
void
)
{
const
unsigned
long
array1
[]
=
{
10
,
13
,
15
,
15
,
17
,
18
,
20
,
22
,
25
,
27
};
const
unsigned
long
array2
[]
=
{
10
,
13
,
15
,
15
,
17
,
18
,
18
,
18
,
20
,
22
};
const
unsigned
long
array3
[]
=
{
20
,
22
,
25
,
27
};
printf
(
"Adresse: %lu
\n
"
,
(
unsigned
long
)
&
array2
[
5
]);
const
unsigned
long
*
element1
=
binarysearch
(
&
array1
[
0
],
&
array1
[
9
],
18
);
const
unsigned
long
*
element2
=
binarysearch
(
&
array2
[
0
],
&
array2
[
9
],
18
);
const
unsigned
long
*
element3
=
binarysearch
(
&
array3
[
0
],
&
array3
[
3
],
18
);
printf
(
"element array 1: %lu
\n
"
,
*
element1
);
printf
(
"element array 2: %lu
\n
Adresse: %lu
\n
"
,
*
element2
,
(
unsigned
long
)
element2
);
printf
(
"element array 3: %lu
\n
"
,
*
element3
);
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