import java.util.ArrayList; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); ArrayList<Integer>arr=new ArrayList<>(); for (int i = 0; i < n; i++) { arr.add(0,sc.nextInt()); } int m=sc.nextInt(); for (int i = 0; i < m+1; i++) { String str=sc.nextLine(); if(!str.equals("")){ String[]s=str.split(" "); if(s[0].equals("show")){ int k=arr.size(); if(k==0)System.out.println("Link list is empty"); else{ for (int j = 0; j < k-1; j++) { System.out.print(arr.get(j)+" "); } System.out.println(arr.get(k-1)); } }else if(s[0].equals("insert")){ int a=Integer.parseInt(s[1]); int b=Integer.parseInt(s[2]); try { arr.add(a-1,b); System.out.println("insert OK"); } catch (Exception e) { System.out.println("insert fail"); } } else if(s[0].equals("delete")){ int a=Integer.parseInt(s[1]); try { arr.remove(a-1); System.out.println("delete OK"); } catch (Exception e) { System.out.println("delete fail"); } } else { int a=Integer.parseInt(s[1]); try { System.out.println(arr.get(a-1)); } catch (Exception e) { System.out.println("get fail"); } } } } } }
0.0分
1 人评分
C语言训练-求函数值 (C语言代码)浏览:931 |
C语言训练-立方和不等式 (C语言代码)浏览:746 |
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:626 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:960 |
C语言程序设计教程(第三版)课后习题6.2 (C语言代码)浏览:685 |
【计算球体积】 (C语言代码)浏览:1101 |
1126题解浏览:584 |
C语言程序设计教程(第三版)课后习题7.5 (C语言代码)浏览:548 |
C语言程序设计教程(第三版)课后习题8.5 (C语言代码)浏览:658 |
C语言训练-字符串正反连接 (C语言代码)浏览:629 |