I'm learning to create adjacency lists and am very new to this. I'm trying to test one on my program. I wanted to create one vertex in the linked lists and then create a list or "edge" within that linked list. I create one linked here but not sure how to actually create one inside the linked list. I've created and tested my linked list class and I know it works, I just need to create a way to implement that into adjacency lists now. Also, I CAN'T use any list functions from the C++ library.
Am I heading in the right direction at all with my code?
#include "Vertex.h"
Vertex::Vertex(){
neighbors = new LinkedList();
discover = 0;
finish = 0;
pi = NULL;
color = "white";
}
Vertex::~Vertex(){
delete neighbors;
}
void Vertex::insert(Vertex* vertex){
LinkedList *temp = new LinkedList();
if(index == 0){
temp->insertElement(vertex);
index++;
if(index != 0){
neighbors->insertElement(vertex);
}
}
} Here's my main. Thanks in advance!
#include <cstdlib>
#include <iostream> //to use cin and cout
#include <string> //to use strings
#include "LinkedList.h"
using namespace std;
int main (){
Vertex *vertex1 = new Vertex();
for (int i =0; i < 10; i++){
vertex1->insert(vertex1);
}
Edit fixed a few things
news in your code. Where is your copy constructor etc?