Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

data structure...

Status
Not open for further replies.

huskers

Programmer
Jan 29, 2002
75
0
0
US
I need help in finding an efficient way of storing the following data. I just want to store all the information in one data structure. The data that will be obtained contains the following info:

The data contains server names.
Each server name will have a socket that it needs to write to.
Each server name can have any number of clients. (2 or 4 or more depending on the data obtained from database)
Each client can have any number of sub clients.

so members are as follows:

serverName char[50];
socket int
client_name char[50];
sub_client char[50];

Thanks
 
It may be overcooking it but if you make your clients and sub clients linked lists then
Code:
stuct subclient
  {
  char *name;
  struct client * next;
  }

struct client 
  {
  char *name;
  struct subclient *first;
  struct client *next;
  }

struct server
  {
  char *name;
  int socket;
  struct client *first;
  }

but you're going to spend a lot of time using malloc!

Columb Healy
 
I am looking for an efficient way to search elements in the following data structure

struct x {
int item;
struct node *element;
}

struct node {
int a;
struct node *ptr;
}

There can be many possible elemets associated for each item and there can be many items. All of this are stored in database. I retrieve the data and create the above data structure.

According to the data sets I have I constructed a data structure for 5 items.
item1 -- 250,000 elements
item2 -- 75,000 elements
item3 -- 50,000
item4 -- 25,000

I have some elements in a file and I have to find out what items are associated to each element in the file. I am looking for an efficient way to traverse through this data structure to search for elements.

Presently my search is as follows: I traverse throught the linked list of elements for each item until I find the required one. Once I find it I break out of the loop and look in the next item.

Is this an efficient data structure? Is there a fastest way to search through this?
 
You might want to look at binary trees. This link is a good place to start. In breif you're sorting your data as you load it in so that searches on the data are as fast as posible.

Columb Healy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top