YU__84 2023-03-22 09:42 采纳率: 0%
浏览 566

c++ expected unqualified-id before 'public'是哪里报错?

public class test {

public static class Node{
    int data;
    Node next;
}

public void List_Init(Node node ,int data[]){
    Node t=new Node();
    t=node;
    for(int i=0;i<data.length;i++){
        Node p=new Node();
        p.data=data[i];
        p.next=null;        
        t.next=p;
        t=p;            
    }
}

public void delete_Element(Node head ,int value){
    Node p=head;        
    while(p.next!=null){
        Node t=p.next;        
        if(t.data==value){    
            p.next=t.next;
            break; 
        }
        else
            p=p.next;    
    }
}

public void outPut(Node node ){
    for(Node x=node.next;x!=null;x=x.next){
        System.out.print(x.data+" ");
    }
    System.out.println();
}
public static void main(String[] args){
    test L=new test();
    int[] data ={10,11,222,3,4,1,56,1,21,5,62,6,7,57};
    int x=2;                
    Node node =new Node();
    L.List_Init(node, data);    
    L.outPut(node);            
    L.delete_Element(node, x);        
    L.outPut(node);            
}

}

  • 写回答

1条回答 默认 最新

  • threenewbee 2023-03-22 09:55
    关注

    看看你的类的定义,肯定是有什么地方写错了,少了符号

    public后面没有冒号

    评论 编辑记录

报告相同问题?

问题事件

  • 创建了问题 3月22日