1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

LinkList in C++

Discussion in 'C++' started by solo_, Aug 27, 2011.

  1. solo_

    solo_ New Member

    Joined:
    Aug 27, 2011
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Norway
    Home Page:
    Hi,

    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?

    linked.h
    Code:
    #ifndef LINKED
    #define LINKED
    
    #include <iostream>
    
    using namespace std;
    
    template<class T>
    class Linked {
    
        protected:
            struct Node{
                T item;
                Node* next;
            }; // struct Node
    
            Node* head;
            long length;
    
        public:
    
            // Postcondition: The Linked container has been initialized
            //                to an empty container.
            Linked(){
                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;
                length++;
            } // push_front
    
    
    
    }; // class Linked
    
    
    #endif
    
     
  2. poornaMoksha

    poornaMoksha New Member

    Joined:
    Jan 29, 2011
    Messages:
    150
    Likes Received:
    33
    Trophy Points:
    0
    Occupation:
    Software developer
    Location:
    India
    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?
    OR
    You don't even know the basics of linked list?
     

Share This Page