Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Promena {
- public static int zbir(SLL<Integer> list, int pos1, int pos2){
- SLLNode<Integer> tmp=list.getFirst();
- int brojac=0;
- int sum=0;
- while (brojac!=pos1){
- tmp=tmp.succ;
- brojac++;
- }
- while(brojac!=pos2+1){
- sum+=tmp.element;
- tmp=tmp.succ;
- brojac++;
- }
- return sum;
- }
- public static void promeni(SLL<Integer> list, int pos1, int pos2){
- int sum=zbir(list,pos1,pos2);
- SLLNode<Integer> tmp=list.getFirst();
- while(tmp!=null){
- tmp=tmp.succ;
- if(tmp==null)
- break;
- list.insertBefore(sum,tmp);
- SLLNode<Integer> kopija=tmp;
- list.delete(tmp);
- tmp=kopija.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());
- }
- int pos1=in.nextInt();
- int pos2=in.nextInt();
- promeni(list,pos1,pos2);
- }
- }
Add Comment
Please, Sign In to add comment