Datasets:

ArXiv:
License:
File size: 639 Bytes
c574d3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class Sum{
  Node first,last,t;

  static class Node{
    int data;
    Node next;

    Node(int d){
      this.data = d;
      this.next = null;
    }
  }


  void create(int a[], int n){

    first = new Node(a[0]);
    last  =first;

    for(int i=1; i <n; i++){

      t = new Node(a[i]);

      last.next = t;
      last =t;
    }
  }


  void summ(){

    Node p = first;

    int s=0;
    while(p!=null){
      s+=p.data;
      p = p.next;
    }

    System.out.println(s);
  }

  public static void main(String[] args){
    Sum l = new Sum();
    int a[] = {1,2,3,4,5};
    int n = a.length;
    l.create(a,n);
    l.summ();
  }
}