Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. package nodeGen;
  2. import java.util.*;
  3. public class MyStructureUse
  4. {
  5. //ג. כתבו במחלקה MyStructureUse פעולה חיצונית בשם createFromInput שמקבלת MyStructure של מספרים ומוסיפה אליו מספרים שנקלטים מהמשתמש עד לקבלת הקלט 999-
  6. public static void createFromInput (MyStructure value){
  7. Scanner scan = new Scanner (System.in);
  8. System.out.println("enter number");
  9. int num = scan.nextInt();
  10.  
  11. while(num != -999){
  12. value.push(num);
  13. System.out.println("enter number");
  14. num = scan.nextInt();
  15.  
  16. }
  17. }
  18.  
  19. //ו. כתבו במחלקה MyStructureUse פעולה חיצונית בשם isInStructure המקבלת MyStructure של מספרים ומספר כלשהו X ומחזירה 'אמת' אם X נמצא ב- MyStructure ו 'שקר' אחרת.
  20. public static boolean isInStructure (MyStructure value , Object x){
  21.  
  22. while(value.isEmpty() != true){
  23. if(value.top() == x){
  24. return true;
  25. }
  26. value.pop();
  27. }
  28. return false;
  29. }
  30.  
  31.  
  32. public static boolean isInStructureSaveOrig (MyStructure value , Object x){
  33. MyStructure bro = value;
  34. while(value.isEmpty() != true){
  35. if(value.top() == x){
  36. bro.toString();
  37. return true;
  38. }
  39. value.pop();
  40. }
  41. bro.toString();
  42. return false;
  43. }
  44.  
  45. public static MyStructure reverse(MyStructure value){
  46. MyStructure reversed = new MyStructure();
  47. while(value.isEmpty() != true){
  48. reversed.push(value.top());
  49. value.pop();
  50. }
  51. return reversed;
  52. }
  53.  
  54.  
  55. public static void main(String[] args)
  56. {
  57. MyStructure U = new MyStructure();///ג
  58. //createFromInput(U);
  59. MyStructure B = new MyStructure();///ג
  60. createFromInput(B);
  61. reverse(B);
  62. System.out.println(B.toString());
  63. /*System.out.println(U.toString());
  64. System.out.println( isInStructure(U,8));
  65. System.out.println(U.toString());
  66. System.out.println(B.toString());
  67. System.out.println( isInStructure(B,8));
  68. System.out.println(B.toString());
  69. System.out.println( isInStructureSaveOrig(B,-3));
  70. System.out.println(B.toString());
  71. */
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement