MCPcopy Create free account
hub / github.com/PrajaktaSathe/Java / main

Method main

Programs/ReverseList.java:4–45  ·  view source on GitHub ↗
(String args[])

Source from the content-addressed store, hash-verified

2import java.util.*;
3public class ReverseList {
4 public static void main(String args[])
5 {
6 try (Scanner sc = new Scanner(System.in)) {
7 ListNode fresh,start=null,prev=null,ptr=null;
8 int c;
9 do
10 {
11 fresh=new ListNode();
12 System.out.println("Enter the data");
13 fresh.data=sc.nextInt();
14 if(start==null)
15 {
16 start=fresh;
17 // stores the starting address
18 }
19 else
20 {
21 prev.next=fresh;
22 }
23 prev=fresh;
24 System.out.println("Press 1 to for next node initialization else press any number other than 1 to exit");
25 c=sc.nextInt();
26 // for next node initialization option is asked from the user
27 }while(c==1);
28 Solution nm=new Solution();
29 System.out.println("The original LinkedList is ");
30 for(ptr=start;ptr!=null;ptr=ptr.next)
31 {
32 System.out.print(ptr.data+" ");
33 }
34 System.out.println();
35 // displayes the original linkedlist
36 System.out.println("The reversed LinkedList is ");
37 nm.reverseList(start);
38 for(ptr=start;ptr!=null;ptr=ptr.next)
39 {
40 System.out.print(ptr.data+" ");
41 }
42 System.out.println();
43 // displays the reserved linkedlist
44 }
45 }
46}
47class Solution
48{

Callers

nothing calls this directly

Calls 2

reverseListMethod · 0.95
printMethod · 0.80

Tested by

no test coverage detected