Guest User

Untitled

a guest
Jan 21st, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.45 KB | None | 0 0
  1. List Cut(List L, Position P)
  2. {
  3.    if (!L || !P) {
  4.         return NULL;
  5.    }
  6.  
  7.    List root = MakeEmpty(NULL);
  8.  
  9.    root->Element = L->Element;
  10.  
  11.    List leaf = root;
  12.    List new_leaf = NULL;
  13.    List pos = L->Next;
  14.  
  15.    while(pos != P && pos != NULL) {
  16.         new_leaf = MakeEmpty(NULL);
  17.  
  18.         new_leaf->Element = pos->Element;
  19.  
  20.         leaf->Next = new_leaf;
  21.  
  22.         leaf = new_leaf;
  23.         pos = pos->Next;
  24.    }
  25.  
  26.    return root;
  27. }
Add Comment
Please, Sign In to add comment