Advertisement
Guest User

ali

a guest
Apr 1st, 2015
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. printf("State: %s\n", ptemp->state);
  2. printf("City: %s\n\n", ptemp->city);
  3. }
  4. else if (ptemp == NULL)
  5. {
  6. printf("The zip code %s was not found.\n", find);
  7. test = 1;
  8. }
  9. ptemp = ptemp->link;
  10. }
  11. puts ("\nType 'y' if you would you like to see the entire list");
  12. puts ("or any other key to continue>>");
  13. if (ch == 'y' || ch == 'Y')
  14. {
  15. test = 1;
  16. while (test != 0)
  17. test = pop (pstack);
  18. }
  19. }
  20. }
  21. int pop (struct node **pstack)
  22. {
  23. struct node *temp;
  24. if (is_empty(*pstack)== 1)
  25. {
  26. printf("\nStack is now empty");
  27. return(0);
  28. }
  29. else
  30. {
  31. temp = *pstack;
  32. printf("Zip Code: %s\n", temp->zip_code);
  33. printf("State: %s\n", temp->state);
  34. printf("City: %s\n\n", temp->city);
  35. *pstack = (*pstack)->link;
  36. free(temp);
  37. return(1);
  38. }
  39. }
  40. int is_empty (struct node *stack) //test if stack points to NULL
  41. {
  42. if (stack == NULL)
  43. return(1); //if stack does point to NULL return 1 or true
  44. return(0); //othrewise stack is not empty
  45. }
  46. void free_nodes (struct node **pstack)
  47. {
  48. struct node *temp; //temp pointer used for free()ing memory
  49. while (*pstack != NULL)
  50. {
  51. temp = *pstack;
  52. *pstack = (*pstack)->link;
  53. free(temp); //release popped node's memory back to Operating System
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement