如何将一个linkedlist的数据存储到另一个linkedlist?

eyh26e7m  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(222)

我正在尝试用java创建一个简单的库存管理系统;我想把所有的产品数据存储在一个链表中。有不同类型的产品(类别/品牌),所以我想为产品创建不同的类别并访问它们,但是我在实现上遇到了困难。这是我的密码
主要功能-

Product_Cat product = new Product_Cat();

        C_LinkedList.Node node;
        C_Queue queue = new C_Queue();
        C_Queue.Node qNode;
        Pull_Stack stack;

        while(true){
            System.out.println("Choose Option: 1: Add Items To The Inventory");
            System.out.println("Choose Option: 2: Order An Item");
            System.out.println("Choose Option: 3: Generate Monthly Report");
            System.out.println("Choose Option: 4: Exit");

            Scanner scan = new Scanner(System.in);

            int cs = scan.nextInt();

            if(cs==1){
                System.out.println("Enter Item SKU: ");
                int No = scan.nextInt();
                System.out.println("Enter Item Name: ");
                String Name = scan.next();
                System.out.println("Enter Item Price: ");
                double Price = scan.nextDouble();
                System.out.println("Enter Item Category: ");
                String Category = scan.next();
                System.out.println("Enter Item Quantity: ");
                int Quantity = scan.nextInt();

                node = new C_LinkedList.Node(No, Name, Price, Quantity);
//                list.addAtEnd(node);
            }
         }

产品信息-

public class C_LinkedList {

    /**
     *
     */
    public static class Node //extends Product_Cat.Root
    {
        int No;
        String Name;
        double Price;
        int Quantity;
        Node next;

        public Node(int No, String Name, double Price, int Quantity) {
            //super(Category, list);
            this.No = No;
            this.Name = Name;
            this.Price = Price;
            this.Quantity = Quantity;
        }

    }

    Node head = null;

    public void addAtFront(Node node)
    {
        node.next = head;
        head = node;
    }

    public void addAtEnd(Node node)
    {
        if(head == null)
        {
            head = node;
        }
        else
        {
            Node temp = head;
            while(temp.next != null)
            {
                temp = temp.next;
            }

            temp.next = node;
        }
    }

    public void removeFront()
    {
        head = head.next;
    }

    public Node search(int no)
    {
       Node temp;
       temp = head;
       while(temp != null)
       {
           if(temp.No == no)
           {
               return temp;
           }
           temp = temp.next;
       }
        return null;
    }

   public void print()
   {
       Node temp = head;
       while(temp!=null)
       {
           System.out.println(temp.No+": "+temp.Name+", "+temp.Price+", "+temp.Quantity+", "+temp.details);
           temp = temp.next;
       }

   }

}

产品类别-

public class Product_Cat {

    public static class Root
    {
        String Category;
        C_LinkedList.Node list;

        Root Next;

        public Root(String Category, C_LinkedList.Node list) {
            this.Category = Category;
            this.list = list;
        }

    }

    Root head = null;

    public void addAtFront(Root node)
    {
        node.Next = head;
        head = node;
    }

    public void addAtEnd(Root node)
    {
        if(head == null)
        {
            head = node;
        }
        else
        {
            Root temp = head;
            while(temp.Next != null)
            {
                temp = temp.Next;
            }

            temp.Next = node;
        }
    }

    public void removeFront()
    {
        head = head.Next;
    }

    public Root search(String Cat)
    {
       Root temp;
       temp = head;
       while(temp != null)
       {
           if(temp.Category.equalsIgnoreCase(Cat))
           {
               return temp;
           }
           temp = temp.Next;
       }
        return null;
    }

   public void print()
   {
       Root temp = head;
       while(temp!=null)
       {
           System.out.println("Item No: "+temp.list.No+". Item Name: "+temp.list.Name+". Item Price: "+temp.list.Price+". \nItem Category"+temp.Category+".\n");
           temp = temp.Next;
       }

   }

}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题