File: list.C

package info (click to toggle)
librudiments0 0.27-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,528 kB
  • ctags: 2,284
  • sloc: cpp: 14,657; sh: 7,547; ansic: 2,664; makefile: 945; xml: 15
file content (92 lines) | stat: -rw-r--r-- 1,932 bytes parent folder | download
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
90
91
92
// Copyright (c) 2003  David Muse
// See the file COPYING for more information

#include <rudiments/linkedlist.h>
#include <stdio.h>

int	main(int argc, char **argv) {

	// create a list of integers
	linkedlist<int>	intl;

	// append values to the list, displaying the list after each append
	printf("append(0)\n");
	intl.append(0);
	intl.print();

	printf("append(1)\n");
	intl.append(1);
	intl.print();

	printf("append(3)\n");
	intl.append(3);
	intl.print();

	// insert a value into the middle of the list, display the list
	printf("insert(2,2)\n");
	intl.insert(2,2);
	intl.print();

	// remove values from the list, displaying the list after each removal
	printf("removeByIndex(0)\n");
	intl.removeByIndex(0);
	intl.print();

	printf("removeByData(3)\n");
	intl.removeByData(3);
	intl.print();

	// change a value in the list, display the list
	printf("setDataByIndex(1,50)\n");
	intl.setDataByIndex(1,50);
	intl.print();

	// clear the list, display the list
	printf("clear()\n");
	intl.clear();
	intl.print();


	printf("\n\n");


	// create a list of strings
	stringlist	strl;

	// append values to the list, displaying the list after each append
	printf("append(zero)\n");
	strl.append("zero");
	strl.print();

	printf("append(one)\n");
	strl.append("one");
	strl.print();

	printf("append(three)\n");
	strl.append("three");
	strl.print();

	// insert a value into the middle of the list, display the list
	printf("insert(2,two)\n");
	strl.insert(2,"two");
	strl.print();

	// remove values from the list, displaying the list after each removal
	printf("removeByIndex(0)\n");
	strl.removeByIndex(0);
	strl.print();

	printf("removeByData(three)\n");
	strl.removeByData("three");
	strl.print();

	// change a value in the list, display the list
	printf("setDataByIndex(1,fifty)\n");
	strl.setDataByIndex(1,"fifty");
	strl.print();

	// clear the list, display the list
	printf("clear()\n");
	strl.clear();
	strl.print();
}