~ubuntu-branches/ubuntu/lucid/igraph/lucid

« back to all changes in this revision

Viewing changes to examples/simple/dqueue.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathieu Malaterre
  • Date: 2009-11-16 18:12:42 UTC
  • Revision ID: james.westby@ubuntu.com-20091116181242-mzv9p5fz9uj57xd1
Tags: upstream-0.5.3
ImportĀ upstreamĀ versionĀ 0.5.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: C -*-  */
 
2
/* 
 
3
   IGraph library.
 
4
   Copyright (C) 2006  Gabor Csardi <csardi@rmki.kfki.hu>
 
5
   MTA RMKI, Konkoly-Thege Miklos st. 29-33, Budapest 1121, Hungary
 
6
   
 
7
   This program is free software; you can redistribute it and/or modify
 
8
   it under the terms of the GNU General Public License as published by
 
9
   the Free Software Foundation; either version 2 of the License, or
 
10
   (at your option) any later version.
 
11
   
 
12
   This program is distributed in the hope that it will be useful,
 
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
   GNU General Public License for more details.
 
16
   
 
17
   You should have received a copy of the GNU General Public License
 
18
   along with this program; if not, write to the Free Software
 
19
   Foundation, Inc.,  51 Franklin Street, Fifth Floor, Boston, MA 
 
20
   02110-1301 USA
 
21
 
 
22
*/
 
23
 
 
24
#include <igraph.h>
 
25
 
 
26
int main() {
 
27
  
 
28
  igraph_dqueue_t q;
 
29
  int i;
 
30
 
 
31
  /* igraph_dqueue_init, igraph_dqueue_destroy, igraph_dqueue_empty */
 
32
  igraph_dqueue_init(&q, 5);
 
33
  if (!igraph_dqueue_empty(&q)) {
 
34
    return 1;
 
35
  }
 
36
  igraph_dqueue_destroy(&q);
 
37
 
 
38
  /* igraph_dqueue_push, igraph_dqueue_pop */
 
39
  igraph_dqueue_init(&q, 4);
 
40
  igraph_dqueue_push(&q, 1);
 
41
  igraph_dqueue_push(&q, 2);
 
42
  igraph_dqueue_push(&q, 3);
 
43
  igraph_dqueue_push(&q, 4);
 
44
  if (igraph_dqueue_pop(&q) != 1) {
 
45
    return 2;
 
46
  }
 
47
  if (igraph_dqueue_pop(&q) != 2) {
 
48
    return 3;
 
49
  }
 
50
  if (igraph_dqueue_pop(&q) != 3) {
 
51
    return 4;
 
52
  }
 
53
  if (igraph_dqueue_pop(&q) != 4) {
 
54
    return 5;
 
55
  }
 
56
  igraph_dqueue_destroy(&q);
 
57
 
 
58
  /* igraph_dqueue_clear, igraph_dqueue_size */
 
59
  igraph_dqueue_init(&q, 0);
 
60
  if (igraph_dqueue_size(&q) != 0) {
 
61
    return 6;
 
62
  }
 
63
  igraph_dqueue_clear(&q);
 
64
  if (igraph_dqueue_size(&q) != 0) {
 
65
    return 7;
 
66
  }
 
67
  for (i=0; i<10; i++) {
 
68
    igraph_dqueue_push(&q, i);
 
69
  }
 
70
  igraph_dqueue_clear(&q);
 
71
  if (igraph_dqueue_size(&q) != 0) {
 
72
    return 8;
 
73
  }
 
74
  igraph_dqueue_destroy(&q);
 
75
 
 
76
  /* TODO: igraph_dqueue_full */
 
77
 
 
78
  /* igraph_dqueue_head, igraph_dqueue_back, igraph_dqueue_pop_back */
 
79
  igraph_dqueue_init(&q, 0);
 
80
  for (i=0; i<10; i++) {
 
81
    igraph_dqueue_push(&q, i);
 
82
  }
 
83
  for (i=0; i<10; i++) {
 
84
    if (igraph_dqueue_head(&q) != 0) {
 
85
      return 9;
 
86
    }
 
87
    if (igraph_dqueue_back(&q) != 9-i) {
 
88
      return 10;
 
89
    }
 
90
    if (igraph_dqueue_pop_back(&q) != 9-i) {
 
91
      return 11;
 
92
    }
 
93
  }
 
94
  igraph_dqueue_destroy(&q);
 
95
 
 
96
  if (IGRAPH_FINALLY_STACK_SIZE() != 0) return 12;
 
97
 
 
98
  return 0;
 
99
}