1.  #ifndef _LINKEDSTRING_H 
  2. #define _LINKEDSTRING_H 
  3.  
  4. typedef struct snode 
  5.   char ch; 
  6.   struct snode *next; 
  7. }LiString; 
  8.  
  9. #endif  
  10.  #include <stdio.h> 
  11. #include "stdlib.h" 
  12. #include "LinkedString.h" 
  13.  
  14. void StrAssign(LiString *l, char ch[]) 
  15.   int loop1=0;    LiString *head = NULL, *rear = NULL; 
  16.   l = (LiString *)malloc(sizeof(LiString)); 
  17.   l->next = NULL;    head = l; 
  18.   while(ch[loop1] != '\0'
  19.   { 
  20.     rear = (LiString *)malloc(sizeof(LiString)); 
  21.     rear->ch = ch[loop1];    rear->next = NULL; 
  22.     head->next = rear;    head = rear; 
  23.     loop1++; 
  24.   } 
  25.  
  26. void StrCpy(LiString *str1, LiString *str2) 
  27.   LiString *tmp1 = NULL,*head1 = NULL, *tmp2 = NULL; 
  28.   tmp2 = str2->next; 
  29.   str1 = (LiString *)malloc(sizeof(LiString)); 
  30.   head1 = str1; 
  31.   while(tmp2 != NULL) 
  32.   { 
  33.     tmp1 = (LiString *)malloc(sizeof(LiString)); 
  34.     tmp1->ch = tmp2->ch; 
  35.     head1->next = tmp1; 
  36.     head1 = tmp1; 
  37.  
  38.     tmp2 = tmp2->next; 
  39.   } 
  40.  
  41. int StrLen(LiString *str) 
  42.   int len = 0; 
  43.   LiString *tmp = str->next; 
  44.   while(tmp != NULL) 
  45.   { 
  46.     len++; 
  47.     tmp = tmp->next; 
  48.   } 
  49.   return len; 
  50.  
  51. LiString *ConCat(LiString *str1, LiString *str2) 
  52.   LiString *total = NULL, *tmp1 = NULL, *rear = NULL, *tmp2 = str1->next; 
  53.   total = (LiString *)malloc(sizeof(LiString)); 
  54.   total->next = NULL;             rear = total; 
  55.  
  56.   while(tmp2 != NULL) 
  57.   { 
  58.     tmp1 = (LiString *)malloc(sizeof(LiString)); 
  59.     tmp1->ch = tmp2->ch; 
  60.     rear->next = tmp1; 
  61.     rear = tmp1; 
  62.     tmp2 = tmp2->next; 
  63.   } 
  64.   tmp2 = str2->next; 
  65.   while(tmp2 != NULL) 
  66.   { 
  67.     tmp1 = (LiString *)malloc(sizeof(LiString)); 
  68.     tmp1->ch = tmp2->ch; 
  69.     rear->next = tmp1; 
  70.     rear = tmp1; 
  71.     tmp2 = tmp2->next; 
  72.   } 
  73.   return total; 
  74.  
  75. LiString *SubStr(LiString *str, int begin, int num) 
  76. {  
  77.   int loop1 = 0; 
  78.   LiString *substr = NULL,*rear = NULL, *tmp1 = NULL, *tmp2 = NULL; 
  79.   substr = (LiString *)malloc(sizeof(LiString)); 
  80.   substr->next = NULL;         rear = substr; 
  81.   tmp2 = str->next; 
  82.   while(begin > 0 && tmp2 != NULL) 
  83.   { 
  84.     tmp2 = tmp2->next; 
  85.     begin--; 
  86.   } 
  87.   for(loop1=0; loop1<num && tmp2 != NULL; loop1++) 
  88.   { 
  89.     tmp1 = (LiString *)malloc(sizeof(LiString)); 
  90.     tmp1->ch = tmp2->ch; 
  91.     rear->next = tmp1; 
  92.     rear = tmp1; 
  93.     tmp2 = tmp2->next; 
  94.   } 
  95.   return substr; 
  96.  
  97. LiString *InsStr(LiString *str1,LiString *str2, int loc) 
  98.   int loop1=0; 
  99.   LiString *total = NULL, *tmp1 = NULL, *tmp2 = NULL; 
  100.   total = (LiString *)malloc(sizeof(LiString)); 
  101.   total->next = NULL; 
  102.   tmp1 = total; 
  103.  
  104.   str1 = str1->next; 
  105.   str2 = str2->next; 
  106.   for(loop1=0; loop1<loc; loop1++) 
  107.   { 
  108.     tmp2 = (LiString *)malloc(sizeof(LiString)); 
  109.     tmp2->ch = str1->ch; 
  110.     tmp1->next = tmp2; 
  111.     tmp1 = tmp2; 
  112.     str1 = str1->next ; 
  113.   } 
  114.   while(str2 != NULL) 
  115.   { 
  116.     tmp2 = (LiString *)malloc(sizeof(LiString)); 
  117.     tmp2->ch = str2->ch; 
  118.     tmp1->next = tmp2; 
  119.     tmp1 = tmp2; 
  120.     str2 = str2->next ; 
  121.   } 
  122.   while(str1 != NULL) 
  123.   { 
  124.     tmp2 = (LiString *)malloc(sizeof(LiString)); 
  125.     tmp2->ch = str1->ch; 
  126.     tmp1->next = tmp2; 
  127.     tmp1 = tmp2; 
  128.     str1 = str1->next ; 
  129.   } 
  130.   return total; 
  131.  
  132. LiString *DelStr(LiString *str,int begin, int num) 
  133.   int loop1 = 0; 
  134.   LiString *total = NULL, *tmp = NULL, *rear = NULL; 
  135.  
  136.   total =    (LiString *)malloc(sizeof(LiString)); 
  137.   total->next = NULL; 
  138.  
  139.   str = str->next ; 
  140.   while(loop1 < begin)   
  141.   {  tmp = (LiString *)malloc(sizeof(LiString)); 
  142.     tmp->ch = str->ch; 
  143.     rear->next = tmp; 
  144.     rear = tmp; 
  145.     str = str->next;     
  146.   } 
  147.   while(num > 0 && str != NULL) 
  148.   {  num--; 
  149.     str = str->next ; 
  150.   } 
  151.   while(str != NULL) 
  152.   { 
  153.     tmp = (LiString *)malloc(sizeof(LiString)); 
  154.     tmp->ch = str->ch; 
  155.     rear->next = tmp; 
  156.     rear = tmp; 
  157.     str = str->next;     
  158.   } 
  159.   return total;