Note 1

Take Note:

Take a note while surfing.





Note With Ink

Give your Note a Colorful Tag.




Easy to Access

Stay on same information and in Sync wherever you are.

Note 2

Take Note:

Organize your information,It may take Shape.





Think With Ink

Differ your Content by Color.




Easy to Access

Easy to pull up your content from anywhere anytime.

Note 3

Take Note:

Don't Let information to miss,Because it take shape





Note With Ink

Simple an Easy Way to take a note.




Easy to Access

Get the same in next visit.

Programs Questions and Answers



  • 1. Write a program insert an element into ascending order list

    Input : ,   Output :

    View Answer View Answer | Program Topics Linked List | Write Your Program Discuss in Forum | Add to Reading List To Reading List | Tag to companies Asked In | Level Fresher
  • Answer In: C   C++  
     
    #include <stdio.h>
    
     #include<iostream>
    using namespace std; 
    void main()
    {
        int i, j, a, n, number[30]; 
        cout<<"Enter the value of N \n";
        cin>>n;
        cout<<"Enter the numbers \n";
        for (i = 0; i < n; ++i)
            cin>>number[i];
        for (i = 0; i < n; ++i)
        {
            for (j = i + 1; j < n; ++j)
            {
                if (number[i] > number[j])
                {
                    a =  number[i];
                    number[i] = number[j];
                    number[j] = a;
                }
            }
        }
         cout<<"The numbers arranged in ascending order are given below \n";
        for (i = 0; i < n; ++i)
             cout<< number[i];
    }
    Tags:

    Virtusa 

  • 2. Write a program to reverse the single linked list

    Input : ,   Output :

    View Answer View Answer | Program Topics Linked List | Write Your Program Discuss in Forum | Add to Reading List To Reading List | Tag to companies Asked In | Level Fresher
  • Answer In: C   C++  
     
    #include <iostream>
    #include <cstddef>
    /* definition of the list node class */
    class Node
    {
        friend class LinkedList;
    private:
        int _value; /* data, can be any data type, but use integer for easiness */
        Node *_pNext; /* pointer to the next node */    
    public:
        /* Constructors with No Arguments */
        Node(void)
        : _pNext(NULL)
        { }    
        /* Constructors with a given value */
        Node(int val)
        : _value(val), _pNext(NULL)
        { }    
        /* Constructors with a given value and a link of the next node */
        Node(int val, Node* next)
        : _value(val), _pNext(next)
        {}    
        /* Getters */
        int getValue(void)
        { return _value; }    
        Node* getNext(void)
        { return _pNext; }
        };
    /* definition of the linked list class */
    class LinkedList
    {
    private:
        /* pointer of head node */
        Node *_pHead;
        /* pointer of tail node */
        Node *_pTail;
        
    public:
        /* Constructors with a given value of a list node */
        LinkedList(int val);
        /* Destructor */
        ~LinkedList(void);
        
        /* Function to a};

    /* definition of the linked list class */
    class LinkedList
    {
    private:
        /* pointer of head node */
        Node *_pHead;
        /* pointer of tail node */
        Node *_pTail;
        
    public:ppend a node to the end of a linked list */
        void tailAppend(int val);
        /* Function to reverse the list */
        void reverse();
        
        /* Traversing the list and printing the value of each node */
        void traverse_and_print();
    };

    LinkedList::LinkedList(int val)
    {
        /* Create a new node, acting as both the head and tail node */
        _pHead = new Node(val);
        _pTail = _pHead;
    }

    LinkedList::~LinkedList()
    {
        /*
         * Leave it empty temporarily.
         * It will be described in detail in the example "How to delete a linkedlist".
         */
    }

    void LinkedList::tailAppend(int val)
    {
        /* The list is empty? */
        if (_pHead == NULL) {
            /* the same to create a new list with a given value */
            _pTail = _pHead = new Node(val);
        }
        else
         {
            /* Append the new node to the tail */
            _pTail->_pNext = new Node(val);
            /* Update the tail pointer */
            _pTail = _pTail->_pNext;
        }
    }

    void LinkedList::reverse()
    {
        Node *pTempHead = _pHead, *pRestNodes = NULL, *pNextNode = NULL;
        /* The list is empty? do nothing */
        if (_pHead == NULL)
            return;
        /* The previous head node will act as the tail node after reversing */
        _pTail = _pHead;
        /* Take out the head node and make the reverse list basing on it */
        pRestNodes = _pHead->_pNext;
        
        while (pRestNodes != NULL) {
            /* Step1: Take out the next node */
            pNextNode = pRestNodes;
            /* Step2: Update the pointer of rest nodes after taking out the first */
            pRestNodes = pRestNodes->_pNext;
            /* Step3: Add the taken out node to the new list */
            pNextNode->_pNext = pTempHead;
            /* Step4: Update the new temp head node */
            pTempHead = pNextNode;
            /* Repeat Step 1-4 */
        }
        _pHead = pTempHead;
        _pTail->_pNext = NULL;
    }

    void LinkedList::traverse_and_print()
    {
        Node *p = _pHead;    
        /* The list is empty? */
        if (_pHead == NULL) {
            cout << "The list is empty" << endl;
            return;
        }    
        cout << "LinkedList: ";
        /* A basic way of traversing a linked list */
        while (p != NULL) { /* while there are some more nodes left */
            /* output the value */
            cout << p->_value << " ";
            /* The pointer moves along to the next one */
            p = p->_pNext;
        }
        cout << endl;
    }
    int main(int argc, const char * argv[])
    {
        /* Create a list with only one node */
        LinkedList list(1);
        /* Append 3 nodes to the end of the list */
        list.tailAppend(2);
        list.tailAppend(3);
        list.tailAppend(4);    
        cout << "Before reversing:" << endl;
        getch();
        }
    Tags:

    Virtusa 

  • 3. Write a program to implement the stack and queue using list

    Input : ,   Output :

    View Answer View Answer | Program Topics Linked List | Write Your Program Discuss in Forum | Add to Reading List To Reading List | Tag to companies Asked In | Level Fresher
  • Answer In: C   C++  
     
    #include<conio.h>       
    #include<iostream.h> 
    #include<process.h>  
    #include<malloc.h>   
    /*Creating a NODE Structure*/
    struct node
    {
       int data;
       struct node *next;
    };
     
    /*Creating a class QUEUE*/
    class queue
    {
       struct node *frnt,*rear;
       public:
          queue() // constructure
          {
         frnt=rear=NULL;
          }
          void insert(); /*to insert an element*/
          void del();  /* to delete an element*/
          void show(); /* to show the stack*/
    };
    /* Insertion */
    void queue::insert()
    {
       int value;
       struct node *ptr;
       cout<<"\nInsertion\n";
       cout<<"Enter a number to insert: ";
       cin>>value;
       ptr=new node;
       ptr->data=value;
       ptr->next=NULL;
       if(frnt==NULL)
          frnt=ptr;
       else
          rear->next=ptr;
       rear=ptr;
       cout<<"\nNew item is inserted to the Queue!!!";
       getch();
    }
     
    /* Deletion*/
    void queue::del()
    {
       if(frnt==NULL)
       {
          cout<<"\nQueue is empty!!";
          getch();
          return;
       }
       struct node *temp;
       temp=frnt;
       frnt=frnt->next;
       cout<<"\nDeletion Operation........\nDeleted value is "<<temp->data;
       delete temp;
       getch();
    }
     
    /* Show Queue*/
    void queue::show()
    {
       struct node *ptr1=frnt;
       if(frnt==NULL)
       {
          cout<<"The Queue is empty!!";
          getch();
          return;
       }
       cout<<"\nThe Queue is\n";
       while(ptr1!=NULL)
       {
          cout<<ptr1->data<<" ->";
          ptr1=ptr1->next;
       }
       cout<<"END";
       getch();
    }
    int main()
    {
       clrscr();
       queue q;
       int choice;
       while(1)
       {
          cout<<"\n-----------------------------------------------------------";
          cout<<"\n\t\tQUEUE USING LINKED LIST\n\n";
          cout<<"1:INSERTION\n2:DELETION\n3:DISPLAY QUEUE\n4:EXIT";
          cout<<"\nEnter your choice(1-4): ";
          cin>>choice;
          switch(choice)
          {
           case 1:
          q.insert();
          break;
           case 2:
          q.del();
          break;
           case 3:
          q.show();
          break;
           case 4:
          exit(0);
          break;
           default:
          cout<<"Please enter correct choice(1-4)!!";
          getch();
          break;
           }
       }
       return 0;
    }
    Tags:

    Virtusa 

  • 4. Write a program to check a String is palindrome or not? How many minimum number of control variable you need.

    Input : ,   Output :

  • Answer In: C   C++   PHP  
     
    #include <iostream>
    using namespace std;
    int main(){
        char string1[20];
        int i, length;
        int flag = 0;
        cout << "Enter a string: "; cin >> string1;    
        length = strlen(string1);    
        for(i=0;i < length ;i++){
            if(string1[i] != string1[length-i-1]){
                flag = 1;
                break;
           }
        }    
        if (flag) {
            cout << string1 << " is not a palindrome" << endl; 
        }    
        else {
            cout << string1 << " is a palindrome" << endl; 
        }
        system("pause");
        return 0;
    }
    Tags:

    Wipro Virtusa 

  • 5. Write a program to delete a node in single and double linked list.

    Input : ,   Output :

    View Answer View Answer | Program Topics Linked List | Write Your Program Discuss in Forum | Add to Reading List To Reading List | Tag to companies Asked In | Level Experience
  • Answer In:
     No Discussion on this question yet!
    Tags:

    Hewlett Packard Enterprise Virtusa 

  • 6. Write a program of removing a node in double linklist.

    Input : ,   Output :

    View Answer View Answer | Program Topics Linked List | Write Your Program Discuss in Forum | Add to Reading List To Reading List | Tag to companies Asked In | Level Experience
  • Answer In:
     No Discussion on this question yet!
    Tags:

    Radisys Virtusa 

  • 7. Write a program to delete a node in double linklist if info match.

    Input : ,   Output :

    View Answer View Answer | Program Topics Linked List | Write Your Program Discuss in Forum | Add to Reading List To Reading List | Tag to companies Asked In | Level Experience
  • Answer In:
     No Discussion on this question yet!
    Tags:

    Wipro Virtusa 

  • 8. Write a program to count the no. of words in the given string?

    Input : hello world,   Output : 2

  • Answer In:
     No Discussion on this question yet!
    Tags:

    Virtusa 

  • 9. Write a program to check & count the occurrence of character in the given string?

    Input : ,   Output :

  • Answer In:
     No Discussion on this question yet!
    Tags:

    Virtusa 

  • 10. Write a program to check whether given date is valid or not?

    Input : 1. DDMMYYYY :: 24092017 2. DDMMYYYY :: 54142017,   Output : 1. Valid 2. Invalid

  • Answer In: JAVA  
     
    <p>import java.text.DateFormat;<br />
    import java.text.ParseException;<br />
    import java.text.SimpleDateFormat;<br />
    import java.util.Scanner;</p>

    <p>class DateValid {</p>

    <p>    public static void main(String[] args) {</p>

    <p>        Scanner input = null;<br />
            try {<br />
                input = new Scanner(System.in);<br />
                System.out.println("Enter date in dd/MM/yyyy format : ");<br />
                String date = input.next();<br />
                if (isDateValid(date)) {<br />
                    System.out.println("Date is valid.");<br />
                } else {<br />
                    System.out.println("Date is not valid.");<br />
                }<br />
            } finally {<br />
                if (input != null) {<br />
                    input.close();<br />
                }<br />
            }<br />
        }</p>

    <p>    private static boolean isDateValid(String date) {</p>

    <p>        boolean result = false;</p>

    <p>        if (isValidDateFormat(date)) {<br />
                DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");<br />
                dateFormat.setLenient(false);<br />
                try {<br />
                    dateFormat.parse(date);<br />
                    result = true;<br />
                } catch (ParseException e) {<br />
                    result = false;<br />
                }<br />
            }<br />
            return result;<br />
        }</p>

    <p>    private static boolean isValidDateFormat(String date) {<br />
            String pattern = "(0?[1-9]|[12][0-9]|3[01])\\/(0?[1-9]|1[0-2])\\/([0-9]{4})";<br />
            boolean result = false;<br />
            if (date.matches(pattern)) {<br />
                result = true;<br />
            }<br />
            return result;</p>

    <p>    }</p>

    <p>}</p>
    Tags:

    Virtusa