- محرك البحث العام
- المركبات
- الأراضي
- العقارات
- الوظائف
رؤية النتائج 1 إلى 3 من 3
الموضوع: مساعدة في حل هذة الاسئلة
-
26/12/2017 07:33 PM #1خاطر
- تاريخ الانضمام
- 14/12/2017
- الجنس
- أنثى
- المشاركات
- 1
مساعدة في حل هذة الاسئلة
Create a class for queue in java to check whether the string entered by user is palindrome or *
.not by exploiting the functionality of dequeue and enqueue methods
Create a class to implement circular queue using array in java which includes methods that *
:Performs the following
Enqueue
Dequeue
Display
Write and execute a menu based JAVA program to create an object of this class which gets
.the input from the user
-
مادة إعلانية
-
07/01/2018 01:00 PM #2عضو نشيط
- تاريخ الانضمام
- 20/03/2009
- الجنس
- ذكر
- المشاركات
- 668
public String dequeue() {
if (isEmpty()) {
throw new RuntimeException("Queue underflow");
} else if (first == last) {
String f = first.item;
first = null;
last = null;
return f;
}
String f = first.item;
first = first.next;
return f;
}
public void enqueue(String item) {
Node x = new Node(item);
if (first == null && last == null) {
first = x;
last = x;
return; // return back when first node is enqueued
}
last.next = x;
last = x;
}
أستعمل هذا الكود و عدل عليه على حسب المتطلب عندك
رقم السؤال 1
-
07/01/2018 01:03 PM #3عضو نشيط
- تاريخ الانضمام
- 20/03/2009
- الجنس
- ذكر
- المشاركات
- 668
/* Java Program to implement a queue using two stacks */
// Note that Stack class is used for Stack implementation
import java.util.Stack;
public class GFG
{
/* class of queue having two stacks */
static class Queue
{
Stack<Integer> stack1 ;
Stack<Integer> stack2 ;
}
/* Function to push an item to stack*/
static void push(Stack<Integer> top_ref, int new_data)
{
//Push the data onto the stack
top_ref.push(new_data);
}
/* Function to pop an item from stack*/
static int pop(Stack<Integer> top_ref)
{
/*If stack is empty then error */
if(top_ref.isEmpty())
{
System.out.println("Stack Overflow");
System.exit(0);
}
//pop the data from the stack
return top_ref.pop();
}
//Function to enqueue an item to the queue
static void enQueue(Queue q, int x)
{
push(q.stack1, x);
}
/* Function to dequeue an item from queue */
static int deQueue(Queue q)
{
int x;
/* If both stacks are empty then error */
if(q.stack1.isEmpty() && q.stack2.isEmpty() )
{
System.out.println("Q is empty");
System.exit(0);
}
/* Move elements from stack1 to stack 2 only if
stack2 is empty */
if(q.stack2.isEmpty())
{
while(!q.stack1.isEmpty())
{
x = pop(q.stack1);
push(q.stack2, x);
}
}
x = pop(q.stack2);
return x;
}
/* Driver function to test anove functions */
public static void main(String args[])
{
/* Create a queue with items 1 2 3*/
Queue q= new Queue();
q.stack1 = new Stack<>();
q.stack2 = new Stack<>();
enQueue(q, 1);
enQueue(q, 2);
enQueue(q, 3);
/* Dequeue items */
System.out.print(deQueue(q)+" ");
System.out.print(deQueue(q)+" ");
System.out.println(deQueue(q)+" ");
}
}
-----------------------------------------------------------------------
سؤال ثاني
مواضيع مشابهه
-
ممكن مساعدة في حل هذه الاسئلة لاني عجزت عن حلها
بواسطة القمر الشاسع في القسم: سبلة التعليم والأنشطة التربويةالردود: 0آخر مشاركة: 17/11/2016, 03:13 PM -
الاسئلة الرمضانية
بواسطة نور السميرات في القسم: ارشيف السبلة الرمضانية لعام 1432هـالردود: 1آخر مشاركة: 02/08/2011, 01:36 PM -
ارجو الرد على بعض الاسئلة؟
بواسطة الحق ينتصر في القسم: سبلة السياسة والاقتصادالردود: 1آخر مشاركة: 29/01/2011, 02:59 PM