Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. public SLLNode getByIndex(int index){
  2. SLLNode current = first;
  3. int counter = 0;
  4. while(current != null){
  5. if(counter == index){
  6. return current;
  7. }
  8. counter+=1;
  9. current = current.succ;
  10. }
  11. return null;
  12. }
  13. public void reverseK(int k){
  14. SLLNode current = first;
  15. SLLNode prev = null;
  16. int counter = 0;
  17. while(current != null){
  18. if(counter == k){
  19. for(int i = 0; i < k; i++){
  20. insertAfter((E) getByIndex(i), prev);
  21. }
  22. }
  23. counter+=1;
  24. prev = current;
  25. current = current.succ;
  26. }
  27. current = first;
  28. counter = 0;
  29. while(current != null){
  30. if(counter < k){
  31. delete(current);
  32. }
  33. counter +=1;
  34. current = current.succ;
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement