Thursday, July 7, 2011

YesterDay .. ToDay .. Day

Hi all , how are you today .. 
if your bodies has no syntax errors 
.. congrats you are still alive !

if you do not have  run time errors 
so you are still a rational person 

anyway , This question came to my mind , 
How can you go through life pretending that you're happy? 
emm .. my brain was under  debugging  level lool ,but surprise
i found the answer without errors "SHEER UP =D"! 

Dear me just .. change your day style , 
and you will feel how happy you are , 
and no need to pretend anymore ! 
>> Wow ~ how wise am i ! -,-"
so our destination was "The  ZOO" !

this is a snapshot of my trip .. , 




I RECOMMEND TO VISIT IT IN THE WINTER ,,
BECAUSE THE WEATHER WAS UNBELIEVABLE

,

.............................................
as every body knows am a good gamer 
 i like programming and web developing so much. 

am starting now read, learn and try some games coding !
at the end am IT student , and ITSs shouldn't stop working 
because every day there is a new thing showing up so these 
days am busy on this project i hope it is finish before the 
next semester without any errors , am working on it 
to keep my knowledge refreshing , and to  improve my skills 
and knowledge .. so yeah keep this in your mind
" we are all time students "  ..  !  
--> Dr. Mohammed thanks ,

 As you see my agenda is completely full nowadays.
 just ten days left for my trip to Turkey
and am praying to go to Omra this Ramadan ! 
D3watcooom !  i really need to do Omra than anything else ! 


.........................................


Finally ,  these words for my brother , 
i wanna say congratulation Bro .. you grow up 
and you will be a groom Allah 2a Denya ! 
Tommorow is a big day for you .. hope 
God bless you &  bless my rest brothers not only in this day 
but also in your entire life ! love yaa all  .. 
even Saif ! oh this little cutey boy !! i love him :$ !

Saturday, July 2, 2011

my watch list

Heyy yaa , 

This my watch list for my best shows !
some shows i already watched them 
in fact ,there is more ,but those what comes to my mind 
right now , ;)


and more . . . . . .

i recommend to watch them ! 
and give me your feedback if you already 
watched them !

Friday, July 1, 2011

Dubai Mall

Dubai .. Dubai .. Dubai .. Heyaaa 
yesterday , I was in Dubai Mall |  . .


Dubai is beautiful city .. especially for shopping 
and that's exactly what girls fall in love with ;) 
anyway it was long trip .. with  beautiful moments

,


Monday, June 27, 2011

| PictureDotComment |

| PictureDotComment  |

in this corner am gonna to summit picture with small comment 
hope you like it .. 

،,


my bro , he is so Handsome guy lool :p
so he likes take photos for himself 
and also he lets others do that for him ,, Daa -.-"
anyway, this picture taken by my brother 
{ .. not the model ..  , Allah y7f6'hoom

،,

هالصُوره من كليتنا الكورس الماضي رغم أن الكورس الماضي
ما حبيته وايد بس كان في لحظات حلوه الصورتين من تصوير 
ربيعتيه لولي .. 
..
صاحب القميص الأبيض هذا دكتور نيكولاس أو مثل ما أسميه .. بوسينا
هالدكتور فنان وسوالف .. بس ما يعرف يوصل الفكره رغم انه وايد
عبقري و مسوي أول ربورت متحدث باللغة العربية .. إبن سينا ، 
بس حرآم يقولون روح عن كليتنا .. ، يلا الله يوفقـه

و بوالقميص أسود .. دكتور سمير البطاينه.. دكتور سمير بإختصار 
قمه .. صراحه إنسان عمرك ما تحسون انه طلاب عنده .. محترم
بشكل فضيع .. و فالكلاس ما يقول غير درر و مواعظ يعني هب 
بس نتعلم عن المساق أكثر من جي و هب بس دكتور والسلام .. ! 

فكل لحظه من شرح يعطينا نصيحه للحياة بشكل عام بدون ما يطلع
عن محور الدرس أو يضيع وقت مثل حد من دكاتره .. يعلقون تعليقات 
مع إحترامي وااايد اووفل وبااد يحسسوني أن الدوله إغلطت يوم يابتهم 
المفروض الدوله ما تشوف بس الشهادة و الخبرة .. تشوف جان عنده 
كورس تعامل مع الطلبه ، حقيقه ما كد صارلي موقف مع دكتور  مول بس
ما أحب الدكاتره إلي تعليقاتهم واااايد و أوففر و خسارة وقت بس !
يعني نحن بالزور متحملينك .. 
واااالله -.-"

بس هالإنسان فعلا كبير بأخلاقه و مساعدته للبنات .. يعني قلبه مفتوح للكل
يحسسنه صدق مثل بناته هب بعض الدكاتره يقولون جي و عقب كلاسين
أقول لو إنته أبويه جان إنتحرت ^.^ ! بس دكتور سمير من الناس 
إلي يغيروني للأفضل الأفضل يمكن من غير ما يدري
.. و عسا الله يحفظه لأهله و يوفقه في الدنيا و الآخره


،,
 Robert Downy JR 
Oh yaaa ! i like this actor 

هالمُمثل عجييب ، ما أحسه يمثل لو أن كل الممثلين جذابين .. يعني لايرز
بس هالممثل شخصيته وحده جي خبال ع رزانه بس صدق إلي يبى يشوف فلم
يطالع فلم من أفلامه أنا هب من النوع إلي يمجد الممثلين
المهم يعيبوني الممثلين الاجانب يعيشون قصة الفلم و العرب هب وايد 
 وياهم  أصلا ما دانيهم أحسهم سخافه من الخاطر ..


،,


next time I'll write small comments .. this time  just a provaaa !  
iShrne ..  

Sunday, June 26, 2011

ZOlO, intresting java problem with the solution !

Hi yaaa / this is an problem that i solved during the Data Structure course , 
was an assignment out of 20 , but it was interesting to solve .. ,


،,

A new race was identified to live on ZOLO, a newly discovered planet. The DNA of these people is much simpler than that of human beings. Each trace is coded by a square of size n x n where n is an even number and 2  n  50. Each cell of the square is either 0 (OFF) or 1 (ON). Scientists discovered that the  relationship between two persons is based on the similarity between the cells of the person with the smaller square trace and the cells of an equal size square centered in the middle of the trace of the person with larger square trace. (the two traces can be of equal size). The relationship is based on the following findings:


• If the number of ones of the corresponding rows in the compared traces are equal (e.g. row#0 of first trace with row#0 of the second trace, row#1 of the first trace with row#1 of the second trace, and so on), then they are related from their mothers’ sides.

• If the number of ones of the corresponding columns in the compared traces are equal (e.g. column#0 of first trace with column#0 of the second trace, column#1 of the first trace with column#1 of the second trace, and so on), then they are related from their fathers’ sides.

• If the number of ones of the corresponding rows and the corresponding columns in the compared traces are equal, then they are related from both their mothers sides and fathers sides.


For example, suppose, two persons X and Y have the following traces, respectively:


0 1 1 1 1 0
0 0 0 0 0 0
1 1 1 1 1 0
1 1 1 0 0 0
1 1 1 0 1 1
1 1 1 1 1 1

1 1 0 1
1 1 1 1
1 0 0 0
0 1 0 0

We say X and Y are related from their fathers’ sides since the number of ones of the corresponding columns are equal.


Input

 
The input data is stored in file “digital.in”. The first line of the input file contains a single integer t (1  t  10), the number of test cases, subsequent lines correspond to the t test cases.
For each test case, the first line contains the number of rows in the small trace person. The subsequent line(s) contains data to fill the cells of that person row by row. Then, a line that contains the number of rows of the larger or equal size trace person. The subsequent line(s) contains data to fill the cells of the person with larger or equal size trace row by row.


Output
The output should be stored in file “digital.out”. The output should contain one line for each test case (as shown in the sample output below) indicating the type of relationship between the two persons as follows: Mothers’ sides, Father’s sides, Both sides, or Not related

Sample Input


The following input file contains 2 test cases. The first test case corresponds to 4x4 and 6x6 traces of two persons, and the second test case corresponds to 2x2 and 4x4 traces of another couple of persons.

2

4
0 0 0 0
1 1 1 1
1 1 0 0
1 1 1 1
6
0 1 1 1 1 0
0 0 0 0 0 0
1 1 1 1 1 0
1 1 1 0 0 0
1 1 1 1 1 1
1 1 1 1 1 1
2
1 1
0 1
4
1 1 1 1
1 1 1 1
1 0 0 0
0 0 0 1

Sample Output


Case 1: Both sides
Case 2: Not related





،, 
there is another solution i will post it soon. 
if you have any question be free to ask .. ! 
ps : i love programming ! °\(^▿^)/°
،, 
------------------------------------------------------------------------------------------[CODE ] !
public class Main { public static void main(String[] args) { Scanner sc =null; PrintStream out = null; try{ sc= new Scanner (new File("digital.in")); out = new PrintStream(new File("digital.out")); int cases , count =1 ; cases= sc.nextInt(); while(cases>= count){ out.print("Case "+count); int size1 = sc.nextInt(); int A[][] = new int [size1][size1]; for(int i=0 ; i<size1 ; i++){ // reading 1st metrix for(int j=0 ; j<size1 ; j++){ A[i][j]= sc.nextInt(); } } int size2 = sc.nextInt(); int B[][] = new int [size2][size2]; for(int i=0 ; i<size2 ; i++){ // reading 2nd metrix for(int j=0 ; j<size2 ; j++){ B[i][j]= sc.nextInt(); } } if(MotherSide(A,B) == true && FatherSide(A,B)==true) out.print(": Both sides"); else if(MotherSide(A, B) == true) out.print(": Mother sides"); else if(FatherSide(A, B) == true) out.print(": Father sides"); else out.print(": Not related"); count++; out.println(); } }catch(Exception e){ System.out.println(" Exception : "+ e); } sc.close(); out.close(); } public static boolean MotherSide(int Small[][], int Big[][]){ boolean found = true; int ones[] = new int [Small.length]; for(int i=0 ; i<Small.length ; i++ ){ int onesCount = 0 ; for(int j =0 ; j<Small.length ; j++){ if (Small[i][j]==1) onesCount = onesCount +1; } ones[i]= onesCount; } int i=0; while(i<Small.length && found == true ){ int onesCount = 0 ; for(int j =0 ; j<Small.length ; j++){ if (Big[i+(Big.length - Small.length)/2][j+(Big.length - Small.length)/2]==1) onesCount = onesCount +1; } if(ones[i]== onesCount) i++; else found = false; } return found; } public static boolean FatherSide(int Small[][], int Big[][]){ boolean found = true; int ones[] = new int [Small.length]; for(int i =0 ; i<Small.length ; i++ ){ int onesCount = 0 ; for(int j =0 ; j<Small.length ; j++){ if (Small[j][i]==1) onesCount = onesCount +1; } ones[i]= onesCount; } int i=0; while(i<Small.length && found == true ){ int onesCount = 0 ; for(int j =0 ; j<Small.length ; j++){ if (Big[j+(Big.length - Small.length)/2][i+(Big.length - Small.length)/2]==1) onesCount = onesCount +1; } if(ones[i]== onesCount) i++; else found = false; } return found; } }


Wednesday, June 22, 2011

مصر .. مصر .. مصر


هالصوره للامَانه ريتها في لابتوب خويَه .. كان في مصَر مرَه تبون الصراحه 
أنا ما كان لي ميول لمصر ولاهل مصر و أي شي يخص مصر يعني طاريها يمر
مرورالكرام حتى يوم سووا مظاهرات على حسني مبارك كان الموضوع عادي
بالنسبه لي  .. لأن للأسف المصريين عندنا في الدوله مشوهين صورتهم .. ! 

للأمانه للأمانه ما كد عرفت مصري أو سمعت عن مصري إلا له سوابق 
أو أنه فيه طمع و حيله و إحتيال .. حتى ما كد تابعت حتى مسلسل مصري 
بس أنا أدري من داخليه ما اكره المصريين و لو أقابل إنسان مصري تعجبني 
شخصيته راح أغير وجهة نظريه 100 % عن مصر و رمستيه هب تقليل بأهل 
مصر انا أدري في ناس ما منهم إثنين .. لكن للأسف كل المصرين إلي تعاملت
وياهم أو عرفتهم او حتى سمعت عنهم كانوا دوم مستوى التعامل الطبيعي  !
مما خلف لي ردة الفعل هاي  .. بس الظاهر مصر دوله حلوه
من الصوره إلي شفتها عند خواني 


،

و دامت ديار العرب عامره بالمسرات والأفراح 
و الله يزيح عنها كل ثورة و حاكم ظالم طاغي 



خربشَات إلكترونيَه


 السَلام عليكُم و رحَمة الله و بركَاتَه 
ما أدَريْ إذا حَد بيقرأ هالزاويَه .. بَسْ أتَمنى إلي بينكَتب راح يَأثر عَلَى حَد
 
 Scorpio2.jpg
 
بُرج العقَربْ .. أنَا أبَداً أبداً أبَداً ما أصَدِقْ بالأبْراجْ ولا عمريَه فَكَرتْ أفتح شَي يَخص الأبراج
أصَلا ما عرفت شُو بِرجِي إلا  من أيَام بسْ .. ، إنزين فِي عِندنا دكتور درسنَي هالكورسْ 
يسمُونَه أحَمد السَريْ .. بخصوص الدكاتره راح أسوي بوست كامل لكل دكتور درسَني ..، 
أو دكتوره فالجَامَعه .. بَس مستحِيل أسوي بوست للي درسَني في المدرسَه لأن للأسف 
ما ضافن لي شَيْ مع إحترامي .. دآآآآآ -.-"! غير إلي مكتُوب فالكتب و حفظن يا بنات .. 
 
آني وآي وين كنَا هيه عند  السَري .. يالس يشرح و فجأه قالي
إنتي شو برجج  ؟ .. جَآن أطالع ذيج النظره البريئَه ؟ 
هَآآآآه ! ما أعرف ؟ سأل الثانيه و الثالثه و إلخ .. ، قال عقب أن 
الموضوع هَب أنه شو بيصيرلجْ باجر ولا إلي عقبه (عيلْ؛  .. 
الموضوع شخصيتج شُو من خلال هالبرج تنعرفيِن .. ( هِيه جِي السَالفَه ؛
و أونه هناك دراسات سيكولوجيه و من هالرمسَه قَامت خويتكم تنبش في هالنت .. 
من زود الفضول  حطيت تاريخ ميلادي .. برج العقرب .. تعيبت تبون الصدق  ! 
 
ياني فضول أكبر .. و أقوم لكم و أقرأ من أول حرف لتالي حرف
تمعنت بالرمسه .. وأسأل نفسي إلي كتب هالرمسه كنَه يعرفني 
بس ما بقول حق المعرفه لأنه يتكلم بشكل عام .. لكن صدقا 
نسبة 90 - 87% هالحدود كلامهم صح .. هآآي أنا كيف ما أدري
يعني نسبه أبدا هب سهله ،
 .. 

و في أشياء مستحيل تكون فيني يمكن أوكي تكون بس هبْ
بالطريقه إلي وصفوها .. قاصر يقولون أني سبب أحداث 11 سبتمبر 
 أو مستحيل لأنها خارج نطاق أخلاقياتنا 

 
 إذا تتوقف حالة هذا الإنسان الصحية إلى حد بعيد على مزاجه وظروفه المعيشية. قد يصاب بالمرض بسبب الإفراط في الطعام والشراب
والتدخين وأحيانا الإدمان على المخدرات والعقاقير، ولكنه يستطيع الشفاء أيضا بفعل إرادته القوية. هذا وعليه أن يحتاط لنفسه من خطر
النار والمتفجرات والغازات السامة والإشعاعات الذرية وغير ذلك من العوامل التي تندفع نحوها وتنجذب إليها طبيعة التحدي فيه.
 
لكن 3\4 الأشياء نعم أنها فيني مثل .. ، و باقي الرمسَه
 
كان علماء الفلك قديما يرمزن إلى مواليد برج العقرب بواسطة أفعى أو ضب أو نسر في بعض الأحيان، وسبب ذلك يعود ولا ريب 
 إلى تعدد الأدوار والشخصيات التي ينجح في أدائها. فهو بحسب الظروف والأوضاع – تارة عقرب سام يؤذي لمجرد اللذة ولا يتورع
 حتى في أذية نفسه، وطورا ضب قاصر لئيم يعيش في الظلمات والخوف، وأحيانا يتحول العقرب أو الضب إلى نسر عظيم يحلق
في الأجواء متحديا الفشل والمرض والفقر، حتى الموت نفسه. هنا يبلغ الإنسان العقرب أسمى درجات الشجاعة والتفاؤل والعظمة.

.. لكن .. في جمله وايد إنتابني شعور غريب تجاهها .. وذلك اليوم أتكلم ويا ربيعتيه عن هالموال .. و قلت لها يقولون أني
أم ويهين لغير هذا مستحيل يكون فيني أنا إنسانه الصراحه بذاتها تقولي يرحم أمج عطيني من صراحَتِجْ  ..
 
 ! الي أبى أوصله  أظنيه هم قصدهم أنه في خاطريه شي بس أطلعه بشي ثاني 
فعلا فيني هالصفه .. فيني صفة عكس الرياء .. كيف .. الرياء شو يعني .. يعني انك من داخل 
إنسان مب زين و تراوي الناس أنك يخزي العين .. انا من داخليه وايد أشياء حلوه وتكون أفعال
بينيه و بين إلي خلقنيه .. لكن جدام الناس أي شي فيه الخير أحيانا أسوي عمريه في لا مبالاه كبيره 
خصوصا بين أهليه .. ، ليش والله أعلم بخوافي الأمور .. بس هالصفه مش دايما ولا نادرا يعني 
مش انها شايعه فيني في كل شي ولا انها تستوي مره في السنه لكن في مواقف معينه 
فعلا أكون بذي الطريقَه ، في مواقف عادي .. يمكن أصلا أن أحس لو أسوي شي زين 
و الناس دروا إييني وسواس قهري انه يكون رياء .. فيمكن هو هالسبب !
  .. ، 

بس باقي رمستهم جنهم إلا يعرفوني عز المعرفه ، بس اكرر أنا ما أصدق بالأبراج و تكهناتهم  الغبيه
بس هذا حاله حال أي تحليل نفسي .. ممكن حد يعرفه عنك من طريقة أكلك كتابتك نظرتك و الخ ! 
و كان الله غفورا رحيما .. و الله يغفرلي على الزله و يمكن هالبوست ما فيه فايده بس لكم كقراء 
و أنا أعتذر على هالشي .. بس بالنسبه لي كان سبب لشي و حبيت أدونَه 
و شكراً جزيلاً جميعاً ..  ،


Thursday, June 9, 2011

Some Stack Methods

Good Morning !
how are you ? Am starving i did not eat my breakfast yet ^^"
any how , as usual today i studied stack , and later I'll study Queue & linkedList.
this is source contains following methods :
  • copy stack 
  • store element without changing the Stack ( the last one / second one )
  • [Advanced] - pick by position
emm the source code is not well organize but method are easy to understand
any way if you've any question be free to ask. :)

 
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package operationonstack; import java.util.Scanner; import java.util.Stack; /** * * @author USER */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { // Set secondElement to the second element in myStack, //leaving myStack without its original top two elements. Scanner sc = new Scanner(System.in); char Element; char store; String he = sc.next(); char h = he.charAt(0); Stack A = new Stack(); Stack B = new Stack(); char a[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'I'}; if (h == 'b') { storeELE(A, a); } if (h == 'S') { for (int i = 0; i < a.length; i++) { A.push(a[i]); } System.out.println("A: " + A); while (!A.isEmpty()) { B.push(A.peek()); A.pop(); } System.out.println("B: " + B); store = (Character) B.peek(); B.pop(); Element = (Character) B.peek(); System.out.println("Element: " + Element); A.push(store); while (!B.isEmpty()) { A.push(B.peek()); B.pop(); break; } System.out.println("A still w/o any changes: " + A); } if (h == 'C') { copyStack(A, a); stackPostionTemp(A, 2); } // -------------------------------------------------------------------- // // Set bottom equal to the bottom element in myStack, leaving myStack empty // } public static Stack storeELE(Stack C, char aR[]) { Stack D = new Stack(); char Elemen = ' '; char mem; for (int i = 0; i < aR.length; i++) { C.push(aR[i]); } System.out.println("C: " + C); while (!C.isEmpty()) { D.push(C.peek()); C.pop(); } System.out.println("D: " + D); mem = (Character) D.peek(); System.out.println("bottom: " + mem); while (!D.isEmpty()) { C.push(D.peek()); D.pop(); } System.out.println("C still w/o any changes: " + C); return C; } public static Stack copyStack(Stack C, char a[]) { Stack D = new Stack(); Stack T = new Stack(); for (int i = 0; i < a.length; i++) { C.push(a[i]); } System.out.println("Stack that you wanna copy it: " + C); while (!C.isEmpty()) { D.push(C.peek()); C.pop(); } while (!D.isEmpty()) { T.push(D.peek()); D.pop(); } System.out.println("Copy of the Stack: " + T); while (!T.isEmpty()) { D.push(T.peek()); T.pop(); } while (!D.isEmpty()) { C.push(D.peek()); D.pop(); } System.out.println("The Orginal Stack : " + C); return C; } //PICK BY : POSTION Method public static Stack stackPostionTemp(Stack c, int pos) { Stack D = new Stack(); Stack temp = new Stack(); char E = ' '; while(!c.isEmpty()) { temp.push(c.peek()); c.pop(); } for (int i = 1; i < temp.size(); i++) { if (pos == i) { for (int k = 1; k <=pos; k++) { D.push(temp.peek()); temp.pop(); } System.out.println("Temp Stack is: " + D); E = (Character) D.peek(); D.pop(); System.out.println( "The Value you wanna pick is : "+E); while(!D.isEmpty()) { temp.push(D.peek()); D.pop(); } while(!temp.isEmpty()) { c.push(temp.peek()); temp.pop(); } } } System.out.println("the Stack after: " + c); return c; } public static Stack PoP(Stack c, int pos) { Stack D = new Stack(); char E = ' '; for (int i = 1; i < c.size(); i++) { if (pos == i) { for (int k = 1; k <=pos; k++) { D.push(c.peek()); c.pop(); } System.out.println("Temp Stack is: " + D); E = (Character) D.peek(); D.pop(); System.out.println( "The Value you wanna pick is : "+E); for (int k = 1; k <=D.size(); k++) { c.push(D.peek()); D.pop(); } } } System.out.println("the Stack after: " + c); return c; } } // copy - Right iShrne - 2011

Wednesday, June 8, 2011

Binary Search Tree Implementation by iShrne

 السَلام عليكُم و رَحمَة الله و بَركَاتُه
 ، ,


Hi every body | :)
 i was study , and i wrote this program as a review for the final exam.
، .. This complete program contains the main methods of binary search tree i wrote them so please
|| IF you Have any question be free to ask.  ^^


Source Code Content:
  1. Insert method
  2. Remove method
  3. Search method
  4. Find min ( return reference )
  5. Count number of  nodes less than given value
  6. Count  number of nodes greater than given value
  7. Check if it is Binary Search Tree or not.
  8. Count Node recursively / non- recursively.
  9. Traversal ( InOrder/PostOrder/PerOrder)
  10.  Single Parent Count
  11. Leave Count
  12. Destroy Tree
  13. Copy Tree
  14. Max
  15. If Two Trees are same ( as a nodes not content ) .  
------------------------------------------------------------------||


[ Main Class ]

import java.util.Scanner; //-- All Rights Reserved to iShrne - 2008 student in United Arab Emirates -- // public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); // Creating a binary search tree Done binarysearchtree T = new binarysearchtree(); binarysearchtree D = new binarysearchtree(); intElement x = new intElement(); intElement y = new intElement(); intElement z = new intElement(); intElement w = new intElement(); intElement s = new intElement(); intElement d = new intElement(); int numElt, num, numu, numElte; while (true) { System.out.println("Enter first letter of the task that you wanna run"); System.out.println(); String choice = input.next(); int ch = choice.charAt(0); switch (ch) { case 's': System.out.print("print"); T.printTree(); break; // Inserting a number in the tree case 'i': System.out.println("-----|There are two tree availble , T and D|----"); String tree = input.next(); char cha = tree.charAt(0); if (cha == 'T') { System.out.println("-----|How many elements do you want to insert in the [ T ] |---- "); numElt = input.nextInt(); for (int i = 1; i <= numElt; i++) { System.out.println("enter the next element TTree"); num = input.nextInt(); x.setNum(num); T.insert(x); } } else if (cha == 'D') { System.out.println("-----|How many elements do you want to insert in the [ D ] |---- "); numElte = input.nextInt(); for (int i = 1; i <= numElte; i++) { numu = input.nextInt(); d.setNum(numu); D.insert(d); D.printTree(); } } else { System.out.println("|| F A I L D / Try Again ||"); } System.out.println(); break; case 'f': System.out.println(" search "); System.out.println("Enter value to find: "); int numb = input.nextInt(); y.setNum(numb); if (T.search(y)) { System.out.println(" :found"); } else { System.out.println(" :not found"); } System.out.println(); break; case 'T': if (T.SimilarTree(T, D)) { System.out.println(" :TRUE"); } else { System.out.println(" :not SAME"); } System.out.println(); break; // Deleting a number from the case 'r': System.out.println(" Deleting a number from the "); System.out.println("Enter value to delete"); int numba = input.nextInt(); z.setNum(numba); if (T.search(z) == true) { T.deleteNode(z); T.printTree(); } else { System.out.println(" :not found"); } System.out.println(); break; // Traversing the tree case 't': System.out.println(" Traversing the tree "); System.out.println(" "); System.out.println("Enter 1 , 2 or 3 of trevarsing way"); int choi = input.nextInt(); if (choi == 1) { T.inorderTraversal(); } else if (choi == 2) { T.postorderTraversal(); } else if (choi == 3) { T.preorderTraversal(); } System.out.println(); break; // Counting the number of nodes in the tree case 'c': System.out.println(" Counting the number of nodes in the tree "); System.out.println(); T.counter(); break; //Counting the number of leaf nodes in the tree case 'l': System.out.println(" Counting the number of leaf nodes in the tree "); System.out.println(T.treeLeavesCount()); System.out.println(); break; // determining whether the binary search tree is a binary search tree. case 'D': System.out.println(" determining whether the [ binary search tree is a binary ] search tree"); System.out.println(T.isBST()); System.out.println(); break; // Counting the number of nodes in the tree whose value is greater than a given value V. case 'G': System.out.println("Counting the number of nodes in the tree whose value is [greater] than a given value V"); System.out.println("Enter a value:"); int numbaa = input.nextInt(); w.setNum(numbaa); System.out.println("there are " + T.FinM(w)); System.out.println(); break; case 'L': System.out.println("Counting the number of nodes in the tree whose value is [Less] than a given value V"); System.out.println("Enter a value:"); int numbaaa = input.nextInt(); s.setNum(numbaaa); System.out.println("there are " + T.FinL(s)); System.out.println(); break; // non recursive function Min to find the smallest value in a BST case 'M': System.out.println("non recursive function Min to find the smallest value in a BST"); T.min(); System.out.println(); break; case 'P': System.out.println("Count Single Parent"); System.out.println(T.singleParentCount()); System.out.println(); break; default: System.out.println("INVALID / TRY ANOTHER CHARACTER"); System.out.println(); break; } System.out.println("END"); System.out.println(); //break; } } }


[ Data Element Class ]

public abstract class DataElement { public abstract boolean equals(DataElement otherElement); //Method to determine whether two objects contain the //same data. //Postcondition: Returns true if this object contains the // same data as the object otherElement; // otherwise, it returns false. public abstract int compareTo(DataElement otherElement); //Method to compare two objects. //Postcondition: Returns a value < 0 if this object is // less than the object otherElement; // Returns 0 if this object is the same as // the object otherElement. // Returns a value > 0 if this object is // greater than the object otherElement. public abstract void makeCopy(DataElement otherElement); //Method to copy otherElement into this object. //Postcondition: The data of otherElement is copied into // this object. public abstract DataElement getCopy(); //Method to return a copy of this object. //Postcondition: A copy of this object is created and // a reference of the copy is returned. }


[ intElementClass ]

/** * * @iShrne | iShrne | iShrne | ---- ! */ public class intElement extends DataElement{ protected int num; //default constructor public intElement() { num = 0; } //constructor with parameters public intElement(int x) { num = x; } //copy constructor public intElement(intElement otherElement) { num = otherElement.num; } //Method to set the value of the instance variable num //Postcondition: num = x; public void setNum(int x) { num = x; } //Method to return the value of the instance variable num //Postcondition: The value of num is returned public int getNum() { return num; } public boolean equals(DataElement otherElement) { intElement temp = (intElement) otherElement; return (num == temp.num); } public int compareTo(DataElement otherElement) { intElement temp = (intElement) otherElement; return (num - temp.num); } public void makeCopy(DataElement otherElement) { intElement temp = (intElement) otherElement; num = temp.num; } public DataElement getCopy() { intElement temp = new intElement(num); return temp; } public String toString() { return String.valueOf(num); } }


[BS class  ]

import java.util.Stack; /** * * @iShrne | iShrne | iShrne | iShrne | iShrne | ---- ! */ public class binarytree { protected class BinaryTreeNode { DataElement info; BinaryTreeNode llink; BinaryTreeNode rlink; } protected BinaryTreeNode root; protected BinaryTreeNode root2; public binarytree() { root = null; } public int singleParentCount() { return singleParentCount(root); } public void printTree() { printTree(root); System.out.println(); } //copy constructor public binarytree(binarytree otherTree) { if (otherTree.root == null) //otherTree is empty { root = null; } else { root = copy(otherTree.root); } } public boolean isEmpty() { return (root == null); } public void inorderTraversal() { inorder(root); } public boolean isBST() { return isBST(root); } public DataElement min() { return min(root); } public void preorderTraversal() { preorder(root); } public void postorderTraversal() { postorder(root); } public int treeLeavesCount() { return leavesCount(root); } public void destroyTree() { root = null; } public void copyTree(binarytree otherTree) { if (this != otherTree) //avoid self-copy { root = null; if (otherTree.root != null) //otherTree is nonempty { root = copy(otherTree.root); } } } private BinaryTreeNode copy(BinaryTreeNode otherTreeRoot) { BinaryTreeNode temp; if (otherTreeRoot == null) { temp = null; } else { temp = new BinaryTreeNode(); temp.info = otherTreeRoot.info.getCopy(); temp.llink = copy(otherTreeRoot.llink); temp.rlink = copy(otherTreeRoot.rlink); } return temp; }//end copy private void inorder(BinaryTreeNode p) { if (p != null) { inorder(p.llink); System.out.print(p.info + " "); inorder(p.rlink); } } private void preorder(BinaryTreeNode p) { if (p != null) { System.out.println(p.info + " "); inorder(p.llink); inorder(p.rlink); } } private void postorder(BinaryTreeNode p) { if (p != null) { inorder(p.llink); inorder(p.rlink); System.out.println(p.info + " "); } } private int leavesCount(BinaryTreeNode p) { if (p == null) {// BASIC CASE return 0; } else if (p.llink == null && p.rlink == null) { // BASIC CASE return 1; } else { return leavesCount(p.llink) + leavesCount(p.rlink); } } private int singleParentCount(BinaryTreeNode p) { if (p == null) { return 0; } else if (p.llink == null && p.rlink != null) { return 1; } else if (p.llink != null && p.rlink == null) { return 1; } else { return singleParentCount(p.llink) + singleParentCount(p.rlink); } } private void printTree(BinaryTreeNode node) { if (node == null) { return; } // left, node itself, right printTree(node.llink); System.out.print("[ " + node.info + " ]" + " "); printTree(node.rlink); } public int FinM(DataElement p) { BinaryTreeNode current = root; return conutMore(current, p); } public int FinL(DataElement p) { BinaryTreeNode current = root; return countLess(current, p); } /** Finds the min value in a non-empty binary search tree. */ public static int conutMore(BinaryTreeNode p, DataElement b) { if (p == null) { return 0; } else if (p.info.compareTo(b) > 0) { return 1 + countNode(p.rlink) + conutMore(p.llink, b); } else if (p.info.equals(b)) { return countNode(p.rlink); } else { return conutMore(p.rlink, b); } } public static int countLess(BinaryTreeNode p, DataElement b) { if (p == null) { return 0; } else if (p.info.compareTo(b) < 0) { return 1 + countNode(p.llink) + countLess(p.rlink, b); } else if (p.info.equals(b)) { return countNode(p.llink); } else { return countLess(p.llink, b); } } private DataElement min(BinaryTreeNode p) { BinaryTreeNode current = p; while (current.llink != null) { current = current.llink; } System.out.println(current.info); return (current.info); } private boolean isBST(BinaryTreeNode p) { if (p == null) { return true; } else if (p.llink == null && p.rlink == null) { return true; } else if (p.llink == null && p.rlink != null) { if (p.info.compareTo(p.rlink.info) < 0) { return isBST(p.rlink); } else { return false; } } else if (p.llink != null && p.rlink == null) { if (p.info.compareTo(p.llink.info) > 0) { return isBST(p.llink); } else { return false; } } else if (p.info.compareTo(p.llink.info) > 0 && p.info.compareTo(p.rlink.info) < 0) { return isBST(p.llink) && isBST(p.rlink); } else { return false; } } // public void counter() { int count = 0; Stack stack = new Stack(); BinaryTreeNode curr = root; while ((curr != null) || (!stack.empty())) { if (curr != null) { stack.push(curr); curr = curr.llink; } else { curr = (BinaryTreeNode) stack.peek(); count++; stack.pop(); curr = curr.rlink; } } System.out.println(count); System.out.println(); } public static int max(BinaryTreeNode p) { int count = 0; BinaryTreeNode current = p; while (current.rlink != null) { count++; current = current.llink; } System.out.println(count); return (count); } public static int countNode(BinaryTreeNode p) { if (p == null) { return 0; } else { return 1 + countNode(p.llink) + countNode(p.rlink); } } public boolean SimilarTree(binarysearchtree p, binarysearchtree k) { BinaryTreeNode a = p.root; BinaryTreeNode b = k.root; if (a == b) { return true; } else if (countNode(a.llink) == countNode(b.llink) && (countNode(a.rlink) == countNode(b.rlink))) { return true; } else { return false; } } }







[ BST class ]
/** * * @author USER */ public class binarysearchtree extends binarytree{ //default constructor //Postcondition: root = null; public binarysearchtree() { super(); } //copy constructor public binarysearchtree(binarysearchtree otherTree) { super(otherTree); } public boolean search(DataElement searchItem) { BinaryTreeNode current; boolean found = false; if (root == null) { System.out.println("Cannot search an empty tree."); } else { current = root; while (current != null && !found) { if (current.info.equals(searchItem)) { found = true; } else if (current.info.compareTo(searchItem) > 0) { System.out.println("path "+current.info); current = current.llink; } else { System.out.println("path "+current.info); current = current.rlink; } } } System.out.println(found); return found; }//end search // Method to find the element and return the value of this elment. //Method to insert insertItem in the binary search tree. //Postcondition: If no node in the binary search tree has // the same info as insertItem, a node with // the info insertItem is created and inserted // in the binary search tree. public void insert(DataElement insertItem) { BinaryTreeNode current; BinaryTreeNode trailCurrent = null; BinaryTreeNode newNode; newNode = new BinaryTreeNode(); newNode.info = insertItem.getCopy(); newNode.llink = null; newNode.rlink = null; if (root == null) { root = newNode; } else { current = root; while (current != null) { trailCurrent = current; if (current.info.equals(insertItem)) { System.err.print("Item is already in the list"); return; } else if (current.info.compareTo(insertItem) > 0) { current = current.llink; } else { current = current.rlink; } } if (trailCurrent.info.compareTo(insertItem) > 0) { trailCurrent.llink = newNode; } else { trailCurrent.rlink = newNode; } } }//end insert //Method to delete deleteItem from the binary search tree //Postcondition: If a node with the same info as deleteItem // is found, it is deleted from the binary // search tree. public void deleteNode(DataElement deleteItem) { BinaryTreeNode current; BinaryTreeNode trailCurrent; boolean found = false; if (root == null) { System.err.println("Cannot delete from the empty tree."); } else { current = root; trailCurrent = root; while (current != null && !found) { if (current.info.equals(deleteItem)) { found = true; } else { trailCurrent = current; if (current.info.compareTo(deleteItem) > 0) { current = current.llink; } else { current = current.rlink; } } }//end while if (current == null) { System.out.println("The delete item is not in the tree."); } else if (found) { if (current == root) { root = deleteFromTree(root); } else if (trailCurrent.info.compareTo(deleteItem) > 0) { trailCurrent.llink = deleteFromTree(trailCurrent.llink); } else { trailCurrent.rlink = deleteFromTree(trailCurrent.rlink); } } } }//end deleteNode private BinaryTreeNode deleteFromTree(BinaryTreeNode p) { { BinaryTreeNode current; BinaryTreeNode trailCurrent; if (p == null) { System.err.println("Error: Can not delete null."); } else if (p.llink == null && p.rlink == null) { p = null; } else if (p.llink == null) { p = p.rlink; } else if (p.rlink == null) { p = p.llink; } else { current = p.llink; trailCurrent = null; while (current.rlink != null) { trailCurrent = current; current = current.rlink; } p.info = current.info; if (trailCurrent == null) { p.llink = current.llink; } else { trailCurrent.rlink = current.llink; } } return p; } } }//end deleteFromTree


Hope this is useful material to share , good luck to you all.
iShrne.