Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "orderedList.h"
- Node *orderedInsert(Node *p, int newval)
- /* Allocates a new Node with data value newval
- and inserts into the ordered list with
- first node pointer p in such a way that the
- data values in the modified list are in
- nondecreasing order as the list is traversed.
- */
- {
- Node *q;
- // q = malloc(sizeof(Node));
- q->data = newval;
- printf("%d\n", q->data);
- printf("%d\n", newval);
- if(p==NULL ||newval<=p->data){
- p = q;
- return q;
- }
- Node *tmp = p;
- while (tmp!=NULL){
- tmp = tmp->next;
- if (tmp->data < q->data){
- q->next = tmp->next;
- tmp->next = q;
- return q;
- break;
- }
- }
- }
- void printList(FILE *outfile, Node *p)
- /* Prints the data values in the list with
- first node pointer p from first to last,
- with a space between successive values.
- Prints a newline at the end of the list.
- */
- {
- outfile = fopen("output0.txt", "w");
- Node *n;
- p = n;
- while (n != NULL){
- n = n->next;
- fprintf(outfile, "%d\n", n->data);
- }
- }
- void clearList(Node **p)
- /* Deletes all the nodes in the list with
- first node pointer *p, resulting in *p
- having value NULL. Note that we are passing
- a pointer by address so we can modify that
- pointer.
- */
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement