Still the same result... Here's the updated code:
Code:
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
#define ValueType int
struct vertex {
int id;
struct vertex *prior;
struct vertex *next;
};
/*
void del(vertex vrtx_pntr){
vrtx_pntr->piror->next = vrtx_pntr->next;
vrtx_pntr->next->prior = vrtx_pntr->prior;
return;
}
*/
/*
* add_node()
* params
* vertex - use current to set prior
* int - data.
**/
vertex add_vrtx(vertex *vrtx_current, int data){
struct vertex *vrtx_new = (struct vertex *) malloc( sizeof( struct vertex) );
// Setup for new vertex
vrtx_new->next = 0;
vrtx_new->prior = vrtx_current;
vrtx_new->id = data;
// Attatch to old vertex
vrtx_current->next = vrtx_new;
return *vrtx_new;
}
int main() {
// set up a root.
struct vertex *root = (struct vertex *) malloc( sizeof( struct vertex) );
root->id = 0; // init all variables to zero.
root->next = 0;
root->prior = 0;
struct vertex *vrtx_pntr = root; // list pointer to first vertex.
for(int i = 1; i < 4; ++i){
*vrtx_pntr = add_vrtx(vrtx_pntr, i); // Link a new vertex to list.
}
vrtx_pntr = root; // reset pointer to root..
if( vrtx_pntr != 0){
cout << "Test: root exists.\n";
while( vrtx_pntr->next != 0 ){
cout << "Test: Nodes exists.\n";
cout << "Sweep: " << vrtx_pntr->id << "\n";
vrtx_pntr = vrtx_pntr->next;
}
}
return 0;
}
Feel free to point out my mistakes.