C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

vector

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (French)
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Tue Mar 13, 2007 6:08 pm    Post subject: vector Reply with quote



Bonjour,
Y'a t il un moyen permettant l'insertion d'un element dans un vector,
tout en gardant l'ordre des elements deja inseres ?
exmple :
vector <int> list_of_integers;
list_of_integers est un ensemble d'entiers triés par ordre
descendant.
sans a avoir a faire un sort a chaue element insere ?

Merci.
Back to top
Michel Decima
Guest





PostPosted: Tue Mar 13, 2007 6:22 pm    Post subject: Re: vector Reply with quote



ccppc400 (AT) gmail (DOT) com a écrit :
Quote:
Bonjour,
Y'a t il un moyen permettant l'insertion d'un element dans un vector,
tout en gardant l'ordre des elements deja inseres ?
exmple :
vector <int> list_of_integers;
list_of_integers est un ensemble d'entiers triés par ordre
descendant.
sans a avoir a faire un sort a chaue element insere ?

int value = 42;
list_of_integers.insert( lower_bound( list_of_integers.begin(),
list_of_integers.end(),
value,
greater<int>() ),
value );
Back to top
Guest






PostPosted: Tue Mar 13, 2007 7:55 pm    Post subject: Re: vector Reply with quote



Merci,
Dans le cas ou j'ai :

vector <c_objects*> list_of_objects;
*c_objects : contient les operateurs < > == <= >
Comment pourrai-je inserer les element afin de garantir que les
objects ponites par c_objects* sont correctement tries ?

Merci.


On 13 mar, 14:22, Michel Decima <michel.dec...@orange-ft.com> wrote:
Quote:
ccppc...@gmail.com a écrit :

Bonjour,
Y'a t il un moyen permettant l'insertion d'un element dans un vector,
tout en gardant l'ordre des elements deja inseres ?
exmple :
vector <int> list_of_integers;
list_of_integers est un ensemble d'entiers triés par ordre
descendant.
sans a avoir a faire un sort a chaue element insere ?

int value = 42;
list_of_integers.insert( lower_bound( list_of_integers.begin(),
list_of_integers.end(),
value,
greater<int>() ),
value );
Back to top
Michel Decima
Guest





PostPosted: Tue Mar 13, 2007 8:14 pm    Post subject: Re: vector Reply with quote

ccppc400 (AT) gmail (DOT) com a écrit :
Quote:
Merci,
Dans le cas ou j'ai :

vector <c_objects*> list_of_objects;
*c_objects : contient les operateurs < > == <= >=

Comment pourrai-je inserer les element afin de garantir que les
objects ponites par c_objects* sont correctement tries ?


template <typename T>
struct indirect_greater : public binary_function<T, T, bool>

{
bool operator()(T lhs, T rhs) const
{
return *lhs > *rhs ;
}
};

c_object* value = new c_object( 42 );
list_of_objects.insert( lower_bound( list_of_objects.begin(),
list_of_objects.end(),
value,
indirect_greater<c_object*>() ),
value );
Back to top
Guest






PostPosted: Tue Mar 13, 2007 9:46 pm    Post subject: Re: vector Reply with quote

Merci.

On 13 mar, 16:14, Michel Decima <michel.dec...@orange-ft.com> wrote:
Quote:
ccppc...@gmail.com a écrit :

Merci,
Dans le cas ou j'ai :

vector <c_objects*> list_of_objects;
*c_objects : contient les operateurs < > == <=
Comment pourrai-je inserer les element afin de garantir que les
objects ponites par c_objects* sont correctement tries ?

template <typename T
struct indirect_greater : public binary_function<T, T, bool

{
bool operator()(T lhs, T rhs) const
{
return *lhs > *rhs ;
}

};

c_object* value = new c_object( 42 );
list_of_objects.insert( lower_bound( list_of_objects.begin(),
list_of_objects.end(),
value,
indirect_greater<c_object*>() ),
value );
Back to top
Fabien LE LEZ
Guest





PostPosted: Tue Mar 13, 2007 10:33 pm    Post subject: Re: vector Reply with quote

http://www.usenet-fr.net/fr.usenet.reponses/usenet/repondre-sur-usenet.html
Back to top
JBB
Guest





PostPosted: Fri Mar 16, 2007 2:32 pm    Post subject: Re: vector Reply with quote

ccppc400 (AT) gmail (DOT) com a écrit :
Quote:
Bonjour,
Y'a t il un moyen permettant l'insertion d'un element dans un vector,
tout en gardant l'ordre des elements deja inseres ?
exmple :
vector <int> list_of_integers;
list_of_integers est un ensemble d'entiers triés par ordre
descendant.
sans a avoir a faire un sort a chaue element insere ?

Merci.

et avec un set<int> ça le ferait pas mieux?

(à supposer sue tu ne veuille pas mettre 2 fois la même valeur)
tu n'a plus alors qu'à parcourir le set en sens inverse.
Back to top
gpg
Guest





PostPosted: Tue Apr 17, 2007 2:41 am    Post subject: Re: vector [bis] Reply with quote

Michel Decima a écrit :
Quote:
ccppc400 (AT) gmail (DOT) com a écrit :
Merci,
Dans le cas ou j'ai :

vector <c_objects*> list_of_objects;
*c_objects : contient les operateurs < > == <= >=

Comment pourrai-je inserer les element afin de garantir que les
objects ponites par c_objects* sont correctement tries ?


template <typename T
struct indirect_greater : public binary_function<T, T, bool

{
bool operator()(T lhs, T rhs) const
{
return *lhs > *rhs ;
}
};

c_object* value = new c_object( 42 );
list_of_objects.insert( lower_bound( list_of_objects.begin(),
list_of_objects.end(),
value,
indirect_greater<c_object*>() ),
value );


Bonjour,
je me suis penché sur la question et voila ce que j'ai fais :

//common.h
#ifndef _common_h_
#define _common_h_

#include <algorithm>
#include <functional>

template <typename T>
struct indirect_greater : public binary_function<T, T, bool>
{
bool operator()(T lhs, T rhs) const
{
return *lhs > *rhs ;
}
};

#endif




//Interface.h
#ifndef _interface_h_
#define _interface_h_

#include "common.h"
#include <vector>
#include <functional>




class C_TRACK
{
public:
C_TRACK(const char* p_track_name);
~C_TRACK();
const char* GetName() const;
bool operator<(const C_TRACK& p_track);
bool operator>(const C_TRACK& p_track);
private:
char m_track_name[100];
};



class C_ALBUM
{
public:
C_ALBUM(const char* p_album_name);
~C_ALBUM();
void AddTrack(C_TRACK* p_track);
void PrintData(void);
private:
char m_album_name[100];
std::vector <C_TRACK*> m_track_list;
};


#endif



//Interface.cpp
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <algorithm>
#include "interface.h"





C_TRACK::C_TRACK(const char* p_track_name)
{
strcpy(m_track_name,p_track_name);
}
C_TRACK::~C_TRACK()
{
}

const char* C_TRACK::GetName(void) const
{
return (m_track_name);
}

bool C_TRACK::operator<(const C_TRACK& p_track)
{
if (strcmp (m_track_name,p_track.GetName())<0)
{
return (true);
}
else
return (false);
}


C_ALBUM::C_ALBUM(const char* p_album_name)
{
strcpy(m_album_name,p_album_name);
}
C_ALBUM::~C_ALBUM()
{
}
void C_ALBUM::AddTrack(C_TRACK* p_track)
{
m_track_list.insert(lower_bound(m_track_list.begin(),
m_track_list.end(),
p_track,
indirect_greater<C_TRACK*>()),
p_track);
}
void C_ALBUM::PrintData(void)
{
if (!m_track_list.empty())
{
for (unsigned short i=0;i<m_track_list.size();i++)
{
printf("Track %s \n",m_track_list[i]->GetName());
}
}
}




common.h:8: error: expected template-name before '<' token
common.h:8: error: expected `{' before '<' token
common.h:8: error: expected unqualified-id before '<' token
common.h:8: error: expected `;' before '<' token

interface.cpp: In member function `void C_ALBUM::AddTrack(C_TRACK*)':
interface.cpp:48: error: `greater' undeclared (first use this function)

interface.cpp:48: error: (Each undeclared identifier is reported only
once for each function it appears in.)
interface.cpp:48: error: expected primary-expression before '*' token
interface.cpp:48: error: expected primary-expression before '>' token
interface.cpp:48: error: expected primary-expression before ')' token

make.exe: *** [interface.o] Error 1


(voir http://rafb.net/p/aSaOzp25.html)

--

Je ne sais pas ce que j'ai réellement oublié, merci de votre aide.
Back to top
gpg
Guest





PostPosted: Tue Apr 17, 2007 3:21 am    Post subject: Re: vector [bis] Reply with quote

gpg a écrit :
Quote:
Michel Decima a écrit :
ccppc400 (AT) gmail (DOT) com a écrit :
Merci,
Dans le cas ou j'ai :

vector <c_objects*> list_of_objects;
*c_objects : contient les operateurs < > == <= >=

Comment pourrai-je inserer les element afin de garantir que les
objects ponites par c_objects* sont correctement tries ?


template <typename T
struct indirect_greater : public binary_function<T, T, bool

{
bool operator()(T lhs, T rhs) const
{
return *lhs > *rhs ;
}
};

c_object* value = new c_object( 42 );
list_of_objects.insert( lower_bound( list_of_objects.begin(),
list_of_objects.end(),
value,
indirect_greater<c_object*>() ),
value );


Bonjour,
je me suis penché sur la question et voila ce que j'ai fais :

//common.h
#ifndef _common_h_
#define _common_h_

#include <algorithm
#include <functional

template <typename T
struct indirect_greater : public binary_function<T, T, bool
{
bool operator()(T lhs, T rhs) const
{
return *lhs > *rhs ;
}
};

#endif




//Interface.h
#ifndef _interface_h_
#define _interface_h_

#include "common.h"
#include <vector
#include <functional




class C_TRACK
{
public:
C_TRACK(const char* p_track_name);
~C_TRACK();
const char* GetName() const;
bool operator<(const C_TRACK& p_track);
bool operator>(const C_TRACK& p_track);
private:
char m_track_name[100];
};



class C_ALBUM
{
public:
C_ALBUM(const char* p_album_name);
~C_ALBUM();
void AddTrack(C_TRACK* p_track);
void PrintData(void);
private:
char m_album_name[100];
std::vector <C_TRACK*> m_track_list;
};


#endif



//Interface.cpp
#include <stdlib.h
#include <stdio.h
#include <string.h

#include <algorithm
#include "interface.h"





C_TRACK::C_TRACK(const char* p_track_name)
{
strcpy(m_track_name,p_track_name);
}
C_TRACK::~C_TRACK()
{
}

const char* C_TRACK::GetName(void) const
{
return (m_track_name);
}

bool C_TRACK::operator<(const C_TRACK& p_track)
{
if (strcmp (m_track_name,p_track.GetName())<0)
{
return (true);
}
else
return (false);
}


C_ALBUM::C_ALBUM(const char* p_album_name)
{
strcpy(m_album_name,p_album_name);
}
C_ALBUM::~C_ALBUM()
{
}
void C_ALBUM::AddTrack(C_TRACK* p_track)
{
m_track_list.insert(lower_bound(m_track_list.begin(),
m_track_list.end(),
p_track,
indirect_greater<C_TRACK*>()),
p_track);
}
void C_ALBUM::PrintData(void)
{
if (!m_track_list.empty())
{
for (unsigned short i=0;i<m_track_list.size();i++)
{
printf("Track %s \n",m_track_list[i]->GetName());
}
}
}




common.h:8: error: expected template-name before '<' token
common.h:8: error: expected `{' before '<' token
common.h:8: error: expected unqualified-id before '<' token
common.h:8: error: expected `;' before '<' token

interface.cpp: In member function `void C_ALBUM::AddTrack(C_TRACK*)':
interface.cpp:48: error: `greater' undeclared (first use this function)

interface.cpp:48: error: (Each undeclared identifier is reported only
once for each function it appears in.)
interface.cpp:48: error: expected primary-expression before '*' token
interface.cpp:48: error: expected primary-expression before '>' token
interface.cpp:48: error: expected primary-expression before ')' token

make.exe: *** [interface.o] Error 1


(voir http://rafb.net/p/aSaOzp25.html)

--

Je ne sais pas ce que j'ai réellement oublié, merci de votre aide.

Il me semble que le ompilateur se plaint du fait qu'il n'y a aucun
operateur < prenant des arguments C_TRACK des deux cotés de l'operation .
Back to top
gpg
Guest





PostPosted: Tue Apr 17, 2007 6:54 am    Post subject: Re: vector [bis] Reply with quote

gpg a écrit :
Quote:
gpg a écrit :
Michel Decima a écrit :
ccppc400 (AT) gmail (DOT) com a écrit :
Merci,
Dans le cas ou j'ai :

vector <c_objects*> list_of_objects;
*c_objects : contient les operateurs < > == <= >=

Comment pourrai-je inserer les element afin de garantir que les
objects ponites par c_objects* sont correctement tries ?


template <typename T
struct indirect_greater : public binary_function<T, T, bool

{
bool operator()(T lhs, T rhs) const
{
return *lhs > *rhs ;
}
};

c_object* value = new c_object( 42 );
list_of_objects.insert( lower_bound( list_of_objects.begin(),
list_of_objects.end(),
value,
indirect_greater<c_object*>() ),
value );


Bonjour,
je me suis penché sur la question et voila ce que j'ai fais :

//common.h
#ifndef _common_h_
#define _common_h_

#include <algorithm
#include <functional

template <typename T
struct indirect_greater : public binary_function<T, T, bool
{
bool operator()(T lhs, T rhs) const
{
return *lhs > *rhs ;
}
};

#endif




//Interface.h
#ifndef _interface_h_
#define _interface_h_

#include "common.h"
#include <vector
#include <functional




class C_TRACK
{
public:
C_TRACK(const char* p_track_name);
~C_TRACK();
const char* GetName() const;
bool operator<(const C_TRACK& p_track);
bool operator>(const C_TRACK& p_track); private:
char m_track_name[100];
};



class C_ALBUM
{
public:
C_ALBUM(const char* p_album_name);
~C_ALBUM();
void AddTrack(C_TRACK* p_track);
void PrintData(void);
private:
char m_album_name[100];
std::vector <C_TRACK*> m_track_list;
};


#endif



//Interface.cpp
#include <stdlib.h
#include <stdio.h
#include <string.h

#include <algorithm
#include "interface.h"





C_TRACK::C_TRACK(const char* p_track_name)
{
strcpy(m_track_name,p_track_name);
}
C_TRACK::~C_TRACK()
{
}

const char* C_TRACK::GetName(void) const
{
return (m_track_name);
}

bool C_TRACK::operator<(const C_TRACK& p_track)
{
if (strcmp (m_track_name,p_track.GetName())<0)
{
return (true);
}
else
return (false);
}


C_ALBUM::C_ALBUM(const char* p_album_name)
{
strcpy(m_album_name,p_album_name);
}
C_ALBUM::~C_ALBUM()
{
}
void C_ALBUM::AddTrack(C_TRACK* p_track)
{
m_track_list.insert(lower_bound(m_track_list.begin(),
m_track_list.end(),
p_track,
indirect_greater<C_TRACK*>()),
p_track);
}
void C_ALBUM::PrintData(void)
{
if (!m_track_list.empty())
{
for (unsigned short i=0;i<m_track_list.size();i++)
{
printf("Track %s \n",m_track_list[i]->GetName());
}
}
}




common.h:8: error: expected template-name before '<' token
common.h:8: error: expected `{' before '<' token
common.h:8: error: expected unqualified-id before '<' token
common.h:8: error: expected `;' before '<' token

interface.cpp: In member function `void C_ALBUM::AddTrack(C_TRACK*)':
interface.cpp:48: error: `greater' undeclared (first use this function)

interface.cpp:48: error: (Each undeclared identifier is reported only
once for each function it appears in.)
interface.cpp:48: error: expected primary-expression before '*' token
interface.cpp:48: error: expected primary-expression before '>' token
interface.cpp:48: error: expected primary-expression before ')' token

make.exe: *** [interface.o] Error 1


(voir http://rafb.net/p/aSaOzp25.html)

--

Je ne sais pas ce que j'ai réellement oublié, merci de votre aide.

Il me semble que le ompilateur se plaint du fait qu'il n'y a aucun
operateur < prenant des arguments C_TRACK des deux cotés de l'operation .



résolu.
Bonne journée.
Back to top
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (French) All times are GMT
Page 1 of 1

 
 


Powered by phpBB © 2001, 2006 phpBB Group