רועש4.)האלול י"ע( תיביטקודניא הטישב ךרעמב רתויב םילודגה םירביא ינש לש שופיחתינסחמו ךרעמ לש רביא ליכמ תמוצ לכ ,םיתמצ לש תרשוקמ המישר םינוב
import
java.util.*;
public
class
MaxMaxInduction {
private
class
Node{// inner class Node
int
num;Stack<Integer>st;
public
Node(
int
num){
this
.num= num; st=
new
Stack<Integer>();}}// data items
int
arr[],size;
// constructor
public
MaxMaxInduction(
int
a[]){size= a.length;
arr=
new
int
[size];
for
(
int
i=0; i<size; i++){
this
.arr[i] = a[i];}}
public
void
maxMax2(){// Start Linked ListLinkedList<Node> list =
new
LinkedList<Node>();
for
(
int
i=0; i<size; i++){Node n =
new
Node(arr[i]);list.add(n);}// Pair Process
int
i=0, comp=0;
while
(list.size()>1){Node n = list.get(i);Node n1 = list.get(i+1);comp++;
if
(n.num<n1.num){
n1.st.push(n.num);
list.remove(n);}
else
{n.st.push(n1.num);
list.remove(n1);}i = i + 1;
if
(i==list.size() || i==list.size()-1) i = 0;}Node n = list.get(0);
int
max1 = n.num;
int
max2 = n.st.pop();
while
(!n.st.isEmpty()){
int
number = n.st.pop();comp++;
if
(max2<number) max2 = number;}System.
out
.println("max1 = "+max1+" ,max2 = "+max2);
System.
out
.println("comp = "+comp);}
Leave a Comment