know yourselves. information, computer, 7 wonders, various.

Monday, November 6, 2017

C++ programming language part- 76 Inserting and Traversing a Node


Inserting  and Traversing a Node

Program 50_2
            //linkedList node.demo
            class node
            {
            char name[10];
            public:
            node *next;
            void accept()
            {
            cout<
            cin>>name;
            }
            void display()
            {
            cout<
            }
            };


            class list
            {
            node *start;

            public:
            list()
            { start=NULL; }         // Constructor, so start will carry NULL
            void add_node()



            {
            node *fresh;
            fresh=new node;
            fresh->accept();
            fresh->next=start;
            start=fresh;
            }

            void traversal()
            {
            node *temp;
            for(temp=start;temp!=NULL;temp=temp->next)
       
            temp->display();
            }
            };

            main()
            {
            list L;
            L.add_node();
            L.add_node();
            L.add_node();
            L.add_node();
            L.traversal();
   

            }



C++ programming language part- 77 Deleting a Node


Deleting a  Node

This involves deletion of a node from the linked list. The following steps are followed to delete a node from the beginning of the list.
Step 1: Store the value of start into a temporary variable
Step 2: Reassign Start so that it points to the next node in the linked list
Step 3: Free the memory occupied by the temporary variable.

The Delete_node() function is defined as follows:
Void list::Delete_node()
{
node *Temp;
Temp=Start;
Start=Start->Next;
delete Temp;
}


Program 50_3
            //linkedList node.demo
            class node
            {
            char name[10];
            public:
            node *next;
            void accept()
            {
            cout<
            cin>>name;
            }
            void display()
            {
            cout<
            }
            };

            class list
            {
            node *start;

            public:
            list()
            { start=NULL; }         // Constructor, so start will carry NULL
            void add_node()
            {
            node *fresh;
            fresh=new node;
            fresh->accept();
            fresh->next=start;
            start=fresh;
            }

            void delete_node()
        {
            node *temp;
            temp=start;
            start=start->next;
            delete temp;
        }
            void traversal()
            {
            node *temp;
            for(temp=start;temp!=NULL;temp=temp->next)
       
            temp->display();
            }
            };

            main()
            {
            list L;
            L.add_node();
            L.add_node();
            L.add_node();
            L.add_node();
            L.traversal();
            L.delete_node();
            L.traversal();
            L.delete_node();
            L.traversal();

            }



C++ programming language part- 78 More about Linked List


More about Linked List

A Linked list with a function which is able to display a menu with the options add end delete record.

Program 50_4
//linkedList node.demo
            class node          // node is just a class name
            { public:
              char name[10];
              int age;
              node *next;

            void accept()
            { cout<>name;
              cout<>age;     }

            void display()
            { cout<
            };




            class list
            { node *start;

            public:
            list()
            { start=NULL; } // Constructor, so start will carry NULL
            void add_node()
            {node *fresh;
              fresh=new node;
              fresh->accept();
              fresh->next=start;
              start=fresh; }

            void delete_node()
            { node *temp;
               temp=start;
               start=start->next;
               delete temp;     }
            void traversal()
            {  node *temp;
                for(temp=start;temp!=NULL;temp=temp->next)     
                temp->display();    }  };

            main()
            { list L;
               char choice;
               do
            {
             L.add_node();
             cout<
             cin>>choice;
             }while (choice=='y' ||choice=='Y') ;
            L.traversal();
            int i=0,j=0;
            cout<
            cin>>i;
            cout<
            for(j=0;j
            L.delete_node();
            L.traversal();
            }


 


Ex: 4_1 arithmetic assign operator.

Programming Logic and Technique:
{ int p=10;
display " Type a number ";
accept p;
p+=5;
display "Aftter using arithmetic operator(+=)the value will be "<

 
Program Ex_4_1
//Ex_4
#include 
void main()
{
int p=10;
cout<<" Type a number "<
cin>>p;
p+=5;
cout<<"After using arithmetic operator(+=)the value will be "<
}


Ex: 9_1 Identify a number to define whether that is even or odd or zero.