Listen Klasse Implementieren




    The List class contains an integer "info" field and a next field. The List class also has two constructors: one that takes two int values (x,l), and another that takes one int value (x). The List class also has two methods: one that inserts an element at position x in the list, and another that deletes the element at position x from the list. The toString() method returns a string that shows the list's contents, starting with the info field and continuing for each element in the list, separated by a comma. The List class also has a public instance variable next that points to the next list in the list's linked list.

    public class List{
      public int info;
      public List next;
      public List (int x, List l){
        info = x;
      public List (int x){
        info = x;
        next =null; 
      // Objekt- Methoden
        public void insert(int x){
        next = new List(x,next);
        public void delete(){
          if (next != null)
            next =;
        public String toString(){
          String result = "["+info;
          for(List t = next; t!=null;
            result = result +", "+;
          return result +"]";
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.