Nested linklist

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
struct IPInfo
{
string IP;
string ipUser;

IPInfo *next;
};

struct AP
{
       IPInfo objIPInfo;
       int user;
       int distance;
       AP *next;
       
};

class IP {
	public:
		IP(void) { head = NULL; } // constructor
		~IP(void); // destructor
		AP* UserApproach(int,int);
		void DisplayIP(void);
		AP*InsertIP(string ipnum);
  	 private:
		AP* head;
};

IP::~IP(void) {
	AP* currNode = head, *nextNode = NULL;
	while (currNode != NULL) {
		nextNode = currNode->next;
		
		delete currNode;
		currNode = nextNode;
	}
}


AP* IP::UserApproach(int use,int dist) {
	int currIndex = 0;
	AP* currNode = head;
	AP* prevNode = NULL;
	while (currNode) {
		prevNode = currNode;
      currNode = currNode->next;
		currIndex++;
	}

   AP* newNode = new AP;
	newNode->user = use;
	newNode->distance = dist;
	if (currIndex == 0) {
		newNode->next = head;
		head = newNode;
  	 } else {
		newNode->next = prevNode->next;
		prevNode->next = newNode;
   	}
   	
 
 return newNode;
}

AP*IP::InsertIP(string ipnum)
{
AP ObjAP ;
ObjAP.objIPInfo.next;
ObjAP = head;
..........
}


This a code segment shows two associated structure which would use to implement linklist later on .The problem is i don't know how to write the code for access the IPinfo*next which would occupy by the InsertIP(string ipnum).The implementation i had wrote so far seems weird and confuse........Any solution?
Topic archived. No new replies allowed.