Home > Back-end >  List of insert (s for the original series, pos for the position of the insertion, t to be inserted i
List of insert (s for the original series, pos for the position of the insertion, t to be inserted i

Time:09-24

Why does the for loop starting from 1, array in the table below is not starting from scratch? And when insert t series, temp + pos [I] why is the subscript I + pos, please can give an example

CodePudding user response:

That is about to see HeapString this structure is how to manage internal string, it should provide access to the internal string methods, may be it will skip zero position of the character, so you want to combine HeapString this structure provide access functions to see the insert function,

CodePudding user response:

reference 1st floor qybao response:
that is about to see HeapString this structure is how to manage internal string, it should provide access to the internal string methods, may be it will skip zero position of the character, so you want to combine HeapString this structure provide access functions to see the insert function,

Or its zero position of characters used for other purposes, such as whether the string memory was released (because it feels like it in the simulation of the heap memory string, it should provide a control is used to judge whether the heap, namely whether hasn't been released), so maybe character is the control of the position 0,

CodePudding user response:

This program is to use space for time method, is to define a chief is the source string length and to insert the string length, the first cycle is inserted into the location of the source string of characters in the new application before the space, then the string to be inserted into the new application space, finally the source string of characters from the pos in the future put them in new applications of string, release of the source string space, the space of the new application address assigned to ch,

CodePudding user response:

https://blog.csdn.net/weixin_30662109/article/details/96733617? Utm_medium=distribute. Pc_relevant_bbs_down. None - task - blog - baidujs - 1. Nonecase& Depth_1 - utm_source=distribute. Pc_relevant_bbs_down. None - task - blog - baidujs - 1. Nonecase
For your reference ~

CodePudding user response:

reference 3 building self-confidence boy reply:
this program is to use space for time method, is to define a chief is the source string length and to insert the string length, the first cycle is inserted into the location of the source string of characters in the new application before the space, then the string to be inserted into the new application space, finally the source string of characters from the pos in the future put them in new applications of string, release of the source string space, the space of the new application address assigned to ch,

Can give you a case, such as assignment s -> ch="12345"
Tc h="00", defines a structure body struct {char * ch, int len}

CodePudding user response:

reference fat beef ^ * ^ 5 floor response:
Quote: refer to the third floor confident boy reply:
this program is to use space for time method, is to define a chief is the source string length and to insert the string length, the first cycle is inserted into the location of the source string of characters in a new application before the space, then the string to be inserted into the new application space, finally the source string of characters from the pos in the future put them in new applications of string, release of the source string space, the space of the new application address assigned to ch,

Can give you a case, such as assignment s -> ch="12345"
Tc h="00", defines a structure body struct {char * ch, int len}

How do the inserted the 00 in the front of the three, I press circle a, if not

CodePudding user response:

reference fat beef ^ * ^ 6 floor response:
Quote: refer to the 5 floor fat beef ^ * ^ reply:
Quote: refer to the third floor confident boy reply:
this program is to use space for time method, is to define a chief is the source string length and to insert the string length, the first cycle is inserted into the location of the source string of characters in a new application before the space, then the string to be inserted into the new application space, finally the source string of characters from the pos in the future put them in new applications of string, release of the source string space, the space of the new application address assigned to ch,

Can give you a case, such as assignment s -> ch="12345"
Tc h="00", defines a structure body struct {char * ch, int len}

How do the inserted the 00 in the front of the three, I press circle a, as if no

Stick your code, and see if it is code problem ~

CodePudding user response:

# include
# include
# include
Typedef struct {
Char * ch;
int len;
} HeapString;
Int StrInsert (HeapString * s, int pos, HeapString t);
Int StrInsert (HeapString * s, int pos, HeapString t)
{
int i;
Char * temp;
If (pos<1 | | pos> S - & gt; Len + 1 | | s - & gt; Len==0)
return 0;
Temp=(char *) malloc (s - & gt; Len + t.l en);
If (temp==NULL)
return 0;
for(i=1; i\ [I]=s - & gt; Ch [I];
for(i=1; i\ [I + pos]=tc h [I];
For (I=pos. i\ [I + t.l en]=s - & gt; Ch [I];
S - & gt; Len +=t.l en;
Free (s - & gt; Ch);
S - & gt; Ch=temp;
return 1;
}
Int main ()
{
HeapString s;
HeapString t;
S.c h="12345";
Tc h="00";
S.l en=5;
T.l en=2;
If (StrInsert (& amp; S, 3, t))
Printf (" % s ", s.c h);
return 0;
}
  • Related