|
-
August 21st, 2010, 06:59 AM
#1
Qestions About The Array
hello
how can i swap between the array
with to elements or couple of numbers for example i got
a { 5 , 2 , 3 , 7 }
b { 2 , 7 , 1 , 9 }
how can i swap between 2 and 7
7 & 3
1 & 2
3 & 7
what should i write i mean the code ?
-
August 21st, 2010, 07:28 AM
#2
Re: Qestions About The Array
To swap elements i and j within the same int array a;
Code:
int temp = a[i];
a[i] = a[j];
a[j] = temp;
Victor Nijegorodov
-
August 21st, 2010, 08:46 AM
#3
Re: Qestions About The Array
can u explain to me the code cuz i didnt understand it
-
August 21st, 2010, 09:12 AM
#4
Re: Qestions About The Array
No, sorry!
You seem to first must learn the basics of mathematics, logic and algorithms
and only after that - go on with basics of programming.
Victor Nijegorodov
-
August 21st, 2010, 07:20 PM
#5
Re: Qestions About The Array
 Originally Posted by jacksparrow
can u explain to me the code cuz i didnt understand it
int temp = a[i];
a[i] = a[j];
a[j] = temp;
He has created an integer variable called "temp" and assigned the value of a[i] to it. Then his has assigned the value of a[j] to a[i]. Finally, he assigned the value of a[i] (which was assigned to temp earlier) and assigned it to a[j].
a[i] goes into 'temp', a[j] goes into a[i], and temp goes into a[j]. Simple enough.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|