السلام عليكم
ارجوا مساعدتي في تصحيح هدا البرنامج الدي يقوم بكتابة ثلاث كلمات وتكرار كل كلمة على حده ثلاث مرات والكود الثالث هو الدي يقوم بتشغيل البرنامج والبرنامج مكتوب باستخدام سنجل لنكد لستSingle linked list)
.
مثال:
("apple","cat","xray")
Then the call Replicate(list,3) should change list as shown below.
("apple","apple","apple","cat","cat","cat","xray","xray","xray")
الكود الاول:
public class SLLNode<E> {
E element;
SLLNode<E> next;
SLLNode(E elem,SLLNode<E> succ){
this.element=elem;
this.next=succ;
}
}
الكود الثاني:
public class SLL<E> {
SLLNode<E> first;
SLL(){
this.first=null;
}
public void printList(){
for(SLLNode<E> curr=this.first;curr!=null; curr=curr.next)
System.out .println(curr.element);
}
public void replicate(){
for (SLLNode<E> curr = first; curr != null; curr = curr.next) {
first=this.first;
first=this.first.next;
first=this.first.next.next;
first=this.first;
first=this.first.next;
first=this.first.next.next;
first=this.first;
first=this.first.next;
first=this.first.next.next;
System.out.print(curr.element);
}
}
}
الكود الثالث:
public class SLLTester{
private SLL sll = null;
public void createSLL()
{
this.sll = new SLL();
}
public void printList()
{
this.sll.addFirst("apple");
this.sll.addMiddle("cat");
this.sll.addLast("xray");
}
public void replicate()
{
this.sll("Apple");
sll.replicate();
this.sll("Cat");
sll.replicate();
this.sll("xray");
sll.repliacte();
}
public static void main(String[] args) {
SLLTester sllTester = new SLLTester();
sllTester.printList();
sllTester.replicate();
}
}