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

مساعدة في داله ترتيب الارقام وقت الادخال تصاعدي

بدأه توتـآ في 14 مارس 2010 · 4 رد · 2,239 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

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

أحتاج مساعدة

في إني سأستقبل من اليوز عدة ارقام

مثلا ً 9 و 3 و 1

هذي الارقام سوف أضيفها في Array موجودة لدي لكن سأرتبها تصاعدي

مثلا ً الـ Array كانت 10 , 6 , 4, 2

عند طباعتها سوف تكون

10 , 9 , 6 , 4 , 3 , 2 , 1

هذي محاولتي ....

void LinkThem(   int R[ ] ,    int L[ ] ,    int Max)  

{

      int i,             // the index of the next Request to be placed in list.

            j,            // the index used to find the correct place in the list.

      Prevj;          // the previous value of j.

      L[0] = 1;      // the previous value of j.

      L[1] = 0;      // initialize the linked list for the first request.



      // R is the next request to be placed in the list

      for(i = 2; i <= Max - 1; i = i + 1)

      {

            Prevj = 0;

            // find the index j where L should point.

            for(j = L[Prevj]; j != 0; j = L[j])


      // R is the next request to be placed in the list

      for(i = 2; i <= Max - 1; i = i + 1)

      {

            Prevj = 0;

            // find the index j where L should point.

            for(j = L[Prevj]; j != 0; j = L[j])



                  if(R < R[j])

                  {

                        // found the place to insert L in the list.

                        cout << "Inserting \n";

                        L[Prevj] = i;

                        L = j;

                        // get the next request to be added to the list.



                  }
#2

تفضل اتمنى ان يخدمك

#include<iostream.h>

class sort
{
  private:

	int arr[100],n,i,temp,j;
  public:
  //constractor for insulize the value of n
  sort ()
	 {
	  i=n=0;
	 }
  void getdata() ;
  void sorting();
  void display();
};


void sort::getdata()
  {
	  cout<< "Enter Element of Array \n";
	  // ensert values to array
	  do
	  {
		 cout<<"Enter Element No("<<(i+1)<<") OR (-99) to Stop:" ;
		 cin>>temp;
		 if (temp!=-99)
			{
			 arr=temp;
			 i++ ;
		  }
		}while(temp!=-99 || i>=99);
	  n=i;
  }

void sort::sorting()
  {
	for(i=1;i<n;i++)
	{
	  for(j=1;j<n;j++)
		{
		  if (arr[j-1]>arr[j])
			  {
				temp=arr[j]  ;
				arr[j]=arr[j-1];
				arr[j-1] =temp;
			  }
			}
	  }
  }

void sort::display()
  {
	 for(i=0;i<n;i++)
		  cout<<"\t"<<arr;
  }


  void main()
	{
	  sort s ;

	  s.getdata();

	  cout<<"\n Elements BEFORE Sorting:\n";
	  s.display(); // display Entered Data
	  s.sorting(); // Sort Elemet assending
	  cout<<"\n Elements AFTER Sorting:\n";
	  s.display();
	}

عذراً .. تم التعديل .. خطأ في فانكشن الترتيب

تحياتي

تم تعديل هذه المشاركة بواسطة omani في 14 مارس 2010 في 17:09

OMANI FOR EVER

-------------------------------------------------

post-12787-12780191801974.jpg

-------------------------------------------------

#3

الله يديك العافيه , والله ماقصرت

حليت لي البرنامج كله رغم إن مشكلتي كانت في داله الـ Sort فقط

شكرا ً جزيلا ً , أشكرك إلهي يسعدك

طبعا ً هذا البرنامج تبعي كامل

#include <iostream>
using namespace std ;

class Sort {

pravite:




public:

int size = 10 ;
int Array[ size] = { 1 , 5 , 7 , 8 ,10 , 20 } ;
int Link[size] ; 

Group6 (){
cout << " Constructor .\n";}

~Group6(){
cout << " Destructor .\n";}



void LinkThem(Array[], Link[], max){

   //  Array[] the number of Requests for each Composer.

      // Link[] will become a linked list.

      // max this minus 1 is the number of Requests to be ordered.

      int i ,             // the index of the next Request to be placed in list.

            j ,            // the index used to find the correct place in the list.

      Prevj ;          // the previous value of j.

      Link[0] = 1;      // the previous value of j.

      Link[1] = 0;      // initialize the linked list for the first request.



      // Array is the next request to be placed in the list

      for(i = 2; i <= max - 1; i = i + 1)

      {

            Prevj = 0;

            // find the index j where Link should point.

            for(j = Link[Prevj]; j != 0; j = Link[j])

            {

                  cout<<"Check \n " ;

                  if(Array < Array[j])

                  {

                        // found the place to insert Link in the list.

                        cout<<"Inserting Link[]\n";

                        Link[Prevj] = i;

                        Link = j;

                        // get the next request to be added to the list.

                        break;

                  }

                  // start traverse/moving forward in the linked list

                  cout<<"Else, move forward, check again...\n";

                  Prevj = j;

            }





}


void print_list()
{
for ( int i =1 ; i >=size ; i++ )
cout << Array << "\n";
}


};


int main (){

Sort GG ;

int x ;

cout << " ====== MENU ====== \n";
cout << " 1- Add New Number to the list . \n ";
cout << " 2- Print all Number in the list . \n";
cout << " 3- Exit . \n";
cout << " Please Enter Your chose : \n";
cin >> x ;

while ( x > 3 || x<1 ){
cout << " You Have Enterd Incorrect Number , Please Enter Your chose: \n";
 }


switch (x) {

case 1 :
GG.LinkThem(Array[], Link[], max);
break;


case 2 :
GG.print_list() ;
break;


case 3 :
cout << " END of the Programm . \n";
exit(1);

}

return 0 ;
}

سويت منيو بحيث اسأل اليوز هل يبغى يضيف رقم للقائمه او يطبعها او يخرج من البرنامج

طبعا ً فكرتي كانت إن الأري تكون موجودة مسبقه في البرنامج

ارقام اليوز اضيفها عليها وارتبها

أشكرك أخي ..

#4

أخي انظر الى هذا اللوب الذي وضعته هنا

while ( x > 3 || x<1 )
{cout << " You Have Enterd Incorrect Number , Please Enter Your chose: \n"; 
}

لو افترضنا ان مستخدم البرنامج ادخل الرقم 4 او صفر أو اي رقم اخر غير 1،2 ، 3 سوف يدخل البرنامج داخل هذا اللوب .. ولن يخرج إطلاقا.

سوف يبقى يبطبع نفس العبارة الى الابد.

تحياتي

1

OMANI FOR EVER

-------------------------------------------------

post-12787-12780191801974.jpg

-------------------------------------------------

#5
omani كتب:

أخي انظر الى هذا اللوب الذي وضعته هنا

while ( x > 3 || x<1 )
{cout << " You Have Enterd Incorrect Number , Please Enter Your chose: \n"; 
}

لو افترضنا ان مستخدم البرنامج ادخل الرقم 4 او صفر أو اي رقم اخر غير 1،2 ، 3 سوف يدخل البرنامج داخل هذا اللوب .. ولن يخرج إطلاقا.

سوف يبقى يبطبع نفس العبارة الى الابد.

تحياتي

أيوه فهمت عليك

نسيت الـ Update

وكذا ممكن يصير infinite loop

والتصحيح يكون

while ( x > 3 || x<1 )
{cout << " You Have Enterd Incorrect Number , Please Enter Your chose: \n"; 
cin>> x ;
}

شكرا ً لك وجزاك الله خير

وأيضا ً شكرا ً لـ omani

تم تعديل هذه المشاركة بواسطة توتـآ في 20 مارس 2010 في 15:54

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