Jim's
Tutorials

Spring 2018
course
site
// function to print a linked list l starting at the first node
void printList(list l){
  node n = l->first;    // n = first node
  while(n != NULL){
    printf(" %d ", n->data);
    n = n->next;
  };
};

// function to return a list struct with first and last node initiated as NULL and length 0
list createList(){
  list new_list = (list)malloc(sizeof(struct node_list));
  new_list->length = 0;
  new_list->first = NULL;
  new_list->last = NULL;
  return new_list;
};

// function to push a given node n into the end of a given list l
void push(list l, node n){
  if(l->length == 0){
    l->first = n;
    l->last = n;
    l->length = 1;
  } else {
    l->last->next = n;
    l->last = n;
    l->length++;
  }
}

// insert a new node n, with data - int data- after node prev
void insertAfter(node prev, int data){
  node n = createNode(data);
  n->next = prev->next;
  prev->next = n;
}
https://cs.marlboro.college /cours /spring2018 /jims_tutorials /web_tech /c_apr10
last modified Sun December 22 2024 4:23 am

attachments [paper clip]

  last modified size
TXT binary-tree.c Sun Dec 22 2024 04:23 am 1.2K
TXT linked-list.c Sun Dec 22 2024 04:23 am 2.3K