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

Monday, November 6, 2017

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.