11.07.2014 Views

Flute acoustics: measurement, modelling and design - School of ...

Flute acoustics: measurement, modelling and design - School of ...

Flute acoustics: measurement, modelling and design - School of ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

APPENDIX B. PROGRAM LISTINGS 300<br />

/* if inserted at beginning, update head */<br />

if(index == 0) {<br />

cur = v->head;<br />

v->head = (Node)malloc(size<strong>of</strong>(*(v->head)));<br />

v->head->object = object;<br />

v->head->next = cur;<br />

}<br />

else {<br />

/* if inserted at end, update tail */<br />

if(index == v->num) {<br />

cur = v->tail;<br />

v->tail = (Node)malloc(size<strong>of</strong>(*(v->tail)));<br />

v->tail->object = object;<br />

v->tail->next = NULL;<br />

cur->next = v->tail;<br />

}<br />

/* otherwise, find position in Vector <strong>and</strong> update appropriately<br />

*/<br />

else {<br />

cur = v->head->next;<br />

prev = v->head;<br />

for(i = 1; i < index; i++) {<br />

cur = cur->next;<br />

prev = prev->next;<br />

}<br />

prev->next = (Node)malloc(size<strong>of</strong>(*(prev->next)));<br />

prev->next->object = object;<br />

prev->next->next = cur;<br />

}<br />

}<br />

}<br />

/* increment size */<br />

v->num++;<br />

return;<br />

}<br />

void setAt(Vector v, void* object, int index) {<br />

int i;<br />

Node cur;<br />

cur = v->head;<br />

/* find indexed element */<br />

for(i = 0; i < index; i++) {<br />

cur = cur->next;<br />

}<br />

/* update indexed element with given object */<br />

cur->object = object;<br />

return;<br />

}<br />

void popFront(Vector v) {<br />

Node second_element;<br />

/* do nothing if empty vector */<br />

if(sizeVector(v) == 0)<br />

return;<br />

/* if only 1 element, free head <strong>and</strong> reinitialise Vector */<br />

if(sizeVector(v) == 1) {<br />

free(v->head);<br />

v->head = NULL;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!