Implementation of sequential strings

Source: Internet
Author: User

Implementation of sequential strings

The data structure of the sequence string is as follows:

typedef struct{ElemType data[MaxSize];int length;}SqString;

Implement the following functions:

Void StrAssign (SqString * & s, char str []); // assign a value to an ordered string to initialize void StrCopy (SqString * & s, SqString * t ); // string copy int StrEqual (SqString * s, SqString * t); // whether the two strings are equal int StrLength (SqString * s ); // The string is equal to void Concat (SqString * & s, SqString * t); // the string is connected to SqString SubStr (SqString * s, int I, int j ); // obtain the substring SqString InsStr (SqString s1, int I, SqString s2); // Insert the string SqString DelStr (SqString s, int I, int j ); // Delete the string SqString RepStr (SqString s, int I, int j, SqString t); // Replace the string void DispStr (SqString * s); // output the string

Specific implementation code:

# Include
 
  
# Include
  
   
# Include
   
    
# Define MaxSize 10000 # define ElemType char # define GET_ARRAY_LENGTH (array) (sizeof (array)/sizeof (array [0]) using namespace std; typedef struct {ElemType data [MaxSize]; int length;} SqString; void StrAssign (SqString * & s, char str []); // assign a value to an ordered string to initialize void StrCopy (SqString * & s, SqString * t); // copy the string to int StrEqual (SqString * s, SqString * t ); // whether the two strings are equal int StrLength (SqString * s); // whether the strings are equal void Concat (SqString * & s, Sq String * t); // String connection SqString SubStr (SqString * s, int I, int j); // obtain the substring SqString InsStr (SqString s1, int I, SqString s2 ); // Insert the string SqString DelStr (SqString s, int I, int j); // Delete the string SqString RepStr (SqString s, int I, int j, SqString t ); // Replace the string void DispStr (SqString * s); // output string void StrAssign (SqString & s, char str []) {int I = 0; while (str [I]! = '\ 0') {s. data [I] = str [I]; I ++;} s. length = I;} void StrCopy (SqString & s, SqString t) {int I = 0; while (t. data [I]! = '\ 0') {s. data [I] = t. data [I]; I ++;} s. length = t. length;} int StrEqual (SqString s, SqString t) {int flag = 0; if (s. length! = T. length) return flag; else {for (int I = 0; I
    
     
S. length | I + j> s. length + 1) return str; for (int k = 0; k
     
      
S1.length + 1) return str; for (int m = 0; m
      
        S. length | j <0 | I + j> s. length + 1) return str; for (int k = 0; k
       
         S. length + 1) return str; for (int k = 0; k
        
         

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.