DEV Community

calteen
calteen

Posted on

linked list;

class Node {
    public:
    int data;
    Node* next;

    Node(int data){
        this ->data = data;
        this -> next = NULL;
    }
};

void InsertAtHead(Node* &head, int d){
    //new node create
    Node* temp = new Node (d);
    temp -> next = head;
    head = temp;
}
void InsertAtTail(Node* &tail, int d){
    Node*temp = new Node (d);
    tail ->next = temp;
    tail = temp;

}

void print(Node* &head){
    Node* temp = head;
    while(temp != NULL){
        cout <<temp ->data;
        temp = temp ->next;
        }
}


int main() {
    cout << "Hello world!";
    Node* node1 = new Node(10);
    cout<< node1 ->data << endl;
    cout << node1 -> next <<endl;
    return 0;
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)