Linked list needing assistance on understanding the code

Hi, I'm trying to understand what the pointers are doing in this linked list. Basically I don't understand the code itself, the concept I do but a thorough explanation would be much appreciated. I'm learning C++ and C and beginning the understanding of pointers and arrays, but still not grasping it fully. Thanks, in advance.

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
72
73
74
75
76
77
  double LinkedSeg::dist(LinkedSeg *inst,size_t &code)
 {
   LinkedSeg *prev=this;
   while(prev->m_prev)
     prev=prev->m_prev;

   Shapefile::ShapePoint *p1=&prev->m_data->m_point[0];
   Shapefile::ShapePoint *p2=&inst->m_data->m_point[0];
   double lat=0.5*(p1->m_y+p2->m_y);
   double cosA=cos(Deg2Rad*lat);
   double dist=sqrt(pow(cosA*(p1->m_x-p2->m_x),2)+pow(p1->m_y-p2->m_y,2));
   code=0;

   size_t m=inst->m_data->m_num_points-1;
   p2=&inst->m_data->m_point[m];
   lat=0.5*(p1->m_y+p2->m_y);
   cosA=cos(Deg2Rad*lat);
   double temp=sqrt(pow(cosA*(p1->m_x-p2->m_x),2)+pow(p1->m_y-p2->m_y,2));
   if(temp < dist){
     code=1;
     dist=temp;
   }

   LinkedSeg *next=this;
   while(next->m_next)
     next=next->m_next;

   m=next->m_data->m_num_points-1;
   p1=&next->m_data->m_point[m];
   lat=0.5*(p1->m_y+p2->m_y);
   cosA=cos(Deg2Rad*lat);
   temp=sqrt(pow(cosA*(p1->m_x-p2->m_x),2)+pow(p1->m_y-p2->m_y,2));
   if(temp < dist){
     code=2;
     dist=temp;
   }

   p2=&inst->m_data->m_point[0];
   lat=0.5*(p1->m_y+p2->m_y);
   cosA=cos(Deg2Rad*lat);
   temp=sqrt(pow(cosA*(p1->m_x-p2->m_x),2)+pow(p1->m_y-p2->m_y,2));
   if(temp < dist){
     code=3;
     dist=temp;
   }

   return dist;
 }
 //============================================================================
 bool LinkedSeg::connect(LinkedSeg *inst,size_t code)
 {
   LinkedSeg *ref=this;
   switch(code){
     case 0:
       inst->reverse();
     case 1:
       ref=this;
       while(ref->m_prev)
         ref=ref->m_prev;
       ref->m_prev=inst;
       inst->m_next=ref;
       break;

     case 2:
       inst->reverse();
     case 3:
       ref=this;
       while(ref->m_next)
         ref=ref->m_next;
       ref->m_next=inst;
       inst->m_prev=ref;
       break;
   }

   return true;
 }
 //========================================================== 
Topic archived. No new replies allowed.