286 |
void* delimiter; |
void* delimiter; |
287 |
stackitem *iterator, *temp, *pack; |
stackitem *iterator, *temp, *pack; |
288 |
|
|
|
if((*stack_head)==NULL) { |
|
|
printerr("Stack empty"); |
|
|
return; |
|
|
} |
|
|
|
|
289 |
delimiter= (*stack_head)->content.ptr; /* Get delimiter */ |
delimiter= (*stack_head)->content.ptr; /* Get delimiter */ |
290 |
toss(stack_head); |
toss(stack_head); |
291 |
|
|
292 |
iterator= *stack_head; |
iterator= *stack_head; |
293 |
|
|
294 |
/* Search for first delimiter */ |
if(iterator==NULL || iterator->content.ptr==delimiter) { |
295 |
while(iterator->next!=NULL && iterator->next->content.ptr!=delimiter) |
temp= NULL; |
|
iterator= iterator->next; |
|
|
|
|
|
/* Extract list */ |
|
|
temp= *stack_head; |
|
|
*stack_head= iterator->next; |
|
|
iterator->next= NULL; |
|
|
|
|
|
if(*stack_head!=NULL && (*stack_head)->content.ptr==delimiter) |
|
296 |
toss(stack_head); |
toss(stack_head); |
297 |
|
} else { |
298 |
|
/* Search for first delimiter */ |
299 |
|
while(iterator->next!=NULL && iterator->next->content.ptr!=delimiter) |
300 |
|
iterator= iterator->next; |
301 |
|
|
302 |
|
/* Extract list */ |
303 |
|
temp= *stack_head; |
304 |
|
*stack_head= iterator->next; |
305 |
|
iterator->next= NULL; |
306 |
|
|
307 |
|
if(*stack_head!=NULL && (*stack_head)->content.ptr==delimiter) |
308 |
|
toss(stack_head); |
309 |
|
} |
310 |
|
|
311 |
/* Push list */ |
/* Push list */ |
312 |
pack= malloc(sizeof(stackitem)); |
pack= malloc(sizeof(stackitem)); |
407 |
new_head= temp= (*stack_head)->content.ptr; |
new_head= temp= (*stack_head)->content.ptr; |
408 |
toss(stack_head); |
toss(stack_head); |
409 |
|
|
410 |
|
if(temp==NULL) |
411 |
|
return; |
412 |
|
|
413 |
/* Search the end of the list */ |
/* Search the end of the list */ |
414 |
while(temp->next!=NULL) |
while(temp->next!=NULL) |
415 |
temp= temp->next; |
temp= temp->next; |
506 |
exit(EXIT_SUCCESS); |
exit(EXIT_SUCCESS); |
507 |
} |
} |
508 |
|
|
509 |
|
/* Clear stack */ |
510 |
|
extern void clear(stackitem** stack_head) |
511 |
|
{ |
512 |
|
while(*stack_head!=NULL) |
513 |
|
toss(stack_head); |
514 |
|
} |
515 |
|
|
516 |
int main() |
int main() |
517 |
{ |
{ |
518 |
stackitem* s= NULL; |
stackitem* s= NULL; |