-
Notifications
You must be signed in to change notification settings - Fork 0
/
array.c
90 lines (77 loc) · 2.1 KB
/
array.c
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
/*
* File: array.c
* - implementation of array datatype
*
* Author: Hermann Stamm-Wilbrandt
* Institut fuer Informatik III
* Roemerstr. 164
* Bonn University
* D-53117 Bonn
* Germany
* email: [email protected]
* phone: 0228-550-260 internal: x260 or x28, Fax: 0228-550-382
*
* For my safety:
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#include "array.h"
/*----------------------------------------------------------------------------*/
num *new_array(num k)
{
num *p=(num *) MALLOC(k*sizeof(num));
if (p==NULL)
err_handler(1,"out of memory during array allocation");
p[0]=0;
return p;
}
void delete_array(num *A) { FREE(A); }
void init_array(num low, num high, num x, num *A)
{ num i; for(i=low; i<=high; i++) A[i]=x; }
double *new_array_of_double(num k)
{
double *p=(double *) MALLOC(k*sizeof(double));
if (p==NULL)
err_handler(1,"out of memory during array allocation");
p[0]=0;
return p;
}
void delete_array_of_double(double *A) { FREE(A); }
void print_array(num low, num high, num *A)
{
num i;
for(i=low; i<=high; i++) printf("+---");
printf("+\n");
for(i=low; i<=high; i++) printf("|%3d",i);
printf("|\n");
for(i=low; i<=high; i++) printf("+---");
printf("+\n");
for(i=low; i<=high; i++) printf("|%3d",A[i]);
printf("|\n");
for(i=low; i<=high; i++) printf("+---");
printf("+\n");
}
void print_array_of_double(num low, num high, double *A)
{
num i;
for(i=low; i<=high; i++) printf("+------");
printf("+\n");
for(i=low; i<=high; i++) printf("|%6d",i);
printf("|\n");
for(i=low; i<=high; i++) printf("+------");
printf("+\n");
for(i=low; i<=high; i++) printf("|%6.2f",A[i]);
printf("|\n");
for(i=low; i<=high; i++) printf("+------");
printf("+\n");
}
void USE2()
{
(void) new_array(0);
delete_array(0);
(void) new_array_of_double(0);
delete_array_of_double(0);
USE2();
}