Firstly ,i'm not asking about the code,i need suggestion and idea how to do it.I don't even know what should be the first thing in the main menu,because i think it is not some sort of input and output program.I thought i might relate to something like queue or stack .Please help!

Consider the following scenario:
Access points are installed on airport hallway to enable users to communicate over the internet. Assuming passengers are holding a PDA. To enable them to stay connected to the internet, the AP will assign dynamic IP to each passenger. Each AP maintains a table of IPs (maximum 3 each). As passenger moves away from an AP the IP will be released, while another passenger moving closer to an AP will be assigned an available IP. Packet sent by a passenger nearest to an AP will arrive earlier than packet sent by farther away passenger. Later packet received may not be assigned with IP if all IPs are allocated.

i think you just want help to generate dynamic and unique IP only??
and that will be from some specific range of IP only??

i think you just want help to generate dynamic and unique IP only??
and that will be from some specific range of IP only??

ACTUALLY ,it is not some complicated program to generate what so call unique IP ,specific address....The IP assume to be preset as three different IP .There would be allocated depends on the condition as i mentioned above.The most important thing is that i cannot figured out the process of the program like the main menu,flow chart ,pseudocode....

I think you can maintan this by creating nested link list ..
In link list first main whatever number of AP available on airport and then after in another nested link list you should maintain table of ip addresses as you say maximum 3 can be there in a table.

than for checking whether that ip is free or allocated you can set flags in that corrosponding link list.

and as u said about to passing of packets based on passenger distance from AP, for that you can take one more parameter in link list that will keep track of distance of passenger assined to that IP, and based on that parameter you can decide which packet will be pass first....

I think you can maintan this by creating nested link list ..
In link list first main whatever number of AP available on airport and then after in another nested link list you should maintain table of ip addresses as you say maximum 3 can be there in a table.

than for checking whether that ip is free or allocated you can set flags in that corrosponding link list.

and as u said about to passing of packets based on passenger distance from AP, for that you can take one more parameter in link list that will keep track of distance of passenger assined to that IP, and based on that parameter you can decide which packet will be pass first....

I know about the technique of linklist,but the nested linklist seems a bit complicated .Any reference or sample about creating the nested linklist?Is it similar like doubly linklist?

Doubley link list and Nested link list is different things ...
But in your case Doubly link list can also be used ...

you can implement same logic using doubly link list ...

I think you can maintan this by creating nested link list ..
In link list first main whatever number of AP available on airport and then after in another nested link list you should maintain table of ip addresses as you say maximum 3 can be there in a table.

than for checking whether that ip is free or allocated you can set flags in that corrosponding link list.

and as u said about to passing of packets based on passenger distance from AP, for that you can take one more parameter in link list that will keep track of distance of passenger assined to that IP, and based on that parameter you can decide which packet will be pass first....

#include <iostream>
#include <conio.h>

using namespace std;

struct AP
{
       string IP;
       int user;
       int distance;
       AP *next;
};

class IP {
	public:
		IP(void) { head = NULL; } // constructor
		~IP(void); // destructor
		bool IsEmpty() { return head == NULL; }
        int UserLeave(int x);
		AP* UserApproach(int,int);
		void DisplayIP(void);
		
        
  	 private:
		AP* head;
};

IP::~IP(void) {
	AP* currNode = head, *nextNode = NULL;
	while (currNode != NULL) {
		nextNode = currNode->next;
		// destroy the current node
		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;
}

void IP::DisplayIP()
{
	int num = 0;
	AP* currNode = head;
	while(currNode!=NULL)
	{
		cout << "User "<<currNode->user <<endl;
		cout << "Distance from AP "<<": "<<currNode->distance <<"m"<<endl;
		currNode = currNode->next;
		num++;
}   
}

int main()
{
 IP allo;
 allo.UserApproach(1,14);
 allo.UserApproach(2,4);
 allo.UserApproach(3,20);
 allo.UserApproach(4,9);
 
 allo.DisplayIP();
 
 cout <<"\n\nSelect one of the following scenario : "<<endl;
 cout <<"1.User approach access point."<<endl;
 cout <<"2.User leave access point.";
 
   
    
getch();
return 0;

}

This is what i've done so far ,but could give me the clear shot about how to implement the nested linklist as u had mentioned "In link list first main whatever number of AP available on airport and then after in another nested link list you should maintain table of ip addresses as you say maximum 3 can be there in a table."
Thanks for ur help.

See in your code you have created one structure ...

struct AP
{
     string IP;
     int user;
     int distance;
     AP *next;
};

Here, u can not assign more than one ip.... coz next object of this struct AP will be treated as another AP.But you want to allow maximum 3 IP on single AP.So there can be one or two or three IP.okay.

what i was saying is like this ...

just simplifying your struct only ...

struct IPInfo
{
      string IP;
      string UserName;
      int distance;
      IPInfo *next;
};

struct AP
{
        IPInfo objIPInfo;
        AP *next;
} ;

Here, one link list for AP will be created and for each node of that AP link list one another link list also created of IPInfo ...

so in IPInfo link list you can create as many node as you want or you can restrict to 3 as you want only 3 ip n wach AP.

so here for every node of AP one indivual link list of IPInfo will be created...

See in your code you have created one structure ...

struct AP
{
     string IP;
     int user;
     int distance;
     AP *next;
};

Here, u can not assign more than one ip.... coz next object of this struct AP will be treated as another AP.But you want to allow maximum 3 IP on single AP.So there can be one or two or three IP.okay.

what i was saying is like this ...

just simplifying your struct only ...

struct IPInfo
{
      string IP;
      string UserName;
      int distance;
      IPInfo *next;
};

struct AP
{
        IPInfo objIPInfo;
        AP *next;
} ;

Here, one link list for AP will be created and for each node of that AP link list one another link list also created of IPInfo ...

so in IPInfo link list you can create as many node as you want or you can restrict to 3 as you want only 3 ip n wach AP.

so here for every node of AP one indivual link list of IPInfo will be created...

hey ,,,,
and by the way i forgot to tell you abt class..
sorry for that ...

that same thing you can do using class and it will be more easier ...

like ,,

class IPInfo
{
         string IP;
         string name;
         int distance;
}

class AP
{
         IPInfo obj[3];
}

int main()
{

         AP ap["no of AP"];
         return 0;
}

hey ,,,,
and by the way i forgot to tell you abt class..
sorry for that ...

that same thing you can do using class and it will be more easier ...

like ,,

class IPInfo
{
         string IP;
         string name;
         int distance;
}

class AP
{
         IPInfo obj[3];
}

int main()
{

         AP ap["no of AP"];
         return 0;
}

See in your code you have created one structure ...


struct AP
{
string IP;
int user;
int distance;
AP *next;
};


Here, u can not assign more than one ip.... coz next object of this struct AP will be treated as another AP.But you want to allow maximum 3 IP on single AP.So there can be one or two or three IP.okay.

what i was saying is like this ...

just simplifying your struct only ...

struct IPInfo
{
string IP;
string UserName;
int distance;
IPInfo *next;
};

struct AP
{
IPInfo objIPInfo;
AP *next;
} ;


Here, one link list for AP will be created and for each node of that AP link list one another link list also created of IPInfo ...

so in IPInfo link list you can create as many node as you want or you can restrict to 3 as you want only 3 ip n wach AP.


so here for every node of AP one indivual link list of IPInfo will be created...

i had modified a bit the codes just now :

#include <iostream>
#include <conio.h>

using namespace std;

struct AP
{
       string ip;
       int user;
       int distance;
       AP *next;
};

class IP {
	public:
		IP(void) { head = NULL; } // constructor
		~IP(void); // destructor
		bool IsEmpty() { return head == NULL; }
        int UserLeave(int x);
		AP* UserApproach(int,int);
		void DisplayIP(void);
		AP* bubbleSort();
  	 private:
		AP* head;
};

IP::~IP(void) {
	AP* currNode = head, *nextNode = NULL;
	while (currNode != NULL) {
		nextNode = currNode->next;
		// destroy the current node
		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;
}

void IP::DisplayIP()
{
	int num = 0;
	AP* currNode = head;    
    while(currNode!=NULL)
	{
		cout << "User "<<currNode->user <<endl;
		cout << "Distance from AP "<<": "<<currNode->distance <<"m"<<endl;
		currNode = currNode->next;
		num++;
}   
}

AP*IP::bubbleSort() {
                    
AP*currNode = head;
AP*secNode = head;
int tempdistance;
int tempuser;
while(currNode!=NULL)
{
secNode = currNode;

while(secNode!=NULL)
{

if(currNode->distance > secNode->distance)
{
 tempdistance = currNode->distance;
 tempuser = currNode->user;
 currNode->distance = secNode->distance;
 currNode->user = secNode->user;
 secNode->distance = tempdistance;
 secNode->user = tempuser;
}
secNode = secNode->next;
}
currNode = currNode->next;
}

}

int main()
{
 int select;
 
 IP allo;
 
 allo.UserApproach(1,14);
 allo.UserApproach(2,4);
 allo.UserApproach(3,20);
 allo.UserApproach(4,9);
 
  
 allo.DisplayIP();          

cout <<"\nAfter sorted"<<endl;
 allo.bubbleSort();
 allo.DisplayIP();

 

 cout <<"\n\nSelect one of the following scenario : "<<endl;
 cout <<"1.User approach access point."<<endl;
 cout <<"2.User leave access point."<<endl;
 cout <<"3.Allocate available IP."<<endl;
 cin >> select;
 
 if(select == 3)
 {
           
}    
getch();
return 0;

}

i think your concept was more closed to the objective of the question since you occupy two associtiate struct IPinfo and AP together.But i have no idea how to implement it in my codes.
struct IPInfo
{
string IP;
string UserName;
int distance;
IPInfo *next;
};

struct AP
{
IPInfo objIPInfo;
AP *next;
} ;

What i was thought is about Bubblesort the distance of 4 person which had been initialise in ascending order and allocate the ip for top 3 person which is nearest to the AP.Could you give me more about that?

ANYONE PLEASE HELP!Refer to the solution of crazyboy,i'm desperate to doing this alone.....


struct IPInfo
{
string IP;
string UserName;
int distance;
IPInfo *next;
};

struct AP
{
IPInfo objIPInfo;
AP *next;
} ;

how could i control the IPInfo *next of struct IP ?I mean to move to next node of IPInfo ?

perheps this will help you ...

AP ObjAP;
ObjAP.ObjIPInfo -> next;

try this .....
may be it will work ... i have not triedd

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.