main
|
Last change
on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago |
|
Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.
git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c
|
-
Property mode
set to
100644
|
|
File size:
841 bytes
|
| Line | |
|---|
| 1 | /* Commandline execution:
|
|---|
| 2 | * civl verify linkedList.cvl
|
|---|
| 3 | * */
|
|---|
| 4 | #include<civlc.cvh>
|
|---|
| 5 |
|
|---|
| 6 | $input int N;
|
|---|
| 7 | $assume(N > 0 && N <= 5);
|
|---|
| 8 |
|
|---|
| 9 | typedef struct Node {
|
|---|
| 10 | double value;
|
|---|
| 11 | struct Node* next;
|
|---|
| 12 | } Node;
|
|---|
| 13 |
|
|---|
| 14 | void main() {
|
|---|
| 15 | $scope s = $here;
|
|---|
| 16 | Node* head;
|
|---|
| 17 | Node* current = (Node *) $malloc(s, sizeof(Node));
|
|---|
| 18 | Node final;
|
|---|
| 19 |
|
|---|
| 20 | head = current;
|
|---|
| 21 | head->value = 0.0;
|
|---|
| 22 | for (int i = 0; i < N-1; i++) {
|
|---|
| 23 | Node* newNode = (Node *) $malloc(s, sizeof(Node));
|
|---|
| 24 |
|
|---|
| 25 | newNode->value = (i+1)*2.71828;
|
|---|
| 26 | current->next = newNode;
|
|---|
| 27 | current = newNode;
|
|---|
| 28 | }
|
|---|
| 29 | current->next = NULL;
|
|---|
| 30 | final = *head;
|
|---|
| 31 | while (final.next != NULL) {
|
|---|
| 32 | final = *(final.next);
|
|---|
| 33 | }
|
|---|
| 34 | $assert(final.value == (N-1)*2.71828);
|
|---|
| 35 | $assert(final.value == current->value);
|
|---|
| 36 | while (head->next != NULL) {
|
|---|
| 37 | Node* tmp = head;
|
|---|
| 38 |
|
|---|
| 39 | head = head->next;
|
|---|
| 40 | $free(tmp);
|
|---|
| 41 | }
|
|---|
| 42 | $free(head);
|
|---|
| 43 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.