الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

doubly class

بدأه بسمة طفوله في 2 أبريل 2010 · 0 رد · 497 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1

السلام عليكم ...هذا برنامجي انا كتبته بعد مجهود بس في بعض من اسئله لم استطع الاجابه عليها .....

مع مراعاة ان نوعية البرنامج Doubly

Could you help me please to solve this Quistion

Remove a node after particular element in the list

public void removeAfter(int after ,int i)...this is A part

Remove a node before particular element in the list

public void removeBefore(int before ,int i)...this is B part

Search a particular element.If found ,print "found" else print "not found"

public void search (int i )......this is C part

Merge tow lists.Merge the second list at the end of first list

public void merge(intDLList12)...this is D part

Count the number of nodes in a list and print

public void count()...this is E part

Note to include different possibilities for each method:

*The list is empty

*The list has one node

*The list has more than one node

And thank you ............

مع علم انا سويت ;class node ,list,test

....

public class dnode

{

public int info;

public dnode next,prev;

public dnode(int i)

{

this(i,null,null);

}

public dnode(int i,dnode n,dnode p)

{

info=i;

next=n;

prev=p;

}

}

.......

وهذا ليست كلاس وابغى اضيف عليه الاسئله الي طلبتها منكم

public class dlist

{

protected dnode head,tail;

public dlist()

{

head=tail=null;

}

public boolean isEmpty()

{

return head==null;

}

public void addToHead(int el)

{

if(!isEmpty())

{

head.prev=new dnode(el,head,null);

head=head.prev;

}

else

head=tail=new dnode(el);

}

public void addToTail(int el)

{

if(!isEmpty())

{

tail.next=new dnode(el,null,tail);

tail=tail.next;

}

else

head=tail=new dnode(el);

}

public int deleteFromHead()

{

int el=head.info;

if(head==tail)

head=tail=null;

else

{

head=head.next;

head.prev=null;

}

return el;

}

public int deleteFromTail()

{

int el=tail.info;

if(head==tail)

head=tail=null;

else

{

tail=tail.prev;

tail.next=null;

}

return el;

}

public void print()

{

for(dnode temp=head;temp!=null;temp=temp.next)

System.out.println(temp.info);

}

public boolean isInList(int el)

{

dnode temp;

for(temp=head;temp!=null&&temp.info!=el;temp=temp. next);

return temp!=null;

}

public void delete(int el)

{

if(!isEmpty())

if(head==tail&&head.info==el)

head=tail=null;

else if(head.info==el)

head=head.next;

else{

dnode temp;

for(temp=head;temp!=null&&temp.info!=el;temp=temp. next);

if(temp!=null)

{

tail=temp.prev;

tail.next=null;

}

if(temp==tail)

{

temp.prev.next=temp.next;

temp.next.prev=temp.prev;

}

}

}

}

....

وهذا تيست كلاس اذا ممكن تساعدوني في اضافة الميثود هنا

public class dtest

{

public static void main(String[] args)

{

dlist d=new dlist();

d.addToHead(5);

d.addToHead(8);

d.addToHead(576);

d.addToTail(46);

d.addToTail(4);

d.addToTail(9);

System.out.println("the list");

d.print();

System.out.println("deliting:");

System.out.println(d.deleteFromHead());

System.out.println(d.deleteFromTail());

System.out.println("the new list");

d.print();

d.delete(5);

System.out.println("the list after deleting 5");

d.print();

System.out.println("4 in list");

System.out.println(d.isInList(4));

}

}

1

مواضيع مشابهة