20120113

How to use Linked list in C++

//Program in cpp to demonstrate linkedlist, linkedlist.cpp
#include<iostream>
using namespace std;
struct node
        {
        public:
        int data;
        node * next;
        };
class linkedlist
        {
        private:
        node* first;
        public:
        linkedlist()
                {
                first=NULL;
                }
        void getdata(int d);
        void display();
        };
void linkedlist::getdata(int dd)
        {
        node* newnode=new node;
        newnode->data=dd;
        newnode->next=first;
        first=newnode;
        }
void linkedlist::display()
        {
        node* current=first;
        while(current!=NULL)
                {
                cout<<current->data<<endl;
                current=current->next;
                }
        }
int main()
{
linkedlist li;
li.getdata(10);
li.getdata(15);
li.getdata(20);
li.getdata(18);
li.getdata(19);
li.display();
return 0;
}
You may also Like:
C++ Program for Circular Queue implementation using linked list  
C++ program for Circular Queue implementation using Array
C++ program for reversing single Linked list nodes 
C++ Program for sorted single linked list with class
C++ Program for BST-Binary Search Tree  

Previous                             Home                               Next

3 comments:

  1. Program in cpp to demonstrate linkedlist, linkedlist.cpp

    Program in C++ to demonstrate linked list, linkedlist.cpp

    Program in cpp to demonstrate linkedlist, linkedlist.cpp

    Program in cpp to demonstrate linkedlist, linkedlist.cpp

    Program in C++ to demonstrate linked list, linkedlist.cpp

    Program in cpp to demonstrate linkedlist, linkedlist.cpp
    Program in cpp to demonstrate linkedlist, linkedlist.cpp

    Program in C++ to demonstrate linked list, linkedlist.cpp

    Program in cpp to demonstrate linkedlist, linkedlist.cpp
    Program in cpp to demonstrate linkedlist, linkedlist.cpp

    Program in C++ to demonstrate linked list, linkedlist.cpp

    Program in cpp to demonstrate linkedlist, linkedlist.cpp
    Program in cpp to demonstrate linkedlist, linkedlist.cpp

    Program in C++ to demonstrate linked list, linkedlist.cpp

    Program in cpp to demonstrate linkedlist, linkedlist.cpp
    Program in cpp to demonstrate linkedlist, linkedlist.cpp

    Program in C++ to demonstrate linked list, linkedlist.cpp

    Program in cpp to demonstrate linkedlist, linkedlist.cpp
    Program in cpp to demonstrate linkedlist, linkedlist.cpp

    Program in C++ to demonstrate linked list, linkedlist.cpp

    Program in cpp to demonstrate linkedlist, linkedlist.cpp
    Program in cpp to demonstrate linkedlist, linkedlist.cpp

    Program in C++ to demonstrate linked list, linkedlist.cpp

    Program in cpp to demonstrate linkedlist, linkedlist.cpp
    Program in cpp to demonstrate linkedlist, linkedlist.cpp

    Program in C++ to demonstrate linked list, linkedlist.cpp

    Program in cpp to demonstrate linkedlist, linkedlist.cpp
    Program in cpp to demonstrate linkedlist, linkedlist.cpp

    Program in C++ to demonstrate linked list, linkedlist.cpp

    Program in cpp to demonstrate linkedlist, linkedlist.cpp

    ReplyDelete
  2. Program in cpp to demonstrate linkedlist, linkedlist.cpp
    Program in cpp to demonstrate linkedlist, linkedlist.cpp

    Program in C++ to demonstrate linked list, linkedlist.cpp

    Program in cpp to demonstrate linkedlist, linkedlist.cpp

    ReplyDelete
  3. Other variations of Linked List programs:

    http://www.howtocpp.com/p/blog-page.html

    ReplyDelete