Note that there are some explanatory texts on larger screens.

plurals
  1. POStoring Linked lists as a index in an Array C++
    primarykey
    data
    text
    <p>Overview: Im currently attempting to write a code that will take a AOV Network graph and put it into a Linked List. I am how ever having trouble whats the best way to go about this. I understand on paper how graphs can be represented in the linked list form.</p> <p>Here is the graph im going off of:</p> <p><img src="https://i.stack.imgur.com/VVse4.png" alt="enter image description here"></p> <p>My Thought process/Pusdo code would be as follows:</p> <blockquote> <p>Create a Linked-List class that just adds the nodes and prints them out for the methods. Then for each edge access the index of an array and go to that Linked list. So then my array would have [s,a,d,g,b,e,h,c,f,i,t] where each letter would represent the >Linked list of that vertex. So if i would like to call the S vertex i would have to call the >0 element of the array and that would point to s Linked-List. Is there a easy implementation >of this in C++?</p> </blockquote> <p>Here is my Linked-List Class right now:</p> <pre><code>class List{ private: typedef struct node{ char vertex; node* next; }* nodePtr; nodePtr head; nodePtr curr; nodePtr temp; public: List(); void AddNode(char AddData); void printList(); }; List::List(){ head = NULL; curr = NULL; temp = NULL; } void List::AddNode(char AddData){ nodePtr n = new node; n-&gt;next = NULL; n-&gt;vertex = AddData; if(head != NULL){ curr = head; while(curr-&gt;next != NULL){ curr = curr-&gt;next; } curr-&gt;next = n; } else{ head = n; } } void List::printList(){ curr = head; while(curr != NULL){ cout &lt;&lt; curr-&gt;vertex &lt;&lt; endl; curr = curr-&gt;next; } } </code></pre> <p>Any help would be much appreciated.</p> <p>EDIT: Can Using a Double Linked List like this work? <img src="https://i.stack.imgur.com/AKshm.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload