#include<iostream>
#include<time.h>
#include<conio.h>
using namespace std;
class adclist
{
struct list
{
int data;
list* next;
};
public:
void makelist();
};
void adclist::makelist()
{
list** table = new list* [10];
for(int j =0; j < 10 ; j++)
table[j] = NULL;
for ( int m =0; m < 10; m++)
{
int x;
cout<<"enter your value"<<endl;
cin>>x;
list* newptr = new list;
newptr->data = x;
newptr->next = NULL;
int y = rand() %9 ;
//.................................................
// WHATS THE MISTAKE IN THIS SEGMENT..........???????????
list* head = new list;
head = table[y] ;
if (head == NULL)
{
head->data = x;
head->next = NULL;
table[y] = head;
}
//.................................
else
{
list* temp = table[y];
while( temp->next!= NULL)
{
temp = temp->next;
}
temp->next = newptr;
}
}
int exit;
cout<<"IF NO MORE DATA ...PLEASE PRESS 1 FOR DISPLAYING UR ADJACENCY LSIT"<<endl;
cin>>exit;
list* temptr;
if ( exit == 1)
{
for ( int m =0; m < 10; m++)
{
temptr = table[m];
while( temptr!= NULL)
{
cout<<m<<" -> "<<temptr->data;
temptr = temptr->next;
}
if ( temptr == NULL)
cout<<endl<<endl;
}
}
}
int main()
{
adclist l1;
l1.makelist();
getch();
return 0;
}
sairakhalid 0 Newbie Poster
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.