{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture_27 - ECE 190 Lecture 27 Miscellaneous C features...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
ECE 190 Lecture 27 April 26, 2011 1 V. Kindratenko Miscellaneous C features Lecture Topics Linked data structures Applying bubble sort on a linked list Miscellaneous C features Passing command-line arguments to the program Function pointers Conditional compilation using pre-processor directives Lecture materials Homework Machine problem MP5.2 due 4/27 Announcements
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
ECE 190 Lecture 27 April 26, 2011 2 V. Kindratenko Bubble sort with linked list void BubbleSort(item **head) { item **node1; int swapped; do { swapped = 0; for (node1 = head; (*node1)->nextItem != NULL; node1 = &(*node1)->nextItem) { if (strcmp((*node1)->name, (*node1)->nextItem->name) < 0) { /* swap nodes */ SwapTwoNodes(node1); swapped = 1; } } } while (swapped); } void SwapTwoNodes(item **head) { item *node1, *node2; item *new_head; node1 = *head; if (node1 == NULL) return; /* not needed when called from BubbleSort */ node2 = node1->nextItem; if (node2 == NULL) return; /* not needed when called from BubbleSort */ new_head = node2; node1->nextItem = node2->nextItem; node2->nextItem = node1; *head = new_head; }
Background image of page 2
ECE 190 Lecture 27 April 26, 2011 3 V. Kindratenko Passing command-line arguments to the program Main function prototype we have used so far: o int main(void) C has yet another prototype: o int main(int argc, char *argv[]) parameters argc (argument count) and argv (argument vector) give the number and value of the program's command-line arguments.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}