Showing posts with label single linked list. Show all posts
Showing posts with label single linked list. Show all posts

20130330

How to write cpp program to reverse a linked list



//C++ program for reversing single Linked list nodes 
Cpp program for implement reversing Single Linked List
Single linked list program for reversing the nodes
How to reverse linked list 
#include<iostream>
using namespace std;

struct node
{
node *next;
int data;
};
class ll
{
private:
node *start;
public:
ll(){start=NULL;}

void insert(int a)
{
cout<<"Inside Insert."<<endl;
node *newnode=new node;
newnode->data=a;
newnode->next=start;
start=newnode;
//return;
}
void display();
void del();
void reverse();
};

How to write sorted linked list program in cpp with class


How to write sorted linked list program in cpp with class
C++ Program for sorted single linked list with class
//sorted linked list latest
#include<iostream>
using namespace std;
struct node
{
int data;
node *next;
};
node *start=NULL;

void insert(int d)
{
node *newnode=new node;
newnode->data=d;
newnode->next=NULL;
//insert as first elt
if(start==NULL)
{

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