Recursively Pointing 2 Linked List

Hi everyone,
I really need help on how to solve the problem when we have a list of word(type-char[]) in linked list and then connect the word two by two to make it become one full sentences. And then when the system meet "." character, it will know that one is the next sentences. I had done a code like above, and it works to connect only two word for level 1 which it become one sentences. But I want to connect it another two for next level which could make it become full sentences at the end.

Illustration:

In book.txt:
"Software Six Sigma is an overall strategy to accelerate and to sustain continuous improvements in the software development process and in software product quality."

After delete redundant:
"Software" -> "Six" -> "Sigma" -> "is" -> "an" -> "overall" -> "strategy" -> "to" -> "accelerate" -> "and" -> "sustain" -> "continuous" -> "improvements" -> "in" -> "the" -> "software" -> "development" -> "process" -> "product" -> "quality."

Then pointing two by two words in level 1 into 1 new address:
"Software" -> "Software Six" <- "Six"
"Sigma" -> "Sigma is" <- "is"
and etc

Lastly, connect all to become word by using 2 by 2 address in next-next level:
Level 2:
"Software Six" -> "Software Six Sigma is" <-"Sigma is"
"an overall" -> "an overall strategy to" <- "strategy to"

Level 3:
"Software Six Sigma is" -> "Software Six Sigma is an overall strategy to" <- "an overall strategy to"

until finish....
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//Problem start here
void mergeNode2(ds *a, ds *b)
{
      if(ptrFirst == (struct ds*)NULL){
                  cout << "None" << endl;
                  return;
      }                 
      ptrThis = ptrFirst;
      do{
         ptrThis2 = ptrFirst;
         while (ptrThis2 != (struct ds*)NULL){
             if ((ptrThis->data!=NULL)&&(strcmp(a->data,ptrThis -> data)==0))
             {   cout << "OK1"<< endl;             
                 if ((ptrThis2->data!=NULL)&&(strcmp(b->data,ptrThis2 -> data)==0))
                 {
                      cout << "OK2"<< endl;                                   
                      ptrNew = (struct ds*) malloc(sizeof(struct ds));
                      if (ptrSecond == (struct ds*)NULL)
                         ptrSecond = ptrThis3 = ptrNew;
                      else{
                           ptrThis3 = ptrSecond;
                           while (ptrThis3 -> ptrNext != (struct ds*)NULL)
                                 ptrThis3 = ptrThis3 -> ptrNext;
                           ptrThis3 -> ptrNext = ptrNew;
                           ptrThis3 = ptrNew;
                      }
                      strcat(ptrThis3 -> data,ptrThis -> data);
                      strcat(ptrThis3 -> data,ptrThis2 -> data);
                      cout << "OK3"<< ptrThis3->data<< endl;
                      ptrThis3 -> ptrNext = (struct ds*)NULL; 
                 }                                    
                
             }
             
             ptrThis2 = ptrThis2 -> ptrNext;
         }
         ptrThis = ptrThis -> ptrNext;
      }while(ptrThis != (struct ds*)NULL);
}

//And here
void mergeNode(void)
{
     struct ds *ptrSearch1 = (struct ds*) malloc(sizeof(struct ds)); 
     struct ds *ptrSearch2 = (struct ds*) malloc(sizeof(struct ds));
     
     FILE *pFile;     
     pFile = fopen("results.txt","r+");
     rewind(pFile);
     
     while(!feof(pFile))
     {
      fscanf(pFile,"%s",ptrSearch1->data);
      fscanf(pFile,"%s",ptrSearch2->data);
      fflush(stdin);
      mergeNode2(ptrSearch1,ptrSearch2);
     } fclose(pFile);    
}

Please help me...
Last edited on
Could someone give me idea, please...
Topic archived. No new replies allowed.