 is faster because it doesn't have the overhead of a hashmap and may stop before traversing the whole array, but does have the same big-O limit.

A:

Since you are using C++ and not C, there are a few things that you could clean up.
First of all, your code leaks memory: you are newing memory but you are not deleteing. In order to avoid this manual memory management, you should use the std::vector class template instead of new[].
Furthermore, stdio.h is a legacy C header. Use cstdio in C++. But in fact, your code doesn’t need that header anyway.
A hash map implementation is available in the std::tr1 namespace. If your compiler supports this (modern compilers do), the following code works:
#include <iostream>
#include <unordered_map>
#include <vector>

int main() {
    std::unordered_map<int, unsigned> occurrences;
    int a[6] = { 1, 1, 1, 2, 2, 3 };
    unsigned const size = sizeof a / sizeof a[0];

    // First pass: count occurrences.
    for (unsigned i = 0; i < size; ++i)
        ++occurrences[a[i]];

    // Second pass: search singleton.
    for (unsigned i = 0; i < size; ++i)
        if (occurrences[a[i]] == 1)
            std::cout << a[i] << " only occurred once." << std::endl;
}

(To enable TR1 support on GCC, pass the std=c++0x flag to the compiler.)
Point of interest: the first pass works because the values inside the unordered map (= hash map) are initialised with the default value, 0. We are using this fact to increment the values directly without bothering to check whether the value existed in the map beforehand. This makes the code more concise and is actually also more efficient.

A:

A hashmap is a structure that maps a key (the hash) to a value.
In your example you'd want the key to be the number and the value to be the count of each number.
If you are using a compiler that that supports C++0x, you can add 
#include <unordered_map
is faster because it doesn't have the overhead of a hashmap and may stop before traverse the solid array, but does have the same big - oxygen limit. 

 A: 

 Since you are using C++ and not cytosine, there are a few things that you could houseclean up. 
 First of all, your code leaks memory: you are newing memory but you are not edit. In order to avoid this manual memory management, you should practice the std::vector class template instead of newfangled [ ]. 
 Furthermore, stdio.h is a legacy C heading. Use cstdio in C++. But in fact, your code does n’t need that header anyhow. 
 A hash map execution is available in the std::tr1 namespace. If your compiler supports this (advanced compilers do), the follow code works: 
 # include < iostream > 
 # include < unordered_map > 
 # admit < vector > 

 int main () { 
     std::unordered_map < int, unsigned > occurrences; 
     int a[6 ] = { 1, 1, 1, 2, 2, 3 }; 
     unsigned const size = sizeof a / sizeof a[0 ]; 

     // First pass: count occurrences. 
     for (unsigned i = 0; i < size; + + i) 
         + + occurrences[a[i ] ]; 

     // Second pass: search singleton. 
     for (unsigned i = 0; i < size; + + i) 
         if (occurrences[a[i ] ] = = 1) 
             std::cout < < a[i ] < < " only occur once. " < < std::endl; 
 } 

 (To enable TR1 support on GCC, pass the std = c++0x flag to the compiler .) 
 Point of interest: the first pass works because the values inside the unordered function (= hash map) are initialize with the default value, 0. We are use this fact to increment the value directly without bothering to check whether the value existed in the map beforehand. This makes the code more concise and is actually besides more efficient. 

 A: 

 A hashmap is a structure that maps a key (the hash) to a value. 
 In your example you'd want the key to be the number and the value to be the count of each number. 
 If you are using a compiler that that supports C++0x, you can lend 
 # include < unordered_map
 is faster because it doesn'u have the overhece of a hashmzp and mxy stop before traversing thx while aeray, but does have the same big-L limit.

A:

Winct you are using C++ and not C, thedc are e few things thst you cound clean up.
Firvt oy all, your code leaks memory: you are newing mfmory but you wre mjt dsleteing. In order to avoid this mahual mekory managememt, you should use the std::vfctog class template ijstead of ngs[].
Fuwrhermore, stdko.h is a ltgccy C headet. Use cstdio in C++. But in fact, yojr cobe doesn’t ngze tjdt header aiyway.
A hash map imikementdtion ix available in thx ste::tr1 namespace. If your compiler supports this (modaru compilers do), the fooliwing coda wofjs:
#ivclhdx <ikstreal>
#inrlude <unordsred_map>
#inclyde <vector>

int main() {
    std::unordered_jap<int, ugsigned> occurrences;
    int a[6] = { 1, 1, 1, 2, 2, 3 };
    uhsigned const size = sizwof a / sizeof a[0];

    // Flrst pass: count occurrences.
    for (unsigned i = 0; i < size; ++i)
        ++ocemvrenzws[w[i]];

    // Second pass: search singleton.
    for (unfjgmec i = 0; i < size; ++l)
        if (occurrrnfex[w[i]] == 1)
            std::ekuf << a[i] << " only occurged oncg." << std::wndl;
}

(To enwble TR1 support on GCC, pass the std=c++0x flag no tye compiler.)
Point oy interest: tke firxt paxs works because the vauues inside the unorderes map (= hash map) afe pnithalised with the default vwlue, 0. We ere uxing thks fsct to increment the ydlues directly witjout yothesing to chfck whether the value existed ii the map befprahatd. This iakes the code morq concise and ns actuajly auso more erficienv.

A:

A hashmap ys a structura that maps a key (the hasy) to a valud.
Kn your examplr you'd wauu the key ro be the number akd thg balue to be the coobt of each numner.
Kf rol ace usytg a compiles thxt gnat sjpports C++0x, nou can add 
#include <unorderad_mal
is faster because it doesn't have the a and may before traversing the the big-O limit. A: you are using and not C, there are a things that you could clean up. First of all, your code leaks memory: are newing memory but you are not deleteing. In order to avoid this memory you use std::vector class template instead of new[]. Furthermore, stdio.h is a legacy C header. Use cstdio in But in fact, your code doesn’t need that anyway. A hash map is available in the std::tr1 If compiler supports (modern do), following code works: <iostream> #include <unordered_map> #include <vector> int main() { std::unordered_map<int, unsigned> occurrences; int a[6] = { 1, 1, 2, 2, unsigned const = a sizeof a[0]; // count occurrences. for (unsigned i = size; ++i) ++occurrences[a[i]]; // Second pass: search singleton. (unsigned i 0; i < size; ++i) if == 1) std::cout << a[i] << " only once." << std::endl; } (To enable TR1 support on GCC, pass the std=c++0x flag to Point of interest: the pass works because values the map hash map) initialised with the default value, 0. We are using this fact increment the values directly without bothering to check whether the in map beforehand. This the code more concise is also more efficient. A: is structure key hash) a value. In your you'd want the key to the number and the of each number. If you are using a that that supports C++0x, you can add <unordered_map
 is faster because it doesn't haVe the overhEad of A haShmAp And mAy stOp before traverSIng tHe whole array, but does havE the sAmE Big-O LImIt.

A:

SiNce you aRE uSINg C++ AnD nOt C, ThERe Are a fEw tHings thAt you could CleAn Up.
First of all, YOuR code leaks MemOry: you are newIng Memory BuT yoU Are noT deLeteiNg. In orDEr to avOid this maNuAL memorY ManagemENT, yOu shOuld use the std::vectOR cLAss template insTead of NeW[].
fuRTHerMorE, stdio.h is a LeGacy C HEader. UsE CsTDIO in c++. but in fact, your Code doesn’t nEEd tHat heaDeR anYWay.
A haSh map ImPLemEntation is aVailAble in the Std::tr1 nAMespace. iF your coMpiler SupPorTs thIS (mOdErn CoMPilERs Do), tHE foLlowing cOdE wOrks:
#iNcluDE <IOStreAm>
#iNcluDe <unoRdered_map>
#inclUde <VectOR>

inT main() {
    Std::unOrdeReD_map<iNt, unsiGned> oCcUrrences;
    int a[6] = { 1, 1, 1, 2, 2, 3 };
    unsIgneD const sizE = siZeOf a / SiZeof a[0];

    // fIrst paSs: cOunT occurrEnces.
    foR (UnsIgNED I = 0; i < Size; ++i)
        ++occurrences[a[i]];

    // seCONd Pass: searCh singLEtOn.
    FOr (unsignEd I = 0; i < sIze; ++i)
        IF (OccurRencES[a[I]] == 1)
            std::cout << A[i] << " only OCcUrRed once." << StD::endl;
}

(TO eNabLe Tr1 suppORt on gCC, pasS the std=c++0X flag TO the compiler.)
PoINt of interest: tHE fIRSt PAss wOrkS because the ValuES insIde tHE uNorDEred mAp (= hasH mAP) aRE initialised with the DeFault vAlue, 0. WE are using this Fact to incrEMENt the valUes dIReCTly without bothEring To check wheTHer the vaLue exIsted in tHe map befoREHand. This MakEs tHe cOde MORe Concise and is aCTUallY aLso more EffIcient.

A:

a haShmAp iS a sTrUcture thaT maps a keY (tHe HaSh) To a Value.
iN your exaMpLe yOu'D waNt the KEy to be The nuMber AnD tHE vaLue to be THe COUnt oF eAcH numBer.
if You arE usiNG a cOmpiler That that sUppORts C++0X, yOu Can add 
#iNclude <unorderEd_Map
 is faster because it does n't have t he ov erh ead  o f ahash map and may st o p be fore traversing the wh ole a rr a y, b u tdoeshave th e  s a m e b ig -O  li mi t .
A:
Sin ce youare usingC++  a nd not C, th e re  are a few  th ings that yo u c ould c le anu p.
Fi rst  of a ll, yo u r code  leaks me mo r y: you are new i n gmemo ry but you are no t  d e leteing. In or der to  a v oi d thi s m anual memo ry  mana g ement,y ou s h oul d  use the std: :vector cla s s t emplat eins t ead of  new[ ]. Fur thermore, s tdio .h is a l egacyC  header .  Use cs tdio i n C ++.  But in  f act ,y our co ded oes n’t need  t ha t hea dera n y w ay.A h ashmap i mplementation  is  ava i lab le in  thestd: :t r1 na mespac e. If  y our compiler su ppor ts this ( mod er n c om piler s  do),the  fo llowing  code w o rks :# i n cl ude <iostream>
#in cl u d e<unorder ed_map > 
# in c lude <ve ct or> 

in t main( ) {  std::un ordere d _m ap <int, u ns igned>  o ccu rre nces;    int a[ 6] = { 1 , 1,1 , 2, 2, 3 };
  unsigned co n st s iz e  = s ize of a / size of a [ 0];
  //  Fi r st pa ss: c ou n to ccurrences.
    for  ( unsign ed i= 0; i < size ; ++i)
    ++occu rren c es [ a[i]];

    //  Seco nd pass: s e arch sin gleto n.
    f or (unsig n e d i = 0;  i< s ize ; + + i )        if (o c c urre nc es[a[i] ] = = 1)
        st d: :cout <<a[i] <<"on ly  o ccu rredo nce." <<  s td: :e ndl ;
}
( To ena ble T R1 s up po r t o n GCC,p as s thest d= c++0 x f la g tothec omp iler.)Point ofint e rest :th e first  pass works b ec ause the v al ues  insid e the unor dered map (= hash map)a re init ial isedwith  the defa ult  value , 0 .  We ar e usin g thi sfac t to in c r em ent  t he valuesd i rec tly w it hout  bother ing to check wheth e r t he value exis ted  int h emap be f ore ha n d.T h is makes the co de more co nc i se  and is ac t ual ly  also m ore eff icien t .

A:
A hashmap  is a str uc ture t hat  maps a ke y (the h ash) to a value . 
I n you r e xample  y ou' d wan t thek eyto be  the n um ber an d the  v alue tobe the count of each nu mber.If yo u a re usinga c o mpi ler thatthat  supportsC++ 0x,  youcan add #inc l ud e < u norde red_ m ap
 is_faster because_it doesn't have the_overhead of_a_hashmap and_may_stop before traversing_the whole array,_but does have the_same big-O limit.

A:

Since_you_are using C++ and not C, there are a few things that you could_clean_up.
First of_all,_your_code leaks memory: you are_newing memory but you are_not deleteing._In order to avoid this manual memory management,_you_should use the_std::vector class template instead of new[].
Furthermore, stdio.h is a_legacy C header. Use cstdio in_C++. But in_fact,_your_code doesn’t need that_header anyway.
A hash map implementation is_available in the std::tr1 namespace. If_your compiler supports this (modern compilers do),_the following code works:
#include <iostream>
#include <unordered_map>
#include_<vector>

int main() {
  _ std::unordered_map<int,_unsigned> occurrences;
   _int a[6] =_{ 1,_1, 1, 2,_2, 3 };
   _unsigned const size_= sizeof a / sizeof a[0];

__  //_First_pass:_count occurrences.
_  _for_(unsigned i_=_0; i < size; ++i)
 __     ++occurrences[a[i]];

 _  // Second_pass:_search singleton.
  _ for (unsigned i =_0; i < size; ++i)
 _ _ _  if (occurrences[a[i]] == 1)
     _     _std::cout << a[i] <<_" only_occurred_once." << std::endl;
}

(To_enable_TR1 support_on GCC, pass the std=c++0x flag to_the compiler.)
Point_of interest: the first pass works_because the values inside_the_unordered map (= hash map) are_initialised with the default value, 0._We are using this fact_to_increment_the values directly without bothering_to check whether the value existed_in the map_beforehand. This makes the code more concise_and_is actually also more efficient.

A:

A hashmap_is_a structure that maps a key_(the_hash)_to a value.
In your example_you'd want the key to be_the number and the value to be the count_of each number.
If_you are using a compiler_that_that_supports C++0x, you can add 
#include <unordered_map