Advertisement
Guest User

orderedlist.c

a guest
Apr 19th, 2015
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. #include "orderedList.h"
  2.  
  3. Node *orderedInsert(Node *p, int newval)
  4. /* Allocates a new Node with data value newval
  5. and inserts into the ordered list with
  6. first node pointer p in such a way that the
  7. data values in the modified list are in
  8. nondecreasing order as the list is traversed.
  9. */
  10. {
  11. Node *q;
  12. // q = malloc(sizeof(Node));
  13. q->data = newval;
  14. printf("%d\n", q->data);
  15. printf("%d\n", newval);
  16. if(p==NULL ||newval<=p->data){
  17. p = q;
  18. return q;
  19. }
  20. Node *tmp = p;
  21. while (tmp!=NULL){
  22. tmp = tmp->next;
  23. if (tmp->data < q->data){
  24. q->next = tmp->next;
  25. tmp->next = q;
  26. return q;
  27. break;
  28. }
  29. }
  30. }
  31.  
  32. void printList(FILE *outfile, Node *p)
  33. /* Prints the data values in the list with
  34. first node pointer p from first to last,
  35. with a space between successive values.
  36. Prints a newline at the end of the list.
  37. */
  38. {
  39. outfile = fopen("output0.txt", "w");
  40. Node *n;
  41. p = n;
  42. while (n != NULL){
  43. n = n->next;
  44. fprintf(outfile, "%d\n", n->data);
  45. }
  46. }
  47.  
  48. void clearList(Node **p)
  49. /* Deletes all the nodes in the list with
  50. first node pointer *p, resulting in *p
  51. having value NULL. Note that we are passing
  52. a pointer by address so we can modify that
  53. pointer.
  54. */
  55. {
  56.  
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement