محمد الحربي نشر 27 سبتمبر 2020 أرسل تقرير مشاركة نشر 27 سبتمبر 2020 اقتباس رابط هذا التعليق شارك على الشبكات الإجتماعية More sharing options...
1 ayoubridouani نشر 27 سبتمبر 2020 أرسل تقرير مشاركة نشر 27 سبتمبر 2020 لا أحب حل التمارين للطلاب عكس أن أتابع معه طرف بطرف حتى الوصول للنتيجة المطلوبة لكن لا عليك سأساعدك في حل التمرين حتى تأخده كمرجع. ملاحظة: لا أفهم ما علاقة queue الموجودة بالسؤال واحد مع stack هناك فرق شاسع بين كلاهما. // Java code for stack implementation import java.io.*; import java.util.*; class Main { // Question1: create stack list static Stack<Integer> stack_create() { return new Stack<Integer>(); } // Question2: Display the stack static void stack_display(Stack<Integer> stack) { System.out.println("Elements on stack: " + stack); } // Question3: count size of the stack static void stack_count(Stack<Integer> stack) { System.out.println("Size of the stack is: " + stack.size()); } // Question4: Insert new nodes on the stack static void stack_push(Stack<Integer> stack) { Scanner sc = new Scanner(System.in); System.out.print("Input the number of nodes: "); int N = sc.nextInt(); for(int i = 0; i < N; i++) { System.out.print("Input data for node " + (i+1) + ": "); stack.push(sc.nextInt()); } } // Question5: remove nodes from the stack static void stack_pop(Stack<Integer> stack) { Integer y = (Integer) stack.pop(); System.out.println("the node which has the value " + y + " is removed"); } public static void main (String[] args) { Stack<Integer> stack = new Stack<Integer>(); stack_push(stack); stack_pop(stack); stack_count(stack); stack_display(stack); } } تمت الإجابة على جميع الأسئلة بكل وضوح ولتسهل القراءة تمت إضافة تعليقات على كل method. الصورة التالية بها عملية test للتمرين: يمكنك الضغط هنا وستجد الكود وبيئة العمل أيضا لتتأكد منه. اقتباس رابط هذا التعليق شارك على الشبكات الإجتماعية More sharing options...
0 ياسين عناية نشر 27 سبتمبر 2020 أرسل تقرير مشاركة نشر 27 سبتمبر 2020 (معدل) 1. create queue list //declare a Queue Queue<Integer> q = new LinkedList<>(); 2. display the list //print the Queue System.out.println("The Queue contents:" + q); 3. count the nodes in queue System.out.println("Size of the Queue: " + q.size()); 4. insert new node q.add("new element"); 5. remove node int removedele = q.remove(); System.out.println("removed element-" + removedele); System.out.println(q); 6. last method Queue q = new Queue(4); q.enqueue(5); q.enqueue(6); q.enqueue(7); q.enqueue(9); اتمنى لك التوفيق. تم التعديل في 27 سبتمبر 2020 بواسطة ياسين عناية 2 اقتباس رابط هذا التعليق شارك على الشبكات الإجتماعية More sharing options...
0 Najah Alqeeq نشر 27 ديسمبر 2022 أرسل تقرير مشاركة نشر 27 ديسمبر 2022 لو بدي اعمل عمليه حذف في LinkedList والى بنحذف ادخلو على ستاك كيف هاد الكود ؟؟ اقتباس رابط هذا التعليق شارك على الشبكات الإجتماعية More sharing options...
السؤال
محمد الحربي
رابط هذا التعليق
شارك على الشبكات الإجتماعية
3 أجوبة على هذا السؤال
Recommended Posts
انضم إلى النقاش
يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.