Advertisement
Guest User

random

a guest
Dec 12th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. element* insert_sorted(element *first, element *new_elem) {
  2.  
  3.  
  4. if (first==NULL){
  5. first = new_elem;
  6. return first;
  7. }
  8.  
  9. if (first!=NULL && ((first->isbn) > (new_elem->isbn))){
  10. new_elem->next = first;
  11. first = new_elem;
  12. return first;
  13. }
  14.  
  15. element *tmp= first;
  16. element *tmp2= tmp->next;
  17.  
  18. if (tmp2 ==NULL) {
  19.  
  20. tmp->next = new_elem;
  21. return first;
  22. }
  23.  
  24. while ((tmp2 != NULL) && ((tmp->isbn) < (tmp2->isbn))){
  25. tmp2 = tmp2->next;
  26. tmp = tmp2;
  27. }
  28.  
  29. new_elem->next = tmp2;
  30. tmp = new_elem;
  31. return first;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement