رد: برنامج بلغة الجافا java
وعليكم السلام ورحمة الله وبركاته....
على الرحب والسعه راح احاول اساعدك راح انزل لك برنامجين طبعا البرامج اخذتهم بمادة الجافا وهم البرامج العمليه يعني افتح برنامج الجافا وانسخهم وان شا الله يطلع لك الاوت بت..لاكن حاول تغير المسميات لان مذكور داخل احد البرامج اسم المحاضره وهي الاب.
البرنامج الاول......................
class linkedliset
public object getDetam()
public Elemennt getnext()
public void insertAfter
public void insertbefor
public LinkedList
public void purge
public gethead
public gettail
public Boolan isempty
public object getfirse
public object getlast
public Element getempty
public void prepend
public void append
public void assign
public void extret
public void print
public classLinkedList
protectedElement head;
protected Element tail;
public final class Element
Object datum;
Element next;
Element (Object datum, Element next)
{this.datum = datum;
this.next = next;
)public Object getDatum ( )
{return
datum;}
public Object getNext ( )
{return next;
public classLinkedList
protectedElement head;
protected Element tail;
public final class Element
EObject datum ;
Element next ;
public void insertAfter (Object item)
{
next = new Element (item, next) ;
if(tail == this)
tail = next
public void insertBefore (Object item)
{
Element tmp = new Element (item, this) ;
if(this == head)
head = tmp ;
else
{
Element prevPtr = head;
while(prevPtr != null && prevPtr.next != this)
prevPtr = prevPtr.next;
prevPtr.next = tmp;
public class lap4list{
public static void main(String[] args)
}
linkedlist listA=new)LinkedList();
System.out.print(the head of the list is:"listA.getHead());
System.out.print(the tail of the list is:"listA.gettail());
System.out.print(is the list empty?:"listA.())
System.out.print(is the list empty?:"listA.isempty())
listA.print(listA);
listA.prepend(30);
listA.prepend(20);
listA.prepend(10);
listA.prepend(listA);
listA.prepend(40);
listA.prepend(50);
lA.prepend(listA);
System.out.print(listA.getFirst()+"")
System.out.print(listA.getLast()+"")
listA.extract(30);
listA.print(listA);
LinkedList listB =new LinkList();
listB.assing(listA);
listA.print(listB);
listB.getPrt(10).intserBefore(100);
listA.print (listB);
listB.getPrt(50).intserAfter(100);
listA.print (listB);
listB.getHead().insterBefoer("xxx");
listB.getTail().insterAfter("xxx");
listB.print(listB);
الثاني.............
/
* @(#)Lab4List.java
*
* Lab4List application
*
* @author
* @version 1.00 2010/7/23
*/
class LinkedList
{
protected Element head;
protected Element tail;
public final class Element
{
Object datum;
Element next;
Element (Object datum, Element next)
{
this.datum = datum;
this.next = next;
}
public Object getDatum ()
{
return datum;
}
public Element getNext ()
{
return next;
}
public void insertAfter (Object item)
{
next = new Element (item, next);
if (tail == this)
tail = next;
}
public void insertBefore (Object item)
{
Element tmp = new Element (item, this);
if (this == head)
head = tmp;
else
{
Element prevPtr = head;
while (prevPtr != null && prevPtr.next != this)
prevPtr = prevPtr.next;
prevPtr.next = tmp;
}
}
}
public LinkedList ()
{
}
public void purge ()
{
head = null;
tail = null;
}
public Element getHead ()
{
return head;
}
public Element getTail ()
{
return tail;
}
public boolean isEmpty ()
{
return head == null;
}
public Object getFirst ()
{
if (head == null)
// throw new ContainerEmptyException ();
System.out.println("Error");
return head.datum;
}
public Object getLast ()
{
if (tail == null)
// throw new ContainerEmptyException ();
System.out.println("Error");
return tail.datum;
}
public Element getPtr(Object item)
{
for (Element ptr = head; ptr != null;ptr = ptr.next)
if (ptr.datum == item)
return ptr;
return null;
}
public void prepend (Object item)
{
Element tmp = new Element (item, head);
if (head == null)
tail = tmp;
head = tmp;
}
public void append (Object item)
{
Element tmp = new Element (item, null);
if (head == null)
head = tmp;
else
tail.next = tmp;
tail = tmp;
}
public void assign (LinkedList list)
{
if (list != this)
{
purge ();
for (Element ptr = list.head; ptr != null; ptr = ptr.next)
append (ptr.datum);
}
}
public void extract (Object item)
{
Element ptr = head;
Element prevPtr = null;
while (ptr != null && ptr.datum != item)
{
prevPtr = ptr;
ptr = ptr.next;
}
if (ptr == null)
throw new IllegalArgumentException ("item not found");
if (ptr == head)
head = ptr.next;
else
prevPtr.next = ptr.next;
if (ptr == tail)
tail = prevPtr;
}
public void print (LinkedList list)
{
if (isEmpty())
System.out.println("The list is empty");
else
{
for (Element ptr = list.head; ptr != null; ptr = ptr.next)
System.out.print(ptr.datum + " ");
System.out.println();
}
}
}
class Lab4 {
public static void main(String [] args)
{
LinkedList listA = new LinkedList(); // create a new empty list l
System.out.println("The head of the list is: " + listA.getHead());
System.out.println("The tail of the list is: " + listA.getTail());
System.out.println("Is the list empty? " + listA.isEmpty());
listA.print(listA);
listA.prepend(30);
listA.prepend(20);
listA.prepend(10);
listA.print(listA);
listA.append(40);
listA.append(50);
listA.print(listA);
System.out.println(listA.getFirst() + "");
System.out.println(listA.getLast() + "");
listA.extract(30);
listA.print(listA);
LinkedList listB = new LinkedList(); // create a new empty list listB
listB.assign(listA); // assign listA to listB
listA.print(listB);
listB.getPtr(10).insertBefore(100);
listA.print(listB);
listB.getPtr(50).insertAfter(100);
listA.print(listB);
listB.getHead().insertBefore("xxx"); // insert before the head of the list
listB.getTail().insertAfter("xxx"); // insert after the tail of the list
listB.print(listB);
}
}
طبعا البرنامج الثاني محدد فيه كل فقره وش المطلوب منها وهو بعد علامه// اتمنى فهمت علي ......
اما من ناحية خبرتي بالبرنامج والله ماعندي عنه خلفيه كثير لان بحكم تخصصي انظمة المعلومات متطرقنا له كثير لاكنه برنامج كريه ومحاضرة الاب (العملي)ثلاث ساعات ونص يعني بجد كرهنا البرنامج.....
تحياتي.......
|