PLplot
5.9.9
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
istack.c
Go to the documentation of this file.
1
//--------------------------------------------------------------------------
2
//
3
// File: istack.c
4
//
5
// Created: 06/06/2001
6
//
7
// Author: Pavel Sakov
8
// CSIRO Marine Research
9
//
10
// Purpose: Handling stack of integers
11
//
12
// Description: None
13
//
14
// Revisions: None
15
//
16
//--------------------------------------------------------------------------
17
18
#define STACK_NSTART 50
19
#define STACK_NINC 50
20
21
#include <stdlib.h>
22
#include <string.h>
23
#include "
istack.h
"
24
25
static
void
istack_init
(
istack
* s )
26
{
27
s->
n
= 0;
28
s->
nallocated
=
STACK_NSTART
;
29
s->
v
= malloc(
STACK_NSTART
*
sizeof
(
int
) );
30
}
31
32
istack
*
istack_create
()
33
{
34
istack
* s = malloc(
sizeof
(
istack
) );
35
36
istack_init
( s );
37
return
s;
38
}
39
40
void
istack_reset
(
istack
* s )
41
{
42
s->
n
= 0;
43
}
44
45
int
istack_contains
(
istack
* s,
int
v )
46
{
47
int
i;
48
49
for
( i = 0; i < s->
n
; ++i )
50
if
( s->
v
[i] == v )
51
return
1;
52
return
0;
53
}
54
55
void
istack_push
(
istack
* s,
int
v )
56
{
57
if
( s->
n
== s->
nallocated
)
58
{
59
s->
v
= realloc( s->
v
, (
size_t
) ( s->
nallocated
+
STACK_NINC
) * sizeof (
int
) );
60
s->
nallocated
+=
STACK_NINC
;
61
}
62
63
s->
v
[s->
n
] = v;
64
s->
n
++;
65
}
66
67
int
istack_pop
(
istack
* s )
68
{
69
s->
n
--;
70
return
s->
v
[s->
n
];
71
}
72
73
void
istack_destroy
(
istack
* s )
74
{
75
if
( s != NULL )
76
{
77
free( s->
v
);
78
free( s );
79
}
80
}
lib
nn
istack.c
Generated on Sat Sep 14 2013 05:04:13 for PLplot by
1.8.4