Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class BrishiPodlisti {
- public static boolean ifEqual(SLLNode<Integer> tmp1, SLL<Integer>list2){
- SLLNode<Integer> tmp2=list2.getFirst();
- for(int i=0;i<list2.length();i++){
- if(tmp1.element!=tmp2.element){
- return false;
- }else{
- tmp1=tmp1.succ;
- tmp2=tmp2.succ;
- if(tmp1==null && tmp2!=null)
- return false;
- }
- }
- return true;
- }
- public static void izbrishi(SLL<Integer> list1, SLL<Integer> list2){
- SLLNode<Integer> tmp1=list1.getFirst();
- SLLNode<Integer> tmp2=list2.getFirst();
- while (tmp1!=null){
- if(tmp1.element==tmp2.element){
- if(ifEqual(tmp1,list2)){
- for(int i=0;i<list2.length();i++){
- SLLNode<Integer> kopija=tmp1;
- list1.delete(tmp1);
- tmp1=kopija.succ;
- }
- }else{
- tmp1=tmp1.succ;
- }
- }
- else{
- tmp1=tmp1.succ;
- }
- }
- System.out.println(list1);
- }
- public static void main(String[] args) {
- Scanner in=new Scanner(System.in);
- int n1=in.nextInt();
- SLL<Integer> list1=new SLL<>();
- for(int i=0;i<n1;i++){
- list1.insertLast(in.nextInt());
- }
- int n2=in.nextInt();
- SLL<Integer> list2=new SLL<>();
- for(int i=0;i<n2;i++){
- list2.insertLast(in.nextInt());
- }
- izbrishi(list1,list2);
- }
- }
Add Comment
Please, Sign In to add comment