首页 > 解决方案 > 我在链接中的整数插入程序从 16 开始转换整数:(2,4,6,8,10,12,14,875311656,942421548,741355820)

问题描述

这是我实现的链接类的插入方法,数据类型是整数(typedef int TELEM)。通过显示存储的数字,从16开始显示其他值太大

包括

typedef int TELEM;

// liste d'éléments de type TELEM
class liste {
 public:
      liste::liste() : m_nb(0) ,m_tetefile(0)
{
  m_tetefile = new TELEM[m_nb+1] ;
}


liste::~liste()
{
  m_nb = 0;
  delete m_tetefile;
}

bool liste::est_vide() const
{
  return m_nb == 0;
}

int liste::taille() const
{
  return m_nb;
}

const TELEM& liste::operator[](int i) const
{
  assert((i>=1) && (i<=m_nb));

  return (m_tetefile[i]);
}

void liste::inserer(const TELEM& e, int i)
{  
  assert((i>=1) && (i<=m_nb+1));
  
  for (int k = m_nb ; k >= i ; --k)
    m_tetefile[k+1] = m_tetefile[k];      
  m_tetefile[i] = e;
  std::cout << e <<std::endl;
  std::cout << m_tetefile[i] <<std::endl;
  
  m_nb++;

}

private:    
  TELEM m_nb ;
  TELEM *m_tetefile;



};

std::ostream& operator<<(std::ostream& os, const liste& l)
{
  os << '(';
  if (!l.est_vide())
    os << l[1];
    for (int i=2; i<=l.taille(); ++i)
      os << ',' << l[i];  
  os << ')';
  return os;
}

从 16 ca 给我这个 (2,4,6,8,10,12,14,875311656,942421548,741355820) 而不是 (2,4,6,8,10,12,14,16,18,20)

标签: c++11

解决方案


推荐阅读