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

Class GfG

Programs/MergeKsortedLists.java:85–130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83
84
85 class GfG
86 {
87 public static void printList(Node node)
88 {
89 while(node != null)
90 {
91 System.out.print(node.data + " ");
92 node = node.next;
93 }
94 }
95
96 public static void main (String[] args) {
97 Scanner sc = new Scanner(System.in);
98
99 int t = sc.nextInt();
100 while(t-- > 0)
101 {
102 int N = sc.nextInt();
103
104 Node []a = new Node[N];
105
106 for(int i = 0; i < N; i++)
107 {
108 int n = sc.nextInt();
109
110 Node head = new Node(sc.nextInt());
111 Node tail = head;
112
113 for(int j=0; j<n-1; j++)
114 {
115 tail.next = new Node(sc.nextInt());
116 tail = tail.next;
117 }
118
119 a[i] = head;
120 }
121
122 Solution g = new Solution();
123
124 Node res = g.mergeKList(a,N);
125 if(res!=null)
126 printList(res);
127 System.out.println();
128 }
129 }
130 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected