Linked list help

Hello all I am trying to read in data from a file and while the program is still reading the file I need to sort the data and print out what data I can. For example say the data I am reading in is show below. I need to read in the 4t,2y,3d, and 1r then print 1r,2y,3d,4t and remove them from the list. Then I can read in the 7h and 9e. I have a program that will read in and sort the data all at once, but I am lost on how to start the second part of the program. Any tips or help would be greatly appreciated!

4t
2y
3d
1r
7h
9e

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
59
60
61
62
63
64
65
66
67
68
69
70
71
#include<iostream>
#include <stdlib.h>
#include <list>
#include <string>
#include <fstream>
#include <algorithm>
using namespace std;


string message (string name)
{
 
  int i = 0;
  int tt = name.size() - 1;
   while(i<=3)
     {
       if(name[i] == ' ')
        {
          i++;
        }
   else break;
     }

  while(name[i] == '1'|| name[i] == '2'|| name[i] =='3' || name[i] =='4' || name[i] =='5' || name[i] =='6' || name[i] =='7' || name[i] =='8' || name[i] =='9' || name[i] == '0')
{
i++;
}
  if(name[i] == ' ')
       i++;

   int k = i;
   while(name[k] != '+'&& name[k] != '-' && name[k] != '=')
    {
     k++;
        if(k==tt)
         break;
    }
       k = k - i;
       return name.substr(i, k);
}




int main()
  {



    list<string> mylist;
    string aline;
    list<string>::iterator t;
    ifstream indata;
    indata.open("packet.data");

    int i;
       while(getline(indata,aline))
         {
           mylist.insert(lower_bound(mylist.begin(),mylist.end(),aline),aline);

         }

  for(t=mylist.begin(); t!=mylist.end(); t++)
    {
      string a = *t;
      string b = message(a);
      cout<< b;
   }
return 0;
}
Topic archived. No new replies allowed.