Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public SLLNode getByIndex(int index){
- SLLNode current = first;
- int counter = 0;
- while(current != null){
- if(counter == index){
- return current;
- }
- counter+=1;
- current = current.succ;
- }
- return null;
- }
- public void reverseK(int k){
- SLLNode current = first;
- SLLNode prev = null;
- int counter = 0;
- while(current != null){
- if(counter == k){
- for(int i = 0; i < k; i++){
- insertAfter((E) getByIndex(i), prev);
- }
- }
- counter+=1;
- prev = current;
- current = current.succ;
- }
- current = first;
- counter = 0;
- while(current != null){
- if(counter < k){
- delete(current);
- }
- counter +=1;
- current = current.succ;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement