1、串的索引存储串的索引存储一.串修改的原则: 1.字符的修改:刷新覆盖,索引区不发生改变。 2.字符的删除:删除字符后,其后面的字符发生移动,索引发生改变,即减一。 3.字符的插入:插入字符后,其后面的字符发生移动,索引发生改变,即加一。 4.字符串的等长修改:刷新覆盖,索引区不发生改变。 5.插入字符串长度比原串长:需要为多余的字符增添空间。 6.插入字符串长度比原串短: 7.删除一行:索引发生改变,数据区不发生改变。 8.插入一行:索引发生改变,数据区发生改变。二.一段有错误的参考程序:mian() / 字符串等长修改操作 Int a=5;/分别是字符的修改和删除操作 b=3; /字符串级插
2、入操作 /缺少c,d的定义,行插入 c=a+b; c=m+; /行级的删除操作 d=c+; /字符的插入操作 printf(%d%d%d,c,d); /字符串的删除main() int a=5; int b=3; int c,d; c=a+b; d=c+; printf(%d%d,c,d);三.三种表格: 表一:字符串内容表100200300400500600700800900mian()Int a = = 5;b =3;c = a + b;c = m + +;d = c + ;printf(“% d % d % d”,c ,d );表二:字符串在计算机中的存储样式00000001000200
3、03000400050006000700080009000A000B000C000Dmian()Inta000E000F0010001100120013001400150016001700180019001A001B=5;b=3;c=a+001C001D001E001F0020002100220023002400250026002700280029b;c=m+;d=c+002A002B002C002D002E002F00300031003200330034003500360037;printf(“%d%d00380039003A003B003C003D003E003F0040004100420
4、04300440045%d“,c,d);0046004700480049004A004B004C004D004E004F0050005100520053表三:串的索引存储示意图:串名串头位置串长10020030040050060070080090000000007000900130018001F0026002C004272105776222四.修改上面错误的程序 (一)字符级的修改 1.字符的插入操作 例如:在名为700的字符串中“d=c+;” 中插入“+”形成新的字符串“d = c + + ; ”。这时,表一:字符串内容表100200300400500600700800900mian()In
5、t a = = 5;b =3;c = a + b;c = m + +;d = c + + ;printf(“% d % d % d”,c ,d );表二:字符串在计算机中的存储样式(蓝色表示不能被访问的空间)0000000100020003000400050006000700080009000A000B000C000Dmian()Inta000E000F0010001100120013001400150016001700180019001A001B=5;b=3;c=a+001C001D001E001F0020002100220023002400250026002700280029b;c=m+;
6、d=c+002A002B002C002D002E002F00300031003200330034003500360037;printf(“%d%d00380039003A003B003C003D003E003F004000410042004300440045%d“,c,d);d=0046004700480049004A004B004C004D004E004F0050005100520053c+;表三:串的索引存储示意图:串名串头位置串长10020030040050060070080090000000007000900130018001F0026(0044)002C004272105776(7)
7、2222.字符的插入操作例如:在串名为300的字符串中“Int a=5; ”中删除“=”形成新的字符串“Int a=5; ”。此时:表一:字符串内容表100200300400500600700800900mian()Int a = 5;b =3;c = a + b;c = m + +;d = c + + ;printf(“% d % d % d”,c ,d );表二:字符串在计算机中的存储样式(蓝色表示不能被访问的空间)0000000100020003000400050006000700080009000A000B000C000Dmian()Inta000E000F00100011001200
8、13001400150016001700180019001A001B=5;b=3;c=a+001C001D001E001F0020002100220023002400250026002700280029b;c=m+;d=c+002A002B002C002D002E002F00300031003200330034003500360037;printf(“%d%d00380039003A003B003C003D003E003F004000410042004300440045%d“,c,d);d=0046004700480049004A004B004C004D004E004F005000510052
9、0053c+;表三:串的索引存储示意图:串名串头位置串长10020030040050060070080090000000007000900130018001F0026002C00427210(9)57762223.字符的修改:例如:在串名为300的字符串中“Int a = = 5; ”中删除“I”改成“i”形成新的字符串“int a=5; ”。此时:表一:字符串内容表100200300400500600700800900mian()int a = 5;b =3;c = a + b;c = m + +;d = c + + ;printf(“% d % d % d”,c ,d );表二:字符串在计
10、算机中的存储样式(蓝色表示不能被访问的空间)0000000100020003000400050006000700080009000A000B000C000Dmian() inta000E000F0010001100120013001400150016001700180019001A001B=5;b=3;c=a+001C001D001E001F0020002100220023002400250026002700280029b;c=m+;d=c+002A002B002C002D002E002F00300031003200330034003500360037;printf(“%d%d00380039
11、003A003B003C003D003E003F004000410042004300440045%d“,c,d);d=0046004700480049004A004B004C004D004E004F0050005100520053c+;表三:串的索引存储示意图:串名串头位置串长10020030040050060070080090000000007000900130018001F0026002C00427295776222(二)字符串级的修改 1.字符串的插入操作例如:在串名为400的字符串中“b = 3 ; ”中插入“int”形成新的字符串“intb = 3 ; ”。此时:表一:字符串内容表1
12、00200300400500600700800900mian()int a = 5;int b =3;c = a + b;c = m + +;d = c + + ;printf(“% d % d % d”,c ,d );表二:字符串在计算机中的存储样式(蓝色表示不能被访问的空间)0000000100020003000400050006000700080009000A000B000C000Dmian() inta000E000F0010001100120013001400150016001700180019001A001B=5;b=3;c=a+001C001D001E001F0020002100
13、220023002400250026002700280029b;c=m+;d=c+002A002B002C002D002E002F00300031003200330034003500360037;printf(“%d%d00380039003A003B003C003D003E003F004000410042004300440045%d“,c,d);d=0046004700480049004A004B004C004D004E004F0050005100520053c+;intb=3;表三:串的索引存储示意图串名串头位置串长1002003004005006007008009000000000700
14、090013(004B)0018001F0026002C00427295(9)7762222.字符串的删除操作例如:在串名为为800的串“printf(“%d%d%d”,c,d); ”中删除“%d”形成新的串“printf(%d%d”,c,d); ”。 此时:表一:字符串内容表100200300400500600700800900mian()int a = 5;int b =3;c = a + b;c = m + +;d = c + + ;printf(“% d % d ”,c ,d );表二:字符串在计算机中的存储样式(蓝色表示不能被访问的空间)00000001000200030004000
15、50006000700080009000A000B000C000Dmian() inta000E000F0010001100120013001400150016001700180019001A001B=5;b=3;c=a+001C001D001E001F0020002100220023002400250026002700280029b;c=m+;d=c+002A002B002C002D002E002F00300031003200330034003500360037;printf(“%d%d00380039003A003B003C003D003E003F004000410042004300440
16、045“,c,d);d=0046004700480049004A004B004C004D004E004F0050005100520053c+;intb=3;表三:串的索引存储示意图串名串头位置串长100200300400500600700800900000000070009004B0018001F0026002C0042729977622(20)23.字符串的修改操作例如:在串名为100的字符串中“mian()”中的“ia”改成“ai”形成新的字符串“main()”。此时:表一:字符串内容表100200300400500600700800900main()int a = 5;int b =3;
17、c = a + b;c = m + +;d = c + + ;printf(“% d % d ”,c ,d );表二:字符串在计算机中的存储样式(蓝色表示不能被访问的空间)0000000100020003000400050006000700080009000A000B000C000Dmain() inta000E000F0010001100120013001400150016001700180019001A001B=5;b=3;c=a+001C001D001E001F0020002100220023002400250026002700280029b;c=m+;d=c+002A002B002C0
18、02D002E002F00300031003200330034003500360037;printf(“%d%d00380039003A003B003C003D003E003F004000410042004300440045“,c,d);d=0046004700480049004A004B004C004D004E004F0050005100520053c+;intb=3;表三:串的索引存储示意图串名串头位置串长100200300400500600700800900000000070009004B0018001F0026002C00427299776202(三)行级的操作1.插入行操作例如:在串
19、名为400的行后面插入新的字符串“int c, d ; ”,此时命名为450,则有:表一:字符串内容表100200300400450500600700800900main()int a = 5;int b =3;int c , d;c = a + b;c = m + +;d = c + + ;printf(“% d % d ”,c ,d );表二:字符串在计算机中的存储样式(蓝色表示不能被访问的空间)0000000100020003000400050006000700080009000A000B000C000Dmain() inta000E000F0010001100120013001400150016001700180019001A001B=5;b=3;c=a+001C001D001E001F0020002100220023002400250026002700280029b;c=m+;d=c+002A002B002C002D002E002F00300031003200330034003500360037;printf(“%d%d00380039003A003B003C003D003E003F004000410042004300440045“,c,d);d=0046004700480049004A004B004C004D004E004F0050005100
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1