Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package nodeGen;
- import java.util.*;
- public class MyStructureUse
- {
- //ג. כתבו במחלקה MyStructureUse פעולה חיצונית בשם createFromInput שמקבלת MyStructure של מספרים ומוסיפה אליו מספרים שנקלטים מהמשתמש עד לקבלת הקלט 999-
- public static void createFromInput (MyStructure value){
- Scanner scan = new Scanner (System.in);
- System.out.println("enter number");
- int num = scan.nextInt();
- while(num != -999){
- value.push(num);
- System.out.println("enter number");
- num = scan.nextInt();
- }
- }
- //ו. כתבו במחלקה MyStructureUse פעולה חיצונית בשם isInStructure המקבלת MyStructure של מספרים ומספר כלשהו X ומחזירה 'אמת' אם X נמצא ב- MyStructure ו 'שקר' אחרת.
- public static boolean isInStructure (MyStructure value , Object x){
- while(value.isEmpty() != true){
- if(value.top() == x){
- return true;
- }
- value.pop();
- }
- return false;
- }
- public static boolean isInStructureSaveOrig (MyStructure value , Object x){
- MyStructure bro = value;
- while(value.isEmpty() != true){
- if(value.top() == x){
- bro.toString();
- return true;
- }
- value.pop();
- }
- bro.toString();
- return false;
- }
- public static MyStructure reverse(MyStructure value){
- MyStructure reversed = new MyStructure();
- while(value.isEmpty() != true){
- reversed.push(value.top());
- value.pop();
- }
- return reversed;
- }
- public static void main(String[] args)
- {
- MyStructure U = new MyStructure();///ג
- //createFromInput(U);
- MyStructure B = new MyStructure();///ג
- createFromInput(B);
- reverse(B);
- System.out.println(B.toString());
- /*System.out.println(U.toString());
- System.out.println( isInStructure(U,8));
- System.out.println(U.toString());
- System.out.println(B.toString());
- System.out.println( isInStructure(B,8));
- System.out.println(B.toString());
- System.out.println( isInStructureSaveOrig(B,-3));
- System.out.println(B.toString());
- */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement