يعني هني ما في فرق بين هالأستيتمنت ..HTML:for(int i=length-1;i>=pos;i--)
و هالاستيتمنت ...HTML:for(int i=length-1;i>pos;i--)

يعني هني ما في فرق بين هالأستيتمنت ..HTML:for(int i=length-1;i>=pos;i--)
و هالاستيتمنت ...HTML:for(int i=length-1;i>pos;i--)
# include<iostream>
using namespace std;
int main ()
{
int list [6]={8,7,6,5,4,3};
int Max_Size[10],newitem;
cout<<"enter a new item";
cin>>newitem;
insert New Element(list,newitem,&length,10)
return 0;
}
Void insertNewElement(int List[],intnewItem,int&length,Const int Max_Size);
for(inti=length-1;i>Max_Size;i--)
a[i]=a[i-1];
for(inti=0;i<length;i++)
if(list[i]==Max_Size)
cout<<"There is nothing";
Problem (3)
Write a function named insertNewElement that takes as parameters: an array of integers , a new element
(int), and the number of elements in the array and the maximum size of the array (Max_Size)
. Assume that the elements in the array are sorted in ascending order, the function should add the new element in a way that the element in the array will remain sorted.
The prototype of the function is: void insertNewElement (int arr[], int newElement, int & length,Const int Max_Size);
HTML:# include<iostream> using namespace std; int main () { int list [6]={8,7,6,5,4,3}; int Max_Size[10],newitem; cout<<"enter a new item"; cin>>newitem; insert New Element(list,newitem,&length,10) return 0; } Void insertNewElement(int List[],intnewItem,int&length,Const int Max_Size);
بصراحة ما عرفت شنو أكتب داخل الفنكشن ..
سؤال شنو الشيء اللي يخليني أعرف أحل , كل مرة احاول أحل سؤال أشير في جزيئة الفنكشن لاني ما أعرف شنو أحط فيها ..
Void insertNewElement(int List[],intnewItem,int&length,Const int Max_Size);
{
for(int i=0;i<=5;i++)
if(list[i]>[i+1] }
{
for(int i=0;i<length;i--)
if(list[i]==Max_Size)
cout<<"There is nothing ";
a[i]=a[i-1]
a[length]=Max_Size;
Max_Size++;}
ShifttoRight(arr,length,i);
HTML:Void insertNewElement(int List[],intnewItem,int&length,Const int Max_Size); { for(int i=0;i<=5;i++) if(list[i]>[i+1] } { for(int i=0;i<length;i--) if(list[i]==Max_Size) cout<<"There is nothing "; a[i]=a[i-1] a[length]=Max_Size;}
int pos;
for (int i=0;i<length;i++)
{
if( List[i] > newItem )
pos = i; break;
}
if ( pos != i )
{
List[length] = newItem ;
length++;
return;
}
for(int z=length-1 ; z>=pos ; z--)
{
List[z+1] = List[z] ;
}
List[pos] = newItem ;
length++ ;
void insertNewElement(int List[],int newItem,int&length,const int Max_Size)
{
int pos;
for (int i=0;i<length;i++)
{
if( List[i] > newItem )
pos = i; break;
}
if ( pos != i )
{
List[length] = newItem ;
length++;
return;
}
for(int z=length-1 ; z>=pos ; z--)
{
List[z+1] = List[z] ;
}
List[pos] = newItem ;
length++ ;
}
void insertNewElement (int arr[], int newElement, int length,int Max_Size)
{
for(int i=0;i<Max_Size;i++)
{
if(arr[i]>newElement)
{
ShifttoRight(arr,length,i);
arr[i]=newElement;
cout<<"Values after Insert"<<endl;
for(int i=0;i<Max_Size;i++)
{
cout<<arr[i]<<endl;
}
return;
}
else
{
arr[Max_Size-1]=newElement;
cout<<"Values after Insert"<<endl;
for(int i=0;i<Max_Size;i++)
{
cout<<arr[i]<<endl;
}
return;
}
}
}
هاي الطريقه اوكي ما فيها مشكله كود يعني بس المشكله ان لازم تسوي الفور لوب كامله عشان تشوف اذا اكبر واحد او لا...بس الارقام مرتبين تقارن الرقم باخر رقم اذا اكبر خلاص ما يحتاج تسوي الفور لوب..كود:if ( pos != i ) { List[length] = newItem ; length++; return; }[/quote]
[/CODE]
هاي الطريقه اوكي ما فيها مشكله كود يعني بس المشكله ان لازم تسوي الفور لوب كامله عشان تشوف اذا اكبر واحد او لا...بس الارقام مرتبين تقارن الرقم باخر رقم اذا اكبر خلاص ما يحتاج تسوي الفور لوب..


بس اذا كان اكبر وفرت الفور لوب الطريقه الثانيه بيسوي الفورلوب في كل الاحوال...المشكلة تصير اذا مثلا عند 1000000 رقم مثلا الخطوه اللي تسويها في الاول اذا طلعت صح بتوفر عليك 1000000 مقارنه# include<iostream>
using namespace std;
int main ()
{
int arr[6]={5,11,2,1,9,3};
int Max_Size[12];
cout<<"enter number to be insert";
cin>>num;
insertOne(arr,6,12)
return 0;
}
Void insertBetweenOdds(intList[],int&length, int Max_Size);
{
if(len==Max_Size)
cout<<"No more space";
{else
for(int i=len;i>index;i--)
{
A[i]=A[i-1]
A[1+i-i++);
len++;
}
A[i]=A[i+1]+A[i+2]
# include<iostream>
using namespace std;
int main ()
{
int arr[6]={5,11,2,1,9,3};
int Max_Size[12];
cout<<"enter number to be insert";
cin>>num;
insertOne(arr,6,12)
return 0;
}
Void insertBetweenOdds(intList[],int&length, int Max_Size);
{
if(len==Max_Size)
cout<<"No more space";
{else
for(int i=len;i>index;i--)
{
A[i]=A[i-1]
A[i]=A[i+1]+A[i+2]
len++;
A++
}
void Insert(parameter 1,parameter 2)
{
}
void ShiftToRight(parameter1,Parameter2)
{
int x,y;
[COLOR=#0000ff]Insert(x,y);[/COLOR]
}