Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class NPatiSredina {
- public static SLLNode<Integer> findEl(SLL<Integer> list, int n){
- SLLNode<Integer> tmp=list.getFirst();
- while(n!=0){
- n--;
- tmp=tmp.succ;
- }
- return tmp;
- }
- public static void brishi(SLL<Integer> list, int m){
- while(m!=0){
- m--;
- int n=list.length()/2;
- if(list.length()%2!=0){
- list.delete(findEl(list,n));
- }
- else{
- SLLNode<Integer> first=findEl(list,n-1);
- SLLNode<Integer> second=findEl(list,n);
- if(first.element==second.element){
- list.delete(first);
- }
- else if(first.element<second.element){
- list.delete(first);
- }else{
- list.delete(second);
- }
- }
- }
- 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 m=in.nextInt();
- brishi(list,m);
- }
- }
Add Comment
Please, Sign In to add comment