//链表反转
struct linka{
int data;
linka* next;
};
#define NULL 0
void reverse(linka*& head)
{
linka* cur=NULL;
linka* next=NULL;
linka* pre=NULL;
cur=head;
while (cur->next!=NULL)
{
next=cur->next;
cur->next=pre;
pre=cur;
cur=next;
next=cur->next;
}
cur->next=pre;
head=cur;
}
//string的构造函数
string::string(const char* str)
{
if (str==NULL)
{
m_data=new char[1];
m_data='/0';
}
else
{
m_data=new char(strlen(str)+1);
strcpy(m_data,str);
}
}
//string的拷贝函数
string::string(const string& other)
{
m_data=new char[strlen(other.m_data)+1];
strcpy(m_data,other.m_data);
}
string& string::operator =(const sting& other)
{
if(this==&other) return *this;
delete[] m_data;
m_data=new char[strlen(other.m_data)+1];
strcpy(m_data,other.m_data);
}
bool strcpy(char* strdst,const char* strsrc)
{
if (strsrc==NULL||strdst==NULL)
{
return false;
}
if (strdst==strdst)
{
return true;
}
while(*strsrc!='\0')
{
*strdst++=*strsrc++;
}
return true;
}
笔试题
最新推荐文章于 2024-06-09 08:15:00 发布