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();
}

Basic Practice Of Linked Lists

Wednesday, October 12, 2011

/*

welcome to tzt code

*/
#include<iostream>
#include<conio.h>
using namespace std;
class node
{
public:
int info;
node *next;
node()
{
info=0;
next=0;
}
};
void main()
{
cout<<"wellcome to TZT code"<<endl;
/*creating first node of linked list*/
node *list=new node;
list->info=5;
list->next=0;
/*creating second node and puting it after 1st node*/
node *neww=new node;
neww->info=8;
neww->next=0;
/*creating third node and puting it between first and second node*/
node *x=new node;
x->info=7;
x->next=neww;
list->next=x;
/*Now searchine all nodes showing data part of it*/
node *p;
int i=0;
p=list;
while(p!=0)
{
i++;
cout<<"data of node no "<<i<<" is "<<p->info<<endl;
p=p->next;
}
cout<<"Total nodes are:" <<i<<endl;
_getch();
}