• Embed Doc
  • Readcast
  • Collections
  • CommentGo Back
 
רועש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);}
of 00

Leave a Comment

You must be to leave a comment.
Submit
Characters: ...
You must be to leave a comment.
Submit
Characters: ...