正在加载图片...
第3章链表 q=q->ink =new ListNode<char>( p->data ) return *this: operator == stringl& ob)i ∥判两串相等 if( curLen I=ob curLen )return 0; ListNode <char> "p=chList, * q=ob.chList; for( int i=0; 1< curLen; 1++) if( p->data I=q->data)return 0; q=q->link; j return I char& stringl : operator [(int i)i 取串中字符 if (i>=0 &&i< curLen)t ListNode <char> *p=chList; int k=0; while( pl= NULL &&k<i)p=p->link; k++;) if( pI= nUlL )return p->data return yO stringl& stringl operator ()(int pos, int len)& /取子串 if pos >=0 & len >=0 & pos curLen & pos len-1< curLen)& ListNode<char> *a,"p=chList for( int k=0; k<pos: k++:)p=p->link ∥定位于第pos结点 q=temp.chList new ListNodechar>( p->data ) for ( int 1=1; i< len:; i++)i 取长度为len的子串 q=q->link = new ListNodeschar>(p->data ) q->link new ListNode<char>(\0); ∥建立串结束符 emp curLen =len emp curLen =0; temp. chList new ListNode<char> (0); return *tem if curLen +ob curLen maxLen )len= maxLen-curLen; else len ob curLen. ∥传送字符数 ListNode<char *q=ob. chList, *p=chList;第 3 章 链表 29 q = q->link = new ListNode<char> ( p->data ); } return *this; } int string1 :: operator == ( string1& ob ) { //判两串相等 if ( curLen != ob.curLen ) return 0; ListNode <char> *p = chList, *q = ob.chList; for ( int i = 0; i < curLen; i++ ) if ( p->data != q->data ) return 0; else { p = p->link; q = q->link; } return 1; } char& string1 :: operator [ ] ( int i ) { //取串中字符 if ( i >= 0 && i < curLen ) { ListNode <char> *p = chList; int k = 0; while ( p != NULL && k < i ) { p = p->link; k++; } if ( p != NULL ) return p->data; } return '\0'; } string1& string1 :: operator ( ) ( int pos, int len ) { //取子串 string1 temp; if ( pos >= 0 && len >= 0 && pos < curLen && pos + len - 1 < curLen ) { ListNode<char> *q, *p = chList; for ( int k = 0; k < pos; k++; ) p = p->link; //定位于第 pos 结点 q = temp.chList = new ListNode<char> ( p->data ); for ( int i = 1; i < len; i++ ) { //取长度为 len 的子串 p = p->link; q = q->link = new ListNode<char> ( p->data ); } q->link = new ListNode<char> ( '\0' ); //建立串结束符 temp.curLen = len; } else { temp.curLen = 0; temp.chList = new ListNode<char> ( '\0' ); } return *temp; } string1& string1 :: operator += ( string1& ob ) { //串连接 if ( curLen + ob.curLen > maxLen ) len = maxLen - curLen; else len = ob.curLen; //传送字符数 ListNode<char> *q = ob.chList, *p = chList;
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有