1 | /* |
---|
2 | * Utilities for handling sets. |
---|
3 | * |
---|
4 | * Copyright (c) 1992, 1993 |
---|
5 | * Regents of the University of California |
---|
6 | * All rights reserved. |
---|
7 | * |
---|
8 | * Use and copying of this software and preparation of derivative works |
---|
9 | * based upon this software are permitted. However, any distribution of |
---|
10 | * this software or derivative works must include the above copyright |
---|
11 | * notice. |
---|
12 | * |
---|
13 | * This software is made available AS IS, and neither the Electronics |
---|
14 | * Research Laboratory or the Universify of California make any |
---|
15 | * warranty about the software, its performance or its conformity to |
---|
16 | * any specification. |
---|
17 | * |
---|
18 | * $Header: /projects/development/hsv/CVSRepository/vl2mv/src/stack/stack.c,v 1.1.1.1 2001/07/09 23:22:44 fabio Exp $ |
---|
19 | * |
---|
20 | * Author: STCheng, stcheng@ic.berkeley.edu |
---|
21 | */ |
---|
22 | |
---|
23 | #include <stdio.h> |
---|
24 | #include "util.h" |
---|
25 | #include "list.h" |
---|
26 | #include "stack.h" |
---|
27 | |
---|
28 | lsList create_stack() |
---|
29 | { |
---|
30 | return lsCreate(); |
---|
31 | } |
---|
32 | |
---|
33 | void destroy_stack(stack, del_func) |
---|
34 | lsList stack; |
---|
35 | void (*del_func)(); |
---|
36 | { |
---|
37 | (void) lsDestroy(stack, del_func); |
---|
38 | } |
---|
39 | |
---|
40 | void push_stack(obj_stack, item) |
---|
41 | lsList obj_stack; |
---|
42 | void *item; |
---|
43 | { |
---|
44 | lsNewEnd(obj_stack, item, 0); |
---|
45 | } |
---|
46 | |
---|
47 | void *pop_stack(obj_stack, item) |
---|
48 | lsList obj_stack; |
---|
49 | void **item; |
---|
50 | { |
---|
51 | if (lsDelEnd(obj_stack, (lsGeneric*)item) == LS_NOMORE) { |
---|
52 | *item = NIL(void); |
---|
53 | return *item; |
---|
54 | } |
---|
55 | |
---|
56 | return *item; |
---|
57 | } |
---|
58 | |
---|
59 | void *top_stack(obj_stack) |
---|
60 | lsList obj_stack; |
---|
61 | { |
---|
62 | void *item; |
---|
63 | |
---|
64 | if (lsLastItem(obj_stack, (lsGeneric*)&item, 0) == LS_NOMORE) { |
---|
65 | item = NIL(void); |
---|
66 | return item; |
---|
67 | } |
---|
68 | |
---|
69 | return item; |
---|
70 | } |
---|