Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- //Ovaa verzija gi brishe samo sprotivnite nodes. Primer : 2 i -2, 3 i -3
- public class ZeroConsecutiveNodes {
- public static void remove(SLL<Integer> list){
- SLLNode<Integer> tmp=list.getFirst();
- SLLNode<Integer> tmp2;
- while (tmp!=null){
- tmp2=tmp.succ;
- if(tmp2==null) break;
- while (tmp2!=null){
- if(tmp.element + tmp2.element == 0){
- list.delete(tmp2);
- SLLNode<Integer> kopija=tmp;
- list.delete(tmp);
- tmp=kopija.succ;
- break;
- }else{
- tmp2 = tmp2.succ;
- }
- }
- if(tmp2==null){
- tmp=tmp.succ;
- }
- }
- System.out.println(list);
- }
- public static void main(String[] args) {
- Scanner in=new Scanner(System.in);
- int n=in.nextInt();
- SLL<Integer> list=new SLL<>();
- for(int i=0;i<n;i++){
- list.insertLast(in.nextInt());
- }
- remove(list);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement