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

ساعدوني في عمل برنامج عن arrays

بدأه أسماء البريكي في 20 مارس 2012 · 4 رد · 483 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

الســــــــــــــــــــــــــــلام عليكم ياشباااااااااااااااااااب ,,,,

أريد مساعده منكم عااااااااااجلة في كتابة برنامج كتطبيق على binary and linear search مع بعض..

أرجوووووووووووووووووووكم ساعدوني أنا حاولت أبدا فيه بس نااااااقص أنتوا شوفوه و إذا خطأ صحووا فيه بلييييييز...

شكـــــــــــــــــــــــــــــــــــــــــــرا مقدما,,,,

الكود ف المرفق..

BL.java

#2

ممكن توضح اين عندك مشكل وشكرا

تم تعديل هذه المشاركة بواسطة SoUfiaNoXx في 21 مارس 2012 في 01:31

#3
SoUfiaNoXx كتب:

ممكن توضح اين عندك مشكل وشكرا

أولا شكرا ع الرد

المشكلة معي أنه م عارفه أدمج linear and binary بطريقة صحيحة بحيث يقوم البرنامج بتطبيق كلا العمليتين مهما كااااان

إذا تقدر تغير ف أماكن الكودات أو تظيف أي شي بكون مشكوووووووووووورة لك أخي الكريم ..

المشكلة موضحة ف الأسفل

BL.java

#4

تفضل ولا تنسانا من التقييم :) :blush:

  
    public static void main(String args[]) {

        int s, mid, t,n, high, low, h,index1 ,index2;

        Scanner scan = new Scanner(System.in);

        System.out.println(" Enter the size of the search array ");

        n = scan.nextInt();

        int[] a = new int[n];

         index1  =  search(a ,n);

        if (index1 == -1)
           System.out.println(" Element is not found ");

        else 
            System.out.println("Element found in Index : "+index1);
        // End Liner Search ^_^

        System.out.println(" Enter the size of the binary search array 2 ");
        h = scan.nextInt();
        int[] r = new int[h];
        index2 = Binarysearch(r,h);
        if (index2 == -1 )
           System.out.println(" Element is not found"); 
        else 
             System.out.println(  "is found at position " + index2);
    }


    public static int  search(int a[], int size ) {
        int x, n=size;
        Scanner scan = new Scanner(System.in);

        System.out.println(" Enter " + n + " elements of the array  ");
        for (int i = 0; i < a.length; i++) 
        {
            a = scan.nextInt();
        }
        System.out.println(" Enter the search element ");
        x = scan.nextInt();
        int j = 0;
        while (j < a.length) 
        {
            if (x == a[j]) 
            {
                return j;

            } 

            j++;
        }
        return -1;
    }

     public static int Binarysearch(int r[],int size){
        Scanner scan = new Scanner(System.in);
       int   mid, t,n, high, h =size,low,s;

    System.out.println(" Enter  " + h + " number  in ascending order ");
        for (t = 0; t < r.length; t++) {
            r[t] = scan.nextInt();
        }
        System.out.println(" Enter the search element 2 ");
        s = scan.nextInt();
        low = 0;
        high = h - 1;
        while (low <= high)
        {
            mid = (low + high) / 2;
            if (s == r[mid]) 
            {
                return mid;
            }
            if (s < r[mid]) 
            {
                high = mid - 1;
            } 
            else 
            {
                low = mid + 1;
            }

        }
       return -1;
    }
1 −1
#5
The.Eagle كتب:

تفضل ولا تنسانا من التقييم :) :blush:

  
    public static void main(String args[]) {

        int s, mid, t,n, high, low, h,index1 ,index2;

        Scanner scan = new Scanner(System.in);

        System.out.println(" Enter the size of the search array ");

        n = scan.nextInt();

        int[] a = new int[n];

         index1  =  search(a ,n);

        if (index1 == -1)
           System.out.println(" Element is not found ");

        else 
            System.out.println("Element found in Index : "+index1);
        // End Liner Search ^_^

        System.out.println(" Enter the size of the binary search array 2 ");
        h = scan.nextInt();
        int[] r = new int[h];
        index2 = Binarysearch(r,h);
        if (index2 == -1 )
           System.out.println(" Element is not found"); 
        else 
             System.out.println(  "is found at position " + index2);
    }


    public static int  search(int a[], int size ) {
        int x, n=size;
        Scanner scan = new Scanner(System.in);

        System.out.println(" Enter " + n + " elements of the array  ");
        for (int i = 0; i < a.length; i++) 
        {
            a = scan.nextInt();
        }
        System.out.println(" Enter the search element ");
        x = scan.nextInt();
        int j = 0;
        while (j < a.length) 
        {
            if (x == a[j]) 
            {
                return j;

            } 

            j++;
        }
        return -1;
    }

     public static int Binarysearch(int r[],int size){
        Scanner scan = new Scanner(System.in);
       int   mid, t,n, high, h =size,low,s;

    System.out.println(" Enter  " + h + " number  in ascending order ");
        for (t = 0; t < r.length; t++) {
            r[t] = scan.nextInt();
        }
        System.out.println(" Enter the search element 2 ");
        s = scan.nextInt();
        low = 0;
        high = h - 1;
        while (low <= high)
        {
            mid = (low + high) / 2;
            if (s == r[mid]) 
            {
                return mid;
            }
            if (s < r[mid]) 
            {
                high = mid - 1;
            } 
            else 
            {
                low = mid + 1;
            }

        }
       return -1;
    }

مشكووووووووووووووووووووور أخي الكريم ع الخدمة القيمة ... شو تقصد يالتقييم؟؟؟

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