Sams Teach Yourself C in 21 Days

(singke) #1
Pointers: Beyond the Basics 429

115: if (new_rec->next_rec != prev_rec->next_rec) 15
116: {
117: printf(“ERROR”);
118: getc(stdin);
119: exit(0);
120: }
121: prev_rec->next_rec = new_rec;
122: break; /* link is added; exit while */
123: }
124: else
125: {
126: tmp_rec = tmp_rec->next_rec;
127: prev_rec = prev_rec->next_rec;
128: }
129: }
130:
131: /* check to see if adding to the end */
132: if (tmp_rec->next_rec == NULL)
133: {
134: if (new_rec->ch < tmp_rec->ch ) /* 1 b4 end */
135: {
136: new_rec->next_rec = tmp_rec;
137: prev_rec->next_rec = new_rec;
138: }
139: else /* at the end */
140: {
141: tmp_rec->next_rec = new_rec;
142: new_rec->next_rec = NULL; /* redundant */
143: }
144: }
145: }
146: }
147: }
148: return(first);
149: }
150:
151: /*========================================================*
152: * Function: show_list
153: * Purpose : Displays the information current in the list
154: *========================================================*/
155:
156: void show_list( LISTPTR first )
157: {
158: LISTPTR cur_ptr;
159: int counter = 1;
160:
161: printf(“\n\nRec addr Position Data Next Rec addr\n”);
162: printf(“======== ======== ==== =============\n”);
163:

LISTING15.13 continued

25 448201x-CH15 8/13/02 11:13 AM Page 429

Free download pdf