GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 25-Jan-2009, 11:15
prem prem is offline
New Member
 
Join Date: Jan 2009
Posts: 5
prem has a little shameless behaviour in the past

Implementing adjacency link list


hi.. i tried impklementing adjacency link list
eg: 1,2,3,4 are nodes and its adjacent nodes are represented by
1->2->3
2->3
3->NULL
4->1
it means that there is an edge between 1 and 2 ...1 and 3 and so on...
so i implemented the below code.. si there anythng wrong in this part of my code
CPP / C++ / C Code:

 ListNode *newNode = NULL;  //This is the new vertex

   ListNode *nodePtr = NULL;   //Traversing pointer

   ListNode *downPtr = NULL;

for( i = 0; i<num_Nodes; i++)

    //ifor 
     {

         V_Name[i]=i+1;
          
 newNode = new ListNode;

         newNode->name = V_Name[i];



         newNode->next = NULL;

         newNode->down = NULL;

// Building the Vertex List

         if(!head)

            head = newNode;

         else

         {

            nodePtr = head;

            while(nodePtr->next)

            nodePtr = nodePtr->next;

            nodePtr->next = newNode;

           }

}//endifor
           


        for( j=0; j<num_Edges; j++)

      //jfor   
      {
               
        
           // cout << "What is the name of edge "<< j+1 << "?: ";
            scanf("%I64d" ,&v1[j]);
            scanf("%I64d" ,&v2[j]);
            scanf("%I64d" ,&alt);
            //elements[v1[j]+v2[j]+v1[j]*v2[j]]=alt;
            elements[v1[j]][v2[j]]=0;
            elements[v2[j]][v1[j]]=0;
            
            elements[v1[j]][v2[j]]=alt;
              elements[v2[j]][v1[j]]=alt;
           // cin>>v1[j]>>v2[j]>>E_Name[v1[j]+v2[j]+(v1[j]*v2[j])];
          //  cout<<"\n e_name"<<E_Name[5];

        
        
        ListNode *nodePtr = NULL;
        ListNode *downPtr = NULL;
            nodePtr = head;
           
           while(nodePtr)  //continue through all vertices

           {

         if(nodePtr->name==v1[j])
         break;
          else
          nodePtr=nodePtr->next;
          }
          /////////
          //nodePtr->next=NULL;
          ///////////////

            ListNode *downNode = NULL;

            down_head =nodePtr->down;

            downNode = new ListNode;

            downNode->name = v2[j];
           // downNode->w=elements[j];

            downNode->down = NULL;
		downNode->next = NULL; //!!!!!!!!!
//Building the Adjacent Vertex List

            if(!down_head)

            {

               nodePtr->down = downNode;

               down_head = downNode;

            }

            else

            {

               downPtr = down_head;


               while(downPtr->down)

                     downPtr = downPtr->down;


              downPtr->down = downNode;

            }
            //////////////
            //downPtr->down=NULL;
            //////////////////
                 ///////// for undirected
                 nodePtr=head;
                    
          while(nodePtr)  //continue through all vertices

    {

         if(nodePtr->name==v2[j])
         break;
          else
          nodePtr=nodePtr->next;
          }

            ListNode *downNode1 = NULL;

            down_head =nodePtr->down;

            downNode1 = new ListNode;

            downNode1->name = v1[j];

            downNode1->down = NULL;
		downNode1->next = NULL; //!!!!!!!!!

//Building the Adjacent Vertex List

            if(!down_head)

            {

               nodePtr->down = downNode1;

               down_head = downNode1;

            }

            else

            {

               downPtr = down_head;


               while(downPtr->down)

                     downPtr = downPtr->down;


              downPtr->down = downNode1;

            }
            
            

         }
...



this is just the graph construction part.... i would like to know if there is any mistake in this part
Last edited by LuciWiz : 25-Jan-2009 at 12:12. Reason: Please insert your C++ code between [cpp] & [/cpp] tags
 
 

Recent GIDBlogAccepted for Ph.D. program by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
I have a segmentation fault in my project takachi C++ Forum 6 09-Mar-2008 23:30
Find the Segmentation Fault jlwelch C Programming Language 3 10-Oct-2006 11:16
My Bane - The Segmentation Fault DCOM C Programming Language 6 08-Feb-2005 23:58
segmentation fault in c++ rushman8282 C++ Forum 2 26-Jan-2005 04:38
child pid xxx exit signal Segmentation fault (11) bezak Apache Web Server Forum 1 24-Nov-2003 10:18

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 09:05.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.