المساعد الشخصي الرقمي

عرض الإصدار الكامل : احتاج مساعدة.... ضروررري



bubbles
30/12/2015, 09:20 PM
هلا.. ممكن مساعد في برنامج :) java
انا حليت بس مايظهر utput
هو سؤالين. تمنى اعرف واش الخطا و ليش مايظهر لي...

Q1
import java.util.*;
class mystack
{
char mystack[];
int top;
char maxsize;
mystack(char r)
{

maxsize=r;
mystack = new char[maxsize];
top=-1;
}
public void push(char val)
{
if(top==maxsize-1)
{
System.out.println("Cannot push Mystack full");
}
else
{
top++;
mystack[top]=val;
}
}
public char pop( )
{
if(top==-1)
{
System.out.println("Cannot pop Mystack empty");
return 0;
}
else
{
return(mystack[top--]);
}
}
public void display()
{
char q;
System.out.println("MyStack is");
for(q=0;q<=top;q++)
{
System.out.print(mystack[q]+"\t");
}
}
public boolean isempty()
{
if(top==-1)
{
return true;
}
else
{
return false;
}
}
public boolean isfull()
{
if(top==maxsize-1)
{
return true;
}
else
{
return false;
}
}
public char peek()
{
return(mystack[top]);
}
public int size()
{
return(top+1);
}

}

class mystackdemo
{
public static void main(String args[])
{

mystack obj1=new char[maxsize]mystack();
mystack obj2=new char[maxsize]mystack();
mystack obj3=new char[maxsize]mystack();

obj1.push('A');
obj1.push('B');
obj1.push('C');

System.out.println("MyStack1 is");
obj1.display();

System.out.println("MyStack2 is");
obj2.display();


System.out.println("MyStack3 is");
obj3.display();


char noor;

noor=obj1.pop();
obj3.push(noor);

noor=obj1.pop();
obj2.push(noor);

noor=obj3.pop();
obj2.push(noor);


noor=obj1.pop();
obj3.push(noor);

noor=obj2.pop();
obj1.push(noor);


noor=obj2.pop();
obj3.push(noor);


noor=obj1.pop();
obj3.push(noor);


System.out.println("Stack1 is");
obj1.display();

System.out.println("Stack2 is");
obj2.display();


System.out.println("Stack3 is ");
obj3.display();

}
}


88888888888888888888888888888888888888888888888888 88888888888888888

Q2

import java.util.*;

class node
{

int data;
node link;

node(int w)
{
data=w;
link=null;
}

}
class linkedlist
{
node head,tail;
int size;
linkedlist()
{
head=null;
tail=null;
size=top;
}

public int getsize()
{
return size;
}


public void insertatend(int val)
{
node R=new node(val);
size++;

if(head==null)
{
head=R;
tail=R;
}

else
{
tail.link=R;
tail=R;
}
}
public void deleteatpos(int pos)
{

node R=new node(val);
if(pos==size)
{
node s=head,t=head;
while(s!=tail)
{
t=s;
s=s.link;
}
tail=t;
tail.link=null;
size--;
return;
}
}
public void display()
{
System.out.println("\n Linked is");

if(size==0)
{
System.out.println("Empty Linked list");
}

if(head.link==null)
{
System.out.println(head.data);
return;
}

node E=head;
while(E!=null)
{
System.out.print(E.data+ "->");
E=E.link;
}

}

public void puch(long val)
{
if(top==maxsize-1)
{
System.out.printLn("Stack is push cannot push stack full");
}
else
{
top++;
stack[top]=val;
}
}
public long pop( )
{
if(top==-1)
{
System.out.println("Stack is empty cannot push stack empty");
return 0;
}
else
{
return(stack[top--]);
}
}
public void display()
{
System.out.println("Stack is");
for(int i=0;i<=top;i++)
{
System.out.print(stack[i]+"\t");
}
}
class listStackmain
{
public static void main(String args[]);
{
linkedlistss AA = new linkedlistss();
int choice;
char ch;
Scanner sc=new Scanner(System.in);
do
{
System.out.println("\n linkedStack");
System.out.println("1:Insert or push in the end");
System.out.println("2:Delete or pop from end");
System.out.println("3:getsize");
choice=sc.nextInt();
switch(choice)
{
case 1:
System.out.println("Enter the value to insert");
val=sc.nextInt();
AA.insertatend(val);
break;
case 2:
System.out.println(" delete the end");
val=sc.nextInt();
AA.deleteatend(val);
break;
case 3:
System.out.println("The size is"+AA.getsize());
break;
default:
System.out.println("Wrong choice");
AA.display();
System.out.println("enter choice(Y/N) (y/n)");
ch=sc.next().charAt(0);
while(ch=='Y'||ch=='y');
return 0;
}
}

}
}

king of torrent
31/12/2015, 07:47 AM
import java.util.*;
class mystack
{
char mystack[];
int top;
int maxsize;
mystack(int size)
{

maxsize=size;
mystack = new char[size];
top=-1;
}
public void push(char val)
{
if(top==maxsize-1)
{
System.out.println("Cannot Mystack full");
}
else
{
top++;
mystack[top]=val;
}
}
public char pop( )
{
if(top==-1)
{
System.out.println("CannotMystack empty");
return 0;
}
else
{
return(mystack[top--]);
}
}
public void display()
{
char q;
for(q=0;q<=top;q++)
{
System.out.print(mystack[q]+"\t");
}
System.out.println();
}
public boolean isempty()
{
if(top==-1)
{
return true;
}
else
{
return false;
}
}
public boolean isfull()
{
if(top==maxsize-1)
{
return true;
}
else
{
return false;
}
}
public char peek()
{
return(mystack[top]);
}
public int size()
{
return(top+1);
}

}

class mystackdemo
{
public static void main(String args[])
{

mystack obj1=new mystack(10);
mystack obj2=new mystack(10);
mystack obj3=new mystack(10);

obj1.push('A');
obj1.push('B');
obj1.push('C');

obj2.push('D');
obj2.push('E');
obj2.push('F');

obj3.push('G');
obj3.push('I');
obj3.push('J');



System.out.print("Stack1 :");
obj1.display();

System.out.print("Stack2 :");
obj2.display();


System.out.print("Stack3 :");
obj3.display();


char noor;

noor=obj1.pop();
obj3.push(noor);

noor=obj1.pop();
obj2.push(noor);

noor=obj3.pop();
obj2.push(noor);


noor=obj1.pop();
obj3.push(noor);

noor=obj2.pop();
obj1.push(noor);


noor=obj2.pop();
obj3.push(noor);


noor=obj1.pop();
obj3.push(noor);


System.out.print("Stack1 :");
obj1.display();

System.out.print("Stack2 :");
obj2.display();


System.out.print("Stack3 :");
obj3.display();

}
}

bubbles
31/12/2015, 12:43 PM
اشكرك اخي.. شوف
هو سؤال عباره عن
Following diagram shows the problem of Tower of Hanoi. The problem says that there are three
towers 1, 2 & 3. Tower 1 has three blocks A,B and C of different sizes. The task is to place these
blocks in tower 3 in the same order as they are placed in tower 1. You can take use tower 2 for
finding the solution.
الا انت حليته ف بيكون
import java.util.*;
class mystack
{
char mystack[];
int top;
int maxsize;
mystack(int size)
{

maxsize=size;
mystack = new char[size];
top=-1;
}
public void push(char val)
{
if(top==maxsize-1)
{
System.out.println("Cannotack full");
}
else
{
top++;
mystack[top]=val;
}
}
public char pop( )
{
if(top==-1)
{
System.out.println("CannotMystacky");
return 0;
}
else
{
return(mystack[top--]);
}
}
public void display()
{
char q;
for(q=0;q<=top;q++)
{
System.out.print(mystack[q]+"\t");
}
System.out.println();
}
public boolean isempty()
{
if(top==-1)
{
return true;
}
else
{
return false;
}
}
public boolean isfull()
{
if(top==maxsize-1)
{
return true;
}
else
{
return false;
}
}
public char peek()
{
return(mystack[top]);
}
public int size()
{
return(top+1);
}

}

class mystackdemo
{
public static void main(String args[])
{

mystack obj1=new mystack(10);
mystack obj2=new mystack(10);
mystack obj3=new mystack(10);

obj1.push('A');
obj1.push('B');
obj1.push('C');

obj2.push('A');
obj2.push('B');
obj2.push('C');

obj3.push('A');
obj3.push('B');
obj3.push('C');



System.out.println("Stack1 is");
obj1.display();

System.out.println("Stack2 is");
obj2.display();

System.out.println("Stack3 is");
obj3.display();

char noor;

noor=obj1.pop();
obj3.push(noor);

noor=obj1.pop();
obj2.push(noor);

noor=obj3.pop();
obj2.push(noor);


noor=obj1.pop();
obj3.push(noor);

noor=obj2.pop();
obj1.push(noor);


noor=obj2.pop();
obj3.push(noor);


noor=obj1.pop();
obj3.push(noor);


System.out.println("Stack1 is");
obj1.display();

System.out.println("Stack2 is");
obj2.display();

System.out.println("Stack3 is");
obj3.display();
}
}

bubbles
31/12/2015, 12:50 PM
بيظهر out put مش متسلسل

bubbles
31/12/2015, 01:01 PM
وسوال الثاني
Write and execute a program in java to demonstrate the various operations like push, pop and
display for stack implemented as linked list
بعد ماطلع معي ابد
import java.util.*;

class node
{

int data;
node link;

node(int w)
{
data=w;
link=null;
}

}
class linkedlist
{
node head,tail;
int size;
linkedlist()
{
head=null;
tail=null;
size=top;
}

public int getsize()
{
return size;
}


public void insertatend(int val)
{
node R=new node(val);
size++;

if(head==null)
{
head=R;
tail=R;
}

else
{
tail.link=R;
tail=R;
}
}
public void deleteatend(int pos)
{

node R=new node(val);
if(pos==size)
{
node s=head,t=head;
while(s!=tail)
{
t=s;
s=s.link;
}
tail=t;
tail.link=null;
size--;
return;
}
}

public void display()
{
System.out.println("\n Linked is");

if(size==0)
{
System.out.println("Empty Linked list");
}

if(head.link==null)
{
System.out.println(head.data);
return;
}

node E=head;
while(E!=null)
{
System.out.print(E.data+ "->");
E=E.link;
}

}

public void puch(long val)
{
if(top==maxsize-1)
{
System.out.printLn("Stack is push cannot push stack full");
}
else
{
top++;
stack[top]=val;
}
}
public long pop( )
{
if(top==-1)
{
System.out.println("Stack is empty cannot push stack empty");
return 0;
}
else
{
return(stack[top--]);
}
}
public void display()
{
System.out.println("Stack is");
for(int i=0;i<=top;i++)
{
System.out.print(stack[i]+"\t");
}
}
class listStackmain
{
public static void main(String args[]);
{
linkedlistss AA = new linkedlistss();
int choice;
char ch;
Scanner sc=new Scanner(System.in);
do
{
System.out.println("\n linkedStack");
System.out.println("1:Insert or push in the end");
System.out.println("2:Delete or pop from end");
System.out.println("3:getsize");
choice=sc.nextInt();
switch(choice)
{
case 1:
System.out.println("Enter the value to insert");
val=sc.nextInt();
AA.insertatend(val);
break;
case 2:
System.out.println(" delete the end");
val=sc.nextInt();
AA.deleteatend(val);
break;
case 3:
System.out.println("The size is"+AA.getsize());
break;
default:
System.out.println("Wrong choice");
AA.display();
System.out.println("enter choice(Y/N) (y/n)");
ch=sc.next().charAt(0);
while(ch=='Y'||ch=='y');
return 0;
}
}


الا يعرف يرد علي بليزززززززززززز

king of torrent
31/12/2015, 01:56 PM
import java.util.*;
class mystack
{
char mystack[];
int top;
int maxsize;
mystack(int size)
{

maxsize=size;
mystack = new char[size];
top=-1;
}
public void push(char val)
{
if(top==maxsize-1)
{
System.out.println("Cannotack full");
}
else
{
top++;
mystack[top]=val;
}
}
public char pop( )
{
if(top==-1)
{
System.out.println("CannotMystacky");
return 0;
}
else
{
return(mystack[top--]);
}
}
public void display()
{
char q;
for(q=0;q<=top;q++)
{
System.out.print(mystack[q]+"\t");
}
System.out.println();
}
public boolean isempty()
{
if(top==-1)
{
return true;
}
else
{
return false;
}
}
public boolean isfull()
{
if(top==maxsize-1)
{
return true;
}
else
{
return false;
}
}
public char peek()
{
return(mystack[top]);
}
public int size()
{
return(top+1);
}

}

class mystackdemo
{
static mystack tower1;
static mystack tower2;
static mystack tower3;
public static void main(String args[])
{

tower1=new mystack(3);
tower2=new mystack(3);
tower3=new mystack(3);

tower1.push('A');
tower1.push('B');
tower1.push('C');

DisplayTowers();

doTowers(3,tower1,tower2,tower3);

}
public static void doTowers(int topN, mystack from, mystack inter, mystack to) {
if (topN == 1){
to.push(from.pop());
DisplayTowers();
}else {
doTowers(topN - 1, from, to, inter);
to.push(from.pop());
DisplayTowers();
doTowers(topN - 1, inter, from, to);
}
}
public static void DisplayTowers(){
System.out.print("Tower1:");
tower1.display();
System.out.print("Tower2:");
tower2.display();
System.out.print("Tower3:");
tower3.display();
System.out.println("------------------------------------------------");
}

}

king of torrent
31/12/2015, 02:02 PM
مادري ليش مسوي الستاك

ممكن تحل المسئلة بشكل بسيط بدون ذا الكود كله

you can solve it with only 2 methods
the solution will be like

Move disk C form Tower1 to Tower3
Move disk B from Tower1 to Tower2
...

king of torrent
31/12/2015, 09:23 PM
غير هذا الجزء




tower1.push('A');
tower1.push('B');
tower1.push('C');



إلــــــى





tower1.push('C');
tower1.push('B');
tower1.push('A');

bubbles
01/01/2016, 10:51 AM
جميل جدا تسلم ...هذه اسهل طريقه من سابقه ...
اشكرك اخي...

king of torrent
01/01/2016, 01:11 PM
العفو واجبنا