[ create a new paste ] login | about

Link: http://codepad.org/9cmp1BFk    [ raw code | fork ]

C, pasted on Mar 3:
#include <stdlib.h>
#include "node.h"

struct node {
    int value;
    Node next;
    Node previous; 
};

Node createNode(int value, Node next, Node previous){// Pass in a new value, a next Node, and a previous Node for the node we are creating
    Node newNode = malloc(sizeof *newNode); //We have to allocate for our new node. Eventually we free it
    newNode->value = value;
    newNode->next = next;
    newNode->previous = previous;
  
    return newNode;
}

int getValue(Node current){ //Returning and passing
    return current->value;
}

Node getNext(Node current){
    return current->next;
}
Node getPrevious(Node current){
    return current->previous;
}

void setValue(Node current, int value){ 
    current->value = value;
} 

void setNext(Node current, Node next){      //Sets the next nodee
    current->next = next;
}

void setNode(Node current, Node previous){ //Sets the previous node
    current->previous = previous; 
}
void freeNode(Node current){
    free(current);
}


Create a new paste based on this one


Comments: