Download presentation
Presentation is loading. Please wait.
1
CSSE221: Software Dev. Honors Day 29 Announcements Announcements Any questions on strings? Any questions on strings? Section 2: pass in quiz after question time. Section 2: pass in quiz after question time. All C Projects due Friday night, 11:59 pm All C Projects due Friday night, 11:59 pm Final Exam next Monday, 6-10 pm, here. Final Exam next Monday, 6-10 pm, here. Any schedule conflicts? Any schedule conflicts?
2
Pig Latin Be very careful with null-terminating strings Be very careful with null-terminating strings strcpy and strcat are your friends strcpy and strcat are your friends IF you pre-allocate enough space to hold the string IF you pre-allocate enough space to hold the string char buffer[1000]; char buffer[1000]; strcpy(buffer, “hi”); // inserts ‘\0’ strcpy(buffer, “hi”); // inserts ‘\0’ strcat(buffer, “ there”); //inserts ‘\0’ strcat(buffer, “ there”); //inserts ‘\0’ strncat(buffer, “Robert”, 3); //doesn’t insert the ‘\0’ strncat(buffer, “Robert”, 3); //doesn’t insert the ‘\0’ Need to manually insert ‘\0’ Need to manually insert ‘\0’
3
strtok usage char * word = strtok(sentence, “ “); while (word != NULL) { // do something with word word = strtok(NULL, “ “); }
4
More “official” help How’d you know about strncat? How’d you know about strncat? Login via secureCRT to addiator. This gives a shell. Login via secureCRT to addiator. This gives a shell. Type “man strncat” Type “man strncat”
5
Pass in string quiz
6
Final research survey Please share thoughts about capsules as a whole, particularly those in round 3 (the last 3.5 weeks, everything since threads). Please share thoughts about capsules as a whole, particularly those in round 3 (the last 3.5 weeks, everything since threads). I was wrong, you don’t need to resign consent form. I was wrong, you don’t need to resign consent form.
7
This week: More C Monday: Monday: Strings in C (capsule) Strings in C (capsule) Tuesday: Tuesday: Linked list implementation in C Linked list implementation in C Thursday: Thursday: Wrap-up C unit Wrap-up C unit Opportunity for questions about final exam Opportunity for questions about final exam
8
Basic version: Basic version: The LinkedList struct has only 2 fields: pointers to the first and last nodes. The LinkedList struct has only 2 fields: pointers to the first and last nodes. Each node keeps track of the next node in the list. Each node keeps track of the next node in the list. Linked Lists
9
Keys to success Always draw box-and-pointer pictures to help you figure out algorithms for inserting and deleting, etc. Always draw box-and-pointer pictures to help you figure out algorithms for inserting and deleting, etc. Be sure to handle special cases: is inserting into an empty list any different from inserting into a non-empty one? Be sure to handle special cases: is inserting into an empty list any different from inserting into a non-empty one? Handle memory with care: Handle memory with care: Every time a node is created, we’ll malloc. Every time a node is created, we’ll malloc. So every time we remove the node, we’ll free! So every time we remove the node, we’ll free!
10
LinkedListBasic.h typedef struct { Node * first; Node * last; } LinkedList; typedef struct { int data; Node* next; } Node; Unfortunately, you can’t recursively create a typedef! This alternate way to declare structs works: struct _Node { int data; struct _Node* next; }; typedef struct _Node Node;
11
Lots of functions to write makeNode makeNode makeList makeList addBack, addFront addBack, addFront display display removeFront removeFront getSize getSize setAt(pos), insertAt(pos), removeAt(pos), displayRecursive setAt(pos), insertAt(pos), removeAt(pos), displayRecursive reverse, reverseRecursive reverse, reverseRecursive Check out the LinkedListBasic project from the public repos. Let’s look together at the header and write some of the code. Then you’ll work on these lots in class.
12
Break
13
Eliminating Special Cases Header and trailer nodes: Header and trailer nodes: Header: an extra node at the beginning of the linked list implementation that points to the node containing the first List item. The contents of the header node are not part of the List. This is stored in the list instead of “first” Header: an extra node at the beginning of the linked list implementation that points to the node containing the first List item. The contents of the header node are not part of the List. This is stored in the list instead of “first” Trailer: an extra node at the back of the list, for symmetry in doubly-linked lists. Trailer: an extra node at the back of the list, for symmetry in doubly-linked lists. Thus there are two nodes in the representation of the empty list, three nodes in the representation of a one-element list, etc. Thus there are two nodes in the representation of the empty list, three nodes in the representation of a one-element list, etc.
14
An enhanced version Once you are done, you should check out the LinkedListEnhanced project. It includes the following enhancements: Once you are done, you should check out the LinkedListEnhanced project. It includes the following enhancements: Doubly-linked Doubly-linked Dummy nodes (header and trailer) to remove special cases. Dummy nodes (header and trailer) to remove special cases. Size field to make getSize a constant-time operation. Size field to make getSize a constant-time operation.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.