如何用单链表实现两大整数相加减?

神的孩子 2011-03-03 09:14:00
那个大整数要怎么表示呢,用字符串还是其它?还有单链表怎么来存那大整数?望各位大虾给点帮助,菜鸟感激不尽!!!
...全文
647 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
pmars 2011-03-03
  • 打赏
  • 举报
回复
大数直接 字符串 或者 用 vector数组 ,多少进制自己定就行了!
没用过单链表来写大数,不过,我想用的话最好给地位放在链表头的一方!
DavidGaku 2011-03-03
  • 打赏
  • 举报
回复
用单链表来存储,第i个结点存储该数字的第i位 加减运算模拟小学算术
無_1024 2011-03-03
  • 打赏
  • 举报
回复

ostream &operator << (ostream & output,const HugeInt &num )
{
//HugeInt h(num);
HugeInt h1;
h1.ReverseList( num );
Listend *currentPtr = h1.firstPtr;
if( h1.fuhao == 1 )
output<<"-";
if( currentPtr == NULL)
{
output<<"0"<<endl;
return output;
}
else
{
while( currentPtr != NULL && currentPtr->getData() == '0' )
{
currentPtr=currentPtr->getNextPtr();
if( !currentPtr->getNextPtr() )
cout<<"0";
}
while( currentPtr != NULL )
{
output<<currentPtr->getData();
currentPtr=currentPtr->getNextPtr();
}
}
//output<<endl;
return output;
}
void HugeInt::insert( const char &value )
{
Listend *newPtr = getNewNode( value ), *previousPtr,*currentPtr;
previousPtr = NULL ;
currentPtr = firstPtr;
while( currentPtr != NULL )
{
previousPtr = currentPtr;
currentPtr = currentPtr->nextPtr;
}
if( previousPtr == NULL )
{
newPtr->nextPtr = firstPtr;
firstPtr = newPtr;
}
else
{
previousPtr -> nextPtr = newPtr;
newPtr -> nextPtr = currentPtr;
}
}

HugeInt HugeInt::ReverseList( HugeInt num)
{
fuhao = num.fuhao;
if( ( num.firstPtr == NULL ) || ( num.firstPtr->getNextPtr() == NULL) )
{
firstPtr = num.firstPtr;
return *this;
}
Listend *previousPtr =firstPtr= new Listend(NULL),*currentPtr = num.firstPtr,*currentPtr2;
while( currentPtr->getNextPtr() != NULL )
{
currentPtr2 = currentPtr;
currentPtr = currentPtr->getNextPtr();
currentPtr2->nextPtr = firstPtr;
firstPtr = currentPtr2;
}
//firstPtr = firstPtr;
return *this;
}
const HugeInt & HugeInt::operator =( const HugeInt &op2 )
{
if( &op2 != this )
{
while( firstPtr && firstPtr->getData() )
{
Listend *previousPtr1 = firstPtr;
firstPtr = firstPtr->getNextPtr();
delete previousPtr1;
}
Listend *currentPtr = op2.firstPtr,*previousPtr = firstPtr =new Listend(NULL);
fuhao = op2.fuhao;
while( currentPtr && currentPtr->getData() )
{
previousPtr->data = currentPtr->getData();
currentPtr = currentPtr->getNextPtr();
previousPtr = previousPtr->nextPtr=new Listend(NULL);
}
}
return *this;
}
HugeInt HugeInt::operator +( HugeInt &op2 )
{
HugeInt temp1(op2),temp2(*this),temp3;
//cout<<temp1<<endl<<temp2;
Listend *currentPtr = temp3.firstPtr = new Listend( NULL );
int carry = 0;
int t;
while( temp1.firstPtr->getData() && temp2.firstPtr->getData() )
{
t = temp1.firstPtr->getData() + temp2.firstPtr->getData() + carry -'0'-'0';
if( t > 9 )
{
carry = 1;
t %=10;
}
else
{
carry = 0;
}
currentPtr->setData( t + '0' );
temp1.firstPtr = temp1.firstPtr->getNextPtr();
temp2.firstPtr = temp2.firstPtr->getNextPtr();
currentPtr = currentPtr->nextPtr = new Listend(NULL);
}
while( temp1.firstPtr->getData() )
{
t = temp1.firstPtr->getData() + carry -'0';
if( t > 9 )
{
carry = 1;
t %=10;
}
else
carry = 0;
currentPtr->setData( t + '0' );
currentPtr = currentPtr->nextPtr = new Listend(NULL);
temp1.firstPtr = temp1.firstPtr->getNextPtr();
}
while( temp2.firstPtr->getData() )
{
t = temp2.firstPtr->getData() + carry -'0';
if( t > 9 )
{
carry = 1;
t %=10;
}
else
carry = 0;
currentPtr->setData( t + '0' );
currentPtr = currentPtr->nextPtr = new Listend( NULL );
temp2.firstPtr = temp2.firstPtr->getNextPtr();
}
if ( carry == 1 )
{
currentPtr->setData( carry + '0' );
currentPtr = currentPtr->nextPtr = new Listend( NULL );
}
return temp3;
}
HugeInt HugeInt::operator -( HugeInt & op2 )//*this - op2 temp2 - temp1
{
HugeInt temp1,temp2,temp3;
if(*this < op2 )
{
temp3.fuhao = 1;
temp1 = *this;
temp2 = op2;
}
else
{
temp1 = op2 ;
temp2= *this;
}
Listend *currentPtr = temp3.firstPtr = new Listend( NULL );
int carry = 0;
int t;
while( temp1.firstPtr->getData() && temp2.firstPtr->getData() )
{
t = temp2.firstPtr->getData() - temp1.firstPtr->getData() - carry;
if( t < 0 )
{
carry = 1;
t += 10;
}
else
{
carry = 0;
}
currentPtr->setData( t + '0' );
temp1.firstPtr = temp1.firstPtr->getNextPtr();
temp2.firstPtr = temp2.firstPtr->getNextPtr();
currentPtr = currentPtr->nextPtr = new Listend(NULL);
}
while( temp1.firstPtr->getData() )
{
t = temp1.firstPtr->getData() - carry -'0';
if( t < 0 )
{
carry = 1;
t += 10;
}
else
carry = 0;
currentPtr->setData( t + '0' );
currentPtr = currentPtr->nextPtr = new Listend(NULL);
temp1.firstPtr = temp1.firstPtr->getNextPtr();
}
while( temp2.firstPtr->getData() )
{
t = temp2.firstPtr->getData() - carry -'0';
if( t < 0 )
{
carry = 1;
t += 10;
}
else
carry = 0;
currentPtr->setData( t + '0' );
currentPtr = currentPtr->nextPtr = new Listend( NULL );
temp2.firstPtr = temp2.firstPtr->getNextPtr();
}
return temp3;
}
HugeInt HugeInt::mult( const HugeInt &op2 , int data )
{
HugeInt temp2(op2),temp3;
int carry = 0;
int t;
Listend *currentPtr = temp3.firstPtr = new Listend( NULL );
while( temp2.firstPtr->getData() )
{
t = data * ( temp2.firstPtr->getData() - '0' ) + carry;
if( t > 9 )
{
carry = t / 10;
t %= 10;
}
else
{
carry = 0;
}
currentPtr->setData( t + '0' );
currentPtr = currentPtr->nextPtr = new Listend( NULL );
temp2.firstPtr = temp2.firstPtr->getNextPtr();
}
if( carry != 0 )
{
currentPtr->setData( carry + '0' );
currentPtr = currentPtr->nextPtr = new Listend( NULL );
}
return temp3;
}
HugeInt HugeInt::operator *( HugeInt &op2 )
{
HugeInt temp1(op2),temp2(*this),temp3,temp4("0");
int carry = 0;
int t = 0;
Listend *currentPtr = temp3.firstPtr = new Listend( NULL );
while( temp1.firstPtr->getData() )
{
temp2 = *this;
temp3 = mult( temp3 , 10 ) + mult( temp2 , ( temp1.firstPtr->getData() - '0' ) );
temp4 =temp4 + mult( temp2 , ( temp1.firstPtr->getData() - '0' ) );
temp4.firstPtr = temp4.firstPtr->getNextPtr();
temp1.firstPtr = temp1.firstPtr->getNextPtr();
}
return temp3;
}
//--------------------移位相减得除法
#if 1
HugeInt HugeInt::operator /( HugeInt & op2 )// temp2 / temp1 *this / op2
{
int k = 0;
HugeInt temp2( ReverseList( *this ) ),temp1(ReverseList( op2 )),temp3,temp4,temp5,temp6("0"),temp7,temp("0");
Listend *currentPtr = temp5.firstPtr = new Listend( NULL );
temp3 = temp1;
temp4 = temp2;
while( temp3.firstPtr->getData() && temp4.firstPtr->getData() )
{
const char t = temp4.firstPtr->getData();
currentPtr->setData( t );
currentPtr = currentPtr->nextPtr = new Listend( NULL );
temp3.firstPtr = temp3.firstPtr->getNextPtr();
temp4.firstPtr = temp4.firstPtr->getNextPtr();
}
if( temp1 == temp )
{
cout<<"ERROR, The dividend is zero!"<<endl;
return temp;
}
while( temp5 >= temp1 && temp5 > temp )
{
k = 0;
temp5 = temp5 - temp1;
temp5 = ClearZero( temp5 );
k ++;
}
temp.firstPtr->setData( k + '0' );
while( temp4.firstPtr->getData() )
{
k = 0;
Listend *currentPtr2 = new Listend( NULL );
const char t = temp4.firstPtr->getData();
currentPtr2->setData( t );
currentPtr2->nextPtr = temp5.firstPtr;
temp5.firstPtr = currentPtr2;
temp4.firstPtr = temp4.firstPtr->getNextPtr();
while( temp5 >= temp1 && temp5 > temp )
{
temp5 = temp5 - temp1;
temp5 = ClearZero( temp5 );
k ++;
}
temp6.firstPtr->setData( k + '0' );
temp = mult( temp , 10 ) + temp6;
}
return temp;
}
#endif

#if 0///--时间复杂度比较高的除法 用减法实现的

HugeInt HugeInt::operator /( HugeInt & op2 )// temp2 / temp1 *this / op2
{
HugeInt temp("0"),temp1(op2),temp2(*this),temp4;
int k = 0;
if( op2 == temp )
{
cout<<"ERROR, The dividend is zero!"<<endl;
return temp;
}
while( temp2 >= temp1 && temp2 > temp )
{
temp4 = temp2 - temp1;
temp2 = temp4;
temp2 = ClearZero( temp2 );
k ++;
}
HugeInt temp3(k);
return temp3;
}
#endif
HugeInt HugeInt::ClearZero( HugeInt & num)
{
HugeInt temp,temp1("0");
temp.ReverseList( num );
//cout<<num<<ends<<temp<<endl;
while( temp.firstPtr->getData() == '0' )
{
temp.firstPtr = temp.firstPtr->getNextPtr();
//cout<<temp.firstPtr->getData()<<"---";
}
//cout<<endl<<"qing 0 is "<<temp<<endl;
temp1.ReverseList( temp );
//cout<<"after qing 0 "<<temp1<<endl;
return temp1;
}
bool HugeInt::operator ==( const HugeInt & op2)
{
HugeInt temp1( op2 ),temp2( *this );
while( temp1.firstPtr->getData() && temp2.firstPtr->getData() )
{
if( temp1.firstPtr->getData() != temp2.firstPtr->getData())
return false;
temp1.firstPtr = temp1.firstPtr->getNextPtr();
temp2.firstPtr = temp2.firstPtr->getNextPtr();
}
if( temp1.firstPtr->getData() || temp2.firstPtr->getData() )
return false;
return true;
}
bool HugeInt::operator !=( const HugeInt & op2 )
{
return !(*this == op2);
}
bool HugeInt::operator < ( const HugeInt & op2 )
{
int i = 0 ,j = 0;
HugeInt temp1( op2 ),temp2( *this );
while( temp1.firstPtr->getData() && temp2.firstPtr->getData() )
{
if( temp1.firstPtr->getData() < temp2.firstPtr->getData() )
{
i = 1;
j = 0;
}
else if( temp1.firstPtr->getData() > temp2.firstPtr->getData() )
{
i = 0;
j = 1;
}
temp1.firstPtr = temp1.firstPtr->getNextPtr();
temp2.firstPtr = temp2.firstPtr->getNextPtr();
}
if( temp1.firstPtr->getData() )
return true;
if( temp2.firstPtr->getData() )
return false;
if( i >= j )
return false;
return true;
}
bool HugeInt::operator <=( const HugeInt & op2 )
{
return (*this < op2 ) || ( *this == op2 );
}
bool HugeInt::operator >=( const HugeInt & op2 )
{
return !( *this < op2 );
}
bool HugeInt::operator >( const HugeInt & op2 )
{
return !( *this <= op2 );
}

無_1024 2011-03-03
  • 打赏
  • 举报
回复

//function hugeint.cpp

#include "hugeint.h"
#include <iostream>
#include <cassert>
#include <cstdlib>

using std::istream;
using std::ostream;
using std::cin;
using std::cout;
using std::endl;
using std::ends;

HugeInt::HugeInt():fuhao(0)
{
firstPtr = NULL;
}
HugeInt::HugeInt( long val ):firstPtr( NULL ),fuhao(0)
{
long number = val ;
while( val!=0 )
{
insert((char)(val % 10 + '0' ));
val/=10;
}
}
HugeInt::HugeInt( const char * str ):firstPtr( NULL ),fuhao(0)
{
int i = strlen(str)-1;
while( i >= 0 )
{
insert( str[i]);
i--;
}
}
HugeInt::HugeInt( const HugeInt & num )
{
Listend *currentPtr = num.firstPtr,*previousPtr = firstPtr =new Listend(NULL);
fuhao = num.fuhao;
while( currentPtr && currentPtr->getData() != NULL )
{
previousPtr->data = currentPtr->getData();
currentPtr = currentPtr->getNextPtr();
previousPtr = previousPtr->nextPtr=new Listend(NULL);
}
}
Listend* HugeInt::getNewNode( const char &value )
{
Listend *ptr = new Listend( value );
assert( ptr != NULL );
return ptr;
}
無_1024 2011-03-03
  • 打赏
  • 举报
回复

//function listend.h

#ifndef LISTEND_H
#define LISTEND_H
class Listend
{
friend class HugeInt;
public:
Listend( const char & );
char getData() const;
void setData( const char & );
void setNextNode( Listend * );
Listend *getNextPtr() const;
private:
char data;
Listend * nextPtr;
};
#endif

//function hugeint.h

#ifndef HUGEINT_H
#define HUGEINT_H
#include <iostream>
#include "listend.h"
using std::istream;
using std::ostream;

class HugeInt
{
friend ostream &operator << (ostream &,const HugeInt &);
public:
HugeInt ();
HugeInt ( long );
HugeInt ( const char * );
HugeInt ( const HugeInt & );
HugeInt mult( const HugeInt & ,int );
HugeInt division( HugeInt &, HugeInt &,HugeInt &);
//HugeInt division(HugeInt &, HugeInt &);
HugeInt operator+ ( HugeInt & );
HugeInt operator- ( HugeInt & );
HugeInt operator* ( HugeInt & );
HugeInt operator/ ( HugeInt & );
const HugeInt & operator= (const HugeInt & );
bool operator == ( const HugeInt & );
bool operator != ( const HugeInt & );
bool operator < ( const HugeInt & );
bool operator > ( const HugeInt & );
bool operator >= ( const HugeInt & );
bool operator <= ( const HugeInt & );
void insert( const char & );
HugeInt ReverseList( HugeInt );
HugeInt ClearZero( HugeInt & );
private:
int fuhao;
Listend *firstPtr;
Listend *getNewNode( const char & );

};
#endif

//function listend.cpp

#include "listend.h"
#include <iostream>
Listend::Listend( const char & info ):data( info ),nextPtr( NULL ){ }

char Listend::getData() const
{
return data;
}
Listend *Listend::getNextPtr() const
{
return nextPtr;
}
void Listend::setData( const char &value )
{
data = value;
}
void Listend::setNextNode( Listend *next )
{
nextPtr = next;
}


//function test.cpp

#include <iostream>
#include "hugeint.h"
#include <cstdlib>

using std::cin;
using std::cout;
using std::endl;

int main()
{
HugeInt h(9998),h2,h5,h6(9998);
HugeInt h4("99989998");
HugeInt h3(h);

cout<<" h4 + h"<<endl;
cout<<( h4 + h)<<endl;

cout<<" h4 * h"<<endl;
cout<<( h4 * h)<<endl;

cout<<" h4 - h"<<endl;
cout<<( h4 - h)<<endl;
cout<<" h - h6"<<endl;
cout<<( h - h6)<<endl;

cout<<" h4 / h"<<endl;
cout<<( h4 / h)<<endl;

cout<<"h6 == h "<<( h6 == h )<<endl;
cout<<"h4 != h "<<( h4 != h )<<endl;
cout<<"h4 < h "<<( h4 < h )<<endl;
cout<<"h4 <= h "<<( h4 <= h )<<endl;
cout<<"h4 > h "<<( h4 > h )<<endl;
cout<<"h4 >= h "<<( h4 >= h )<<endl;

return 0;
}
bdmh 2011-03-03
  • 打赏
  • 举报
回复
赵4老师 2011-03-03
  • 打赏
  • 举报
回复
如何用软件工程实现两个一亿亿亿亿亿亿亿亿亿亿亿亿亿亿亿亿位数相加减?(^_^)
無_1024 2011-03-03
  • 打赏
  • 举报
回复
如果需要的话 等到晚上回来还没有结贴的话 就发给你 太长了 一下只能发三个帖子 以前的一个作业题 有点长
無_1024 2011-03-03
  • 打赏
  • 举报
回复
发错了啊 悲剧
無_1024 2011-03-03
  • 打赏
  • 举报
回复


#ifndef TERM_H
#define TERM_H
#include <iostream>

using std::ostream;

class Term
{
friend ostream & operator<<(ostream &,const Term &);
friend class Polynominal;
private:
int coef;
int exp;
Term* link;
public:
Term(int c, int e);
Term(int c, int e, Term* nxt);
Term* InsertAfter(int c, int e);
};

#endif


#ifndef POLYNOMIAL_H
#define POLYNOMIAL_H

#include "term.h"
#include <iostream>

using std::ostream;
using std::istream;

class Polynominal
{
friend ostream& operator<<(ostream& out,const Polynominal& x);
friend istream& operator>>(istream& in, Polynominal& x);
friend Polynominal& operator + (Polynominal& a, Polynominal& b);
friend Polynominal& operator - (Polynominal& a, Polynominal& b);
friend Polynominal& operator * (Polynominal& a, Polynominal& b);
public:
Polynominal();
Polynominal(Polynominal& r);
~Polynominal();
void AddTerms(istream& in);
void Output(ostream& out)const;
Polynominal& PolyAdd(Polynominal& r);
Polynominal& PolyMul(Polynominal& r);
Polynominal& PolySub(Polynominal& r);
Polynominal& operator=(Polynominal& r);
Polynominal& operator += (Polynominal& a);
Polynominal& operator -= (Polynominal& a);
Polynominal& operator *= (Polynominal& a);
void PolyClear();
private:
Term* thelist;
};
#endif


#include <iostream>
#include "term.h"

using std::cin;
using std::cout;
using std::endl;

Term::Term(int c, int e)
{
link=0;
}

Term::Term(int c, int e, Term* nex):coef(c),exp(e)
{
link=nex;
}

Term* Term::InsertAfter(int c, int e)
{
link=new Term(c,e,link);
return link;
}


ostream &operator <<(ostream& out,const Term& val)
{
if(val.coef==0)
return out;
out<<val.coef;
switch(val.exp)
{
case 0:break;
case 1:out<<"x";break;
default:out<<"x^"<<val.exp;break;
}
return out;
}


#include "polynomial.h"
#include <iostream>

using std::cin;
using std::cout;
using std::endl;
using std::ends;

Polynominal& Polynominal::operator=(Polynominal& r)
{
this->PolyClear();
Term* q=thelist->link,* p;
for(p=r.thelist->link;p->exp>=0;p=p->link)
q=q->InsertAfter(p->coef,p->exp);
return *this;

}
Polynominal::Polynominal(Polynominal& r)
{
this->PolyClear();
Term* q=thelist->link,* p;
for(p=r.thelist->link;p->exp>=0;p=p->link)
q=q->InsertAfter(p->coef,p->exp);
}
Polynominal::Polynominal()
{
thelist=new Term(0,-1);
thelist->link=thelist;
}

Polynominal::~Polynominal()
{
Term* p=thelist->link;
while(p!=thelist)
{
thelist->link=p->link;
delete p;
p=thelist->link;
}
delete thelist;
}

void Polynominal::PolyClear()
{
Term* p=thelist->link;
while(p->exp>=0)
{
thelist->link=p->link;
delete p;
p=thelist->link;
}
}

void Polynominal::AddTerms(istream& in)
{
Term* q=thelist;
int c,e;
for(;;)
{
cout<<"Input a term(coef,exp):";
cin>>c>>e;
if( e < 0 )
break;
q=q->InsertAfter(c,e);
}
}

void Polynominal::Output(ostream& out)const
{
int first=1,second = 0;
Term* p=thelist->link;
for(;p!=thelist;p=p->link)
{
if(!first&&(p->coef>0))
out<<"+";
first=0;
cout<<*p;
second = 1;
}
if( !second )
out<<"0";
}

Polynominal& Polynominal::PolyAdd(Polynominal& r)
{
Polynominal *t = new Polynominal;
*t = *this;
Term *q,*q1=t->thelist,*p;
p=r.thelist->link;
q=q1->link;
while( p->exp >= 0 )
{
while(p->exp < q->exp)
{
q1=q;
q=q->link;
}
if(p->exp == q->exp)
{
q->coef=q->coef+p->coef;
if( q->coef == 0 )
{
q1->link=q->link;
delete (q);
q=q1->link;
}
else
{
q1 = q;
q = q->link;
}
}
else
{
q1=q1->InsertAfter(p->coef,p->exp);
}
p=p->link;
}
return *t;
}
Polynominal& Polynominal::PolySub(Polynominal& r)//this - r
{
Polynominal *t = new Polynominal;
*t = *this;
Term *q,*q1=t->thelist,*p;
p=r.thelist->link;
q=q1->link;
while( p->exp >= 0 )
{
while(p->exp < q->exp)
{
q1=q;
q=q->link;
}
if(p->exp == q->exp)
{
q->coef = q->coef - p->coef;
if( q->coef == 0 )
{
q1->link=q->link;
delete (q);
q=q1->link;
}
else
{
q1=q;
q=q->link;
}
}
else
{
q1=q1->InsertAfter(-p->coef,p->exp);
}
p=p->link;
}
return *t;
}
Polynominal& Polynominal::PolyMul(Polynominal& r)
{
Term *q,*p;
Polynominal *temp=new Polynominal,*t=new Polynominal;
Term *qq;
for(p=r.thelist->link;p->exp>=0;p=p->link)
{
for(q=thelist->link,qq=temp->thelist->link;q->exp>=0;q=q->link)
{
qq=qq->InsertAfter(q->coef*p->coef,p->exp+q->exp);
}
*t = t->PolyAdd(*temp);
temp->PolyClear();
}
delete temp;
return *t;
}

ostream& operator<<(ostream& out,const Polynominal& x)
{
x.Output(out);
return out;
}

istream& operator>>(istream& in, Polynominal & x)
{
x.AddTerms(in);
return in;
}

Polynominal& operator + (Polynominal& a, Polynominal& b)
{
Polynominal *t = new Polynominal;
*t = a.PolyAdd(b);
return *t;
}

Polynominal& operator - (Polynominal& a, Polynominal& b)
{
Polynominal *t = new Polynominal;
*t = a.PolySub(b);
return *t;
}
Polynominal& operator *(Polynominal& a, Polynominal& b)
{
/*Polynominal *t = new Polynominal;
*t = a.PolyMul(b);
return *t;*/
return a.PolyMul(b);
}

Polynominal& Polynominal::operator += (Polynominal& a)
{
*this = *this + a;
return *this;
}

Polynominal& Polynominal::operator -= (Polynominal& a)
{
*this = *this - a;
return *this;
}

Polynominal& Polynominal::operator *= (Polynominal& a)
{
*this = *this * a;
return *this;;
}


#include <iostream>
#include "polynomial.h"

using std::cin;
using std::cout;
using std::endl;

int main()
{
Polynominal p,q,r;
cout<<"input poly p: "<<endl;
cin>>p;
cout<<"input poly q: "<<endl;
cin>>q;
cout<<"测试结果如下:"<<endl;
cout<<"p+q="<<p+q<<endl;
cout<<"p*q="<<p*q<<endl;
cout<<"p-q="<<p-q<<endl;
p+=q;
cout<<"p+=q"<<p<<endl;
return 0;
}

//有三个.cpp两个 .h文件
  • 打赏
  • 举报
回复
还是用数组吧,链表效率太低

64,637

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧