-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJava_ds_demo
More file actions
88 lines (85 loc) · 1.87 KB
/
Copy pathJava_ds_demo
File metadata and controls
88 lines (85 loc) · 1.87 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package cs_dsa;
import java.util.Iterator;
import java.util.LinkedList;
public class ds {
public static void main(String[] args) {
LinkedList node = new LinkedList<Integer>(); // empty linked list object
node.add(2);
node.add(30);
node.add(40);
node.add(50);
node.add(60);
LinkedList nodesecond = new LinkedList<Integer>();
nodesecond.add(60);
nodesecond.add(50);
nodesecond.add(40);
nodesecond.add(30);
nodesecond.add(20);
ds d = new ds();
/*int total = d.sumLinkedList(node, nodesecond);
System.out.println("total of both list :"+total);*/
/*int max = d.maxno(node, nodesecond); //1st question
System.out.println("Maximum number is :"+max);*/
//int sing = d.single(node, nodesecond); // 2nd question
int unq = d.unique(node, nodesecond);
}
int sumLinkedList(LinkedList a , LinkedList b) {
int sum = 0 ;
Iterator it = a.iterator();
while(it.hasNext())
{
int n = (Integer)it.next();
sum = sum + n ;
}
it = b.iterator();
while(it.hasNext())
{
int n = (Integer)it.next();
sum = sum + n ;
}
return sum;
}
int maxno(LinkedList a , LinkedList b){
int num = (Integer)a.get(0);
Iterator it = a.iterator() ;
while(it.hasNext()) {
int n = (Integer)it.next();
if(n>=num) {
num = n;
}
}
it = b.iterator();
while(it.hasNext()) {
int n = (Integer)it.next();
if(n>=num) {
num = n;
}
}
return num;
}
int single(LinkedList a , LinkedList b) {
Iterator it = a.iterator() ;
int num = 0 ;
while(it.hasNext()) {
int n = (Integer)it.next();
if(n < 10 && n> -10) {
System.out.print(n+" ");
}
else {
System.out.println("nahi hai");
}
}
return 0;
}
int unique(LinkedList a , LinkedList b) {
Iterator it = a.iterator() ;
while(it.hasNext()) {
int n = (Integer)it.next();
while(it.hasNext()) {
int n1 = (Integer)it.next();
if()
}
}
return 0;
}
}