Want to start learning C ++ and check whether g ++-V is installed on the server.
Configured :.. /configure -- prefix =/usr -- Mandir =/usr/share/man -- infodir =/usr/share/info -- enable-shared -- enable-threads = POSIX -- enable-checking = release -- With-system-zlib -- enable-_ cxa_atexit -- disable-libunwind-exceptions -- enable-libgcj-Multifile
-- Enable-languages ages = C, C ++, objc, obj-C ++, Java, Fortran, ADA -- enable-Java-AWT = GTK -- disable-DSSI -- enable-plugin -- With-Java-home =/usr/lib/JVM/java-1.4.2-gcj-1.4.2.0/JRE -- With-CPU = generic -- Host = x86_64-redhat-linux
Thread model: POSIX
GCC version 4.1.2 20080704 (Red Hat 4.1.2-48)
If C ++ is not installed or is not supported, install the GNU make and GNU binutils packages. For more information, see gcc.gnu.org/install.
First, let's implement a simple algorithm:
From 0 to 9 randomly disrupt the array and Output
Shuffle. cpp
# Include <iostream>
# Include <vector>
# Include <algorithm>
# Include <iterator>
# Include "utils. H"
Using namespace STD;
Int main (){
Vector <int> V;
Back_insert_iterator <STD: vector <int> P = back_inserter (v );
For (INT I = 0; I <10; ++ I ){
* P = I;
}
Printcontainer (v, true );
Random_shuffle (V. Begin (), V. End ());
Printcontainer (v, true );
}
Utils. h
# Include <iostream>
# Include <string>
# Include <algorithm>
# Include <iterator>
# Include <vector>
Using namespace STD;
Template <typename FWD>
Void printrange (FWD first, FWD last, char delim = ',', ostream & out = cout ){
Out <"{";
While (first! = Last ){
Out <* first;
If (++ first! = Last)
Out <delim <'';
}
Out <"}" <Endl;
}
Template <typename C>
Void printcontainer (const C & C, char delim = ',', ostream & out = cout ){
Printrange (C. Begin (), C. End (), delim, out );
}
Compile:
G ++-O shuffle. cpp
Run:
./Shuffle
Output result:
{0 1 2 3 4 5 6 7 8 9}
{4 3 7 8 0 5 2 1 6 9}
Now, let's get started and try again later!