Welcome

Hi! This blog is for beginners of c++ and java .You can check and pick codes for your programming assignments. This will also help you to understand the concepts of these programming languages. Its all about programming.

Lab Assignment # 1 (Link List)

Friday, October 28, 2011

#include<iostream>
using namespace std;
#include<conio.h>
class link
{
public:
    int info;
    link *next;
    link()
    {
        info=0;
        next=0;
    }
};
class node
{
    private:
    link *list;
    public:
        node()
        {
            list=NULL;
        }
    void insert(int a)
        {
        link* temp=new link();
        temp->info=a;
        temp->next=NULL;
        if(list==NULL)
        {
            list=temp;
        }
        else
            {
            while(list->next!=NULL)
            list=list->next;
            list->next=temp;
            }
        }
    void insert_mid(int a,int b)
        {
            link *temp=new link();
            temp=list;
            for(;temp->info!=b;temp=temp->next);
            link *newtemp=new link();
            newtemp->info=a;
            newtemp->next=temp->next;
            temp->next=newtemp;
        }
    void del_mid(int a)
    {
        link* temp=new link();
        temp=list;
        if(list->info==a)
        {
            list=list->next;
        }
        else
        {
        while(list->next->info!=a)
        {
            list=list->next;
        }
        list->next=list->next->next;
        list=temp;
        }
    }
    void show_list()
        {
            while(list!=NULL)
            {
                cout<<list->info;
                list=list->next;
            }
        }

};
void main()
{
    node *ob=new node();
    ob->insert(5);
    ob->insert(7);
    ob->insert_mid(8,5);
    ob->del_mid(8);
    ob->show_list();
_getch();
}