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

مسـاعده في حساب الرن تايم ضـــروري ..

بدأه Besnsha في 27 ديسمبر 2011 · 2 رد · 332 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمه الله وبركاته

كتبت برنامج جافا يعمل العمليات التاليه :

حذف من اليمين

حذف من اليسار

وsort

بأستخدام Doubly linked list

بحيث ان يكون الان بوت راندم

واحسب الرن تايم للكل عمليه

كتبت كود ولكن الرن تايم تظهر اعداد كبير

الرجاء المساعده

import java.util.Scanner;
import java.io.*;
import java.util.*;
public class DoublyLinkedList {
  private Link first; 

  private Link last; 

  public DoublyLinkedList() {
    first = null; 
    last = null;
  }

  public boolean isEmpty(){
    return first == null;
  }





  public Link deleteFirst(){ 
    Link temp = first;
    if (first.next == null) 
      last = null; 
    else
      first.next.previous = null;
    first = first.next; 
    return temp;
  }


 public Link deleteLast(){ 
    Link temp = last;
    if (first.next == null)
      first = null; 
    else
      last.previous.next = null;
    last = last.previous; 
    return temp;
  }


  public void display () {
    System.out.print("List (first to last): ");
    Link current = first; // start at beginning
    while (current != null) // until end of list,
    {
      current.displayLink();
      current = current.next; // move to next link
    }
    System.out.println("");
  }





   public void insertsort (long key){
    Link newLink = new Link(key);

    Link previous = null; 
    Link current = first;
if (isEmpty()) 
      last = newLink; 
    else

    while (current != null && key > current.dData) {
      previous = current;
      current = current.next;
    }
    if (previous == null)
      first = newLink; 
    else
      previous.next = newLink; 
    newLink.next = current; 
  }



  public static void main(String[] args)throws IOException {





int ch ; 
Scanner input = new Scanner(System.in);

int i = 0  ;

   DoublyLinkedList  list = new DoublyLinkedList();
   BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
   int dqarr[] = new int [101];

  double b =System.currentTimeMillis();
       System.out.print( "Enter number of element :p" );
		System.out.print(dqarr+ "\t");
		int n =Integer.parseInt(br.readLine());
		 Random rand = new Random();
        for( i = 0; i < n ; i ++ ) { 

						dqarr = rand.nextInt(3);

                   list.insertsort(dqarr);




        }
         list.display();
System.out.print("Effe");
 double a =System.currentTimeMillis();
System.out.println(a-b);


       list.deleteFirst();
list.display();









    }



















	}	






class Link {
  public long dData; // data item

  public Link next; // next link in list

  public Link previous; // previous link in list

  public Link(long d)
  {
    dData = d;
  }

  public void displayLink(){
    System.out.print(dData + " ");
  }

}
#2

أختي أنتي تدخلي عملية قراءة النص من المستخدم في الحسبة

وهذه العملية تأخذ وقت كبير

تحياتي

حزمة المحرك الإصدارة 0.8

أي أحد يجد أني ظلمته فليراسلني

وبإذن الله لو كان له حق سيأخذه

728x90.png

#3

السلام عليكم

إستبدلي هذا السطر

System.out.println(a-b);

بهذا السطر لحساب الوقت بالثانية

System.out.println(Math.round(a - b) / 1000.0) ;

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