Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   LinkList in C++ (http://www.go4expert.com/forums/linklist-in-cpp-t26579/)

solo_ 27Aug2011 18:45

LinkList in C++

I got an assigment from my teacher in C++ to create a program using a file called linked.h

The program is Win32 Console.

But how do i use the linked.h-file?


#ifndef LINKED
#define LINKED

#include <iostream>

using namespace std;

template<class T>
class Linked {

        struct Node{
            T item;
            Node* next;
        }; // struct Node

        Node* head;
        long length;


        // Postcondition: The Linked container has been initialized
        //                to an empty container.
            head = NULL;
            length = 0;
        } // default constructor

        // Postcondition: The number of items in the Linked container
        //                has been returned.
        long size() const{
            return length;
        } // size

        // Postcondition: A node with newItem has been inserted at the
        //                front of the Linked container.
        void push_front (const T& newItem){
            Node* newHead = new Node;
            newHead -> item = newItem;
            newHead -> next = head;
            head = newHead;
        } // push_front

}; // class Linked


poornaMoksha 9Sep2011 23:45

Re: LinkList in C++
Just wanted to know one thing :

You already know the concept of a linked list but still confused with the usage of this header file?
You don't even know the basics of linked list?

All times are GMT +5.5. The time now is 08:58.