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

[مخالف]الرجاء مساعدتي عاجلاً

مغلق
بدأه nnnnnnnnnn2 في 15 ديسمبر 2011 · 3 رد · 338 مشاهدة · في ارشيف قسم C/C++
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمة الله

مرحباًأعضاء المنتدى اتمنى تساعدوني باسرع وقت مشكورين

Bubble sort is a simple and one of the well-known sorting algorithms. It sorts an array in an ascending order (from smaller to larger). It works by comparing a pair of values from the begging of the array and swapping only if the value of the current element in the array is larger than the next element.

Example. Sort {7, 3, 12, -4, 20} using bubble sort.

7 3 12 -4 20 unsorted

7 3 12 -4 20 7 > 3, swap

3 7 12 -4 20 7 < 12, Ok

3 7 12 -4 20 12 > -4, swap

3 7 -4 12 20 12 < 20, Ok

3 7 -4 12 20 3 < 7, Ok

3 7 -4 12 20 7 > -4, swap

3 -4 7 12 20 7 < 12, Ok

3 -4 7 12 20 3 > -4, swap

-4 3 7 12 20 3 < 7, Ok

-4 3 7 12 20 -4 < 3, Ok

-4 3 7 12 20 Sorted

Write a function Bubble_sort (int [] array, int array_size) that takes an array of integers along with the size of the array. The function should sort the array.

1. Use this function with the Binary search function (Exercise 1) in one program to sort then search

a. Do a menu having two options 1- Binary search 2- Bubble sort

b. Do a validation to check that the Binary search is performed on a sorted array (user selects option 2 before 1 for the first time

)

#2

السلام عليكم ورحمة الله تفضل أخي هذا مثال بسيط حول دالة Bubble_sort

يمكنك إضافته إلي التمرين

#include <iostream>
using namespace std;
void Bubble_sort(int * Array, int length);
void swap(int * Array, int length);
int main(int argc, char *argv[])
{
    // simple example of Bubble_sort function
    const int length = 7;
    int Array[length] = {5,1,4,2,8,11,0};
    Bubble_sort(Array, length);
    for(int i = 0; i < length; i++)
    {
        cout << Array << endl;
    }
    return 0;
}
void swap(int * Array, int index)
{
    // function that swap between two integers
	int inter = Array[index];
	Array[index] = Array[index - 1];
	Array[index - 1] = inter;
}
void Bubble_sort(int  * Array, int length)
{
    // function that sorts an  array of integers
	int stoper = 0;
	while(true)
	{
		stoper = 0;
		for(int i = 1; i < length ; i++)
		{
			if(Array[i - 1] > Array)
			{
				swap(Array, i);
			}
			else
                stoper++;
		}
		if(stoper == length - 1)
            break;
	}
}
1
#3

مشكوور ماقصرت الله يجزاك خير :thumb_up:

#4

الأخ الكريم/الأخت الكريمة

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

مرحباً بكم في منتدى الفريق العربي للبرمجة

تأسف إدارة المنتدى لغلق الموضوع وذلك لمخالفته قوانين المشاركات .

قواعد طرح المشاركات

/index.php?showtopic=29343

شاكرين لكم حُسن تعاونكم

{username}

صورة
صورة

حسابي في الفيس بوك
http://goo.gl/XIzwL

حسابي في تويتر
http://goo.gl/6p4e3

 

 
 

هذا الموضوع مغلق.

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