C++ Programming Tutorial

 
 
 

Data File Structure Programs

Array

Insert, edit, delete, append, display, Srch. Insert, delete, merge, delete multiple occurrences Arrays as a Stack in graphics

Stack

Stack operations using array Stack using static memory allocation Stack using dynamic memory allocation Double ended link list as a stack Lnked list as a Stack Infix expr. to Postfix expr. Postfix expr. into an Infix expr. Arrays as a Stack in graphics Stack as an Arithmetic expr. Evaluater Graphical Rep. of Stack Stack to traverse - inodr, postodr, preodr

Queue

Queue using static memory allocation Queue using dynamic memory allocation Circular queue Linked list as a Queue Double Ended linked list as a Queue Graphical Rep. of Queue Arrays as a Linear Queue Array as a Circular Queue Arrays as a Linear Queue ( in graphics ) Arrays as a Circular Queue ( in graphics )

Linked List

Singly link list Circular linked list Doubly link list Linked list as a Queue Linked list as a Stack Double Ended linked list as a Queue Double Ended linked list as a Stack Infix to Postfix - Linked List as Stack Circular doubly link list Single Ended Linked List - Sorting in both odr Hashing - double ended Linked List Sort of link list

Tree

Linked List as a Binary Srch. Tree Set Class using Binary Srch. Tree Maximum depth of Binary Srch. Tree Minimum Spaning Tree Prims algo - minimum spanning tree Traverse binary tree - inodr, preodr, post Find number in binary Srch. tree display levell

Sorting

Bubble Sort Selection Sort Insertion Sort Radix Sort Merge Sort Quick Sort Heap Sort Linear Sort Shell Sort Topological Sort

Searching

Linear Srch. or Sequential Srch. Binary Search Breadth First Search Traversal Depth First Search Traversal Shortest Path-Given Source-Destination-Dijkstras

Hashing

Simple implementation of Hashing Hashing using double-ended Linked List Hashing using Mid-Square Method Example of Hashing n term of the fibonacci series using recursion

Recursion

Factorial of the given number using recursion Mystery of Towers of Hanoi using recursion
 
 

Image

# include <iostream.h>
# include <process.h>
# include <conio.h>
# include <malloc.h>

int cur_link_list=1;
int display_menu();
struct link_list
{
 int no;
 struct link_list *next;
};

class link
{
 link_list *list;
 public:
       link_list *head;
       link()
       {
    list=NULL;
    head=NULL;
       }
       void get_list();
       void display_list();
       void insert();
       void delete_list();
       void sort();
       void merge(link_list *,link_list*);
       friend void union_list(link_list *,link_list *);
       friend void intersact(link_list *,link_list *);
       void reverse();
};

void link :: get_list()
{
  int no;
  if(head!=NULL)
  {
  while(list->next!=head)
  {
   delete(list);
   list=list->next;
  }
  list=NULL;
  head=NULL;
  }
  while(1)
  {
    cout<<\"Enter Number :\";
    cin>>no;
    if(no!=0)
    {
      if(list==NULL)
      {
       list=new link_list;





       head=list;
      }
      list->no=no;
      list->next = new link_list;
      list=list->next;
    }
    else
    {
     list->next=head;
     break;
    }
  }
}

void link :: display_list()
{
 list=head;
 cout<<endl;
 if (list==NULL)
 {
  cout<<\"Link list is empty !!!\";
  return;
 }
 if(list->next==head)
 {
  cout<<list->no;
  return;
 }
 while(list->next!=head)
 {
   cout<<list->no<<\"\\t\";
   list=list->next;
 }
}

void link :: insert()
{
  int ch;
  list=head;
  cout<<endl;
  cout<<\"[ 1 ] : Insert at First\"<<endl;
  cout<<\"[ 2 ] : Insert in Middle\"<<endl;
  cout<<\"[ 3 ] : Insert at Last\"<<endl;
  cout<<\"[ 4 ] : Back to main Menu\"<<endl;
  cout<<\"Enter your choice :\";
  cin>>ch;
  link_list *newnode;
  newnode=new link_list;
  switch(ch)
  {
   case 1:
       cout<<\"Enter Number :\";
       cin>>newnode->no;
       list=head;
       newnode->next=list;
        while(list->next!=head)
        {
         list=list->next;
        }
        list->next=newnode;
        head=newnode;
       break;
   case 2: int no;
       cout<<endl;
       cout<<\"Enter Number after which you want to insert :\";





       cin>>no;
       list=head;
       while(list->next !=head)
       {
         if(list->no==no)
         {
           cout<<\"Enter Number to Insert :\";
           cin>>newnode->no;
           if(list==head)
           {
           list=head;
           newnode->next=list;
           while(list->next!=head)
           {
          list=list->next;
           }
           list->next=newnode;
           head=newnode;
           }
           else
           {
        newnode->next=list->next;
        list->next=newnode;
           }
           return;
         }
         list=list->next;
       }
       cout<<\"Key not found ...\"<<endl;
       break;
   case 3 : list=head;
        while(list->next!=head)
        {
         list=list->next;
        }
        cout<<\"Enter Number :\";
        cin>>newnode->no;
        list->next=newnode;
        newnode->next=head;
        break;
  }
}

void link :: delete_list()
{
 cout<<endl;
 list=head;
 int no;
 cout<<\"Enter the number to deleted :\";
 cin>>no;
  if(head->no==no)
   {
    while(list->next!=head)
    {
     list=list->next;
    }
    list->next=head->next;
    head=head->next;
    return;
   }

 while(list->next!=head)
 {
   if(list->next->no==no)
   {





     list->next=list->next->next;
     return;
   }
   list=list->next;
 }
 cout<<\"Number not not found !!!\";
}

void link :: sort()
{
 link_list *i,*j,*t;
 for(i=head;i->next!=head;i=i->next)
 {
  for(j=head;j->next!=head;j=j->next)
  {
   if(i->no < j->no)
   {
     t->no=i->no;
     i->no=j->no;
     j->no=t->no;
   }
  }
 }
}

void union_list(link_list *l1,link_list *l2)
{
  cout<<endl;
  link_list *head1,*head2;
  head1=l1;
  head2=l2;
  link_list *h;
  h=l1;

  while(l1->next!=head1)
  {
    cout<<l1->no<<\"\\t\";
    l1=l1->next;
  }
 int flag=0;
  while(l2->next!=head2)
  {
     l1=h;
     flag=0;
     while(l1->next!=head1)
     {
      if(l1->no==l2->no)
      {
       flag=1;
       break;
      }
      l1=l1->next;
     }
     if(flag==0)
     {
       cout<<l2->no<<\"\\t\";
     }
     l2=l2->next;
  }
}

void intersact (link_list *l1,link_list *l2)
{
 link_list *head1;
 head1=l1;





 link_list *h;
 h=l2;
 while(l1->next!=head1)
 {
   l2=h;
   while(l2->next!=h)
   {
     if(l1->no==l2->no)
     {
      cout<<l1->no<<\"\\t\";
      break;
     }
     l2=l2->next;
   }
   l1=l1->next;
 }
}

void link :: reverse()
{
 int a[50];
 list=head;
 int i=0;
 while(list->next!=head)
 {
  a[i]=list->no;
  list=list->next;
  i=i+1;
 }
 int n=i-1;
 i=n;
 list=head;
 while(list->next!=head)
 {
  list->no=a[i];
  list=list->next;
  i=i-1;
 }
}

void link :: merge(link_list *l1,link_list *l2)
{
 link_list *head1,*head2;
 head1=l1;
 head2=l2;
 head=NULL;
 list=new link_list;
 while(l1->next !=head1)
 {
   if(head==NULL)
   {
    head=list;
   }
   list->no=l1->no;
   list->next=new link_list;
   list=list->next;
   l1=l1->next;
   list->next=head;
 }
 while(l2->next !=head2)
 {
  list->no=l2->no;
  list->next=new link_list;
  list=list->next;
  l2=l2->next;





  list->next=head;
 }
 list->next=head;
}
void main()
{
 clrscr();
 link l1,l2,l3;
 while(1)
 {
  switch(display_menu())
  {
      case 1: cout<<\"Enter LinkList Number [ 1 , 2 , 3 ]:\";
          int n;
          cin>>n;
          if(n>=1 && n<=3)
          {
           cur_link_list=n;
          }
          break;
      case 2: switch(cur_link_list)
          {
           case 1: l1.get_list();
               break;
           case 2: l2.get_list();
               break;
           case 3: l3.get_list();
               break;
          }
          getch();
          break;

      case 3: switch(cur_link_list)
          {
        case 1 : l1.display_list();
             l1.insert();
             break;
        case 2 : l2.display_list();
             l2.insert();
             break;
        case 3 : l3.display_list();
             l3.insert();
             break;
          }
          getch();
          break;
      case 4: switch(cur_link_list)
          {
        case 1: l1.display_list();
            break;
        case 2: l2.display_list();
            break;
        case 3: l3.display_list();
            break;
          }
          getch();
          break;
      case 5:
          switch(cur_link_list)
          {
           case 1: l1.display_list();
               l1.delete_list();
               break;

           case 2: l2.display_list();





               l2.delete_list();
               break;

           case 3: l3.display_list();
               l3.delete_list();
               break;
          }
          getch();
          break;
      case 6: cout<<endl;
          switch(cur_link_list)
          {
        case 1: l1.sort();
            l1.display_list();
            break;
        case 2: l2.sort();
            l2.display_list();
            break;
        case 3: l3.sort();
            l3.display_list();
            break;
          }
          cout<<endl<<endl<<\"Linklist sorted !!!\";
          getch();
          break;

      case 7: cout<<endl<<endl<<\"Union of First two List...\"<<endl;
          union_list(l1.head,l2.head);
          getch();
          break;
      case 8:cout<<endl<<endl<<\"Intersaction of First two list...\"<<endl;
         intersact(l1.head,l2.head);
         getch();
         break;
      case 9: switch(cur_link_list)
          {
           case 1: l1.reverse();
               break;
           case 2: l2.reverse();
               break;
           case 3: l3.reverse();
               break;
          }
          getch();
          break;
      case 10 : l3.merge(l1.head,l2.head);
        cout<<endl;
        cout<<\"First two linklist merged in third link list !!!\";
        l3.display_list();
        getch();
        break;
      case 11 : exit(1);

  }
 }

}

int display_menu()
{
 clrscr();
 cout<<endl;
 cout<<\" [ 01 ] Select Linklist (Selected List is:\"<<cur_link_list<<\")\"<<endl;
 cout<<\" [ 02 ] Get Elements\"<<endl;
 cout<<\" [ 03 ] Insert\"<<endl;





 cout<<\" [ 04 ] Display\"<<endl;
 cout<<\" [ 05 ] Delete\"<<endl;
 cout<<\" [ 06 ] Sort\"<<endl;
 cout<<\" [ 07 ] Union\"<<endl;
 cout<<\" [ 08 ] Intersaction\"<<endl;
 cout<<\" [ 09 ] Reverse\"<<endl;
 cout<<\" [ 10 ] Merge Linklist\"<<endl;
 cout<<\" [ 11 ] Exit\"<<endl;
 cout<<\" Enter your choice :\";
 int ch;
 cin>>ch;
 return ch;
}

    Related Post:
  1. Program to create a circular linked list

  2. Program to illustrate the operations that can be performed on pointers

  3. Program to show the projection of 3D objects using Orthographics Parallel Projection w.r.t. xy-plane and along vector v

  4. Program to illustrate the implementation of arrays as a Linear Queue ( in graphics )

  5. Program that uses this DFA and validates whether an entered string is valid integer or not.

  6. Program to illustrate the declaration , initialization and printing a constant variable

  7. Program that places n equally spaced points on the circumference of a circle of radius r,and then join each point to every other point

  8. Write a program to Add Two Matrix

  9. Program to print a Single Ended Linked List in Original & Reverse order and sort it in Ascending & Decending Order

  10. Scanner of valide variable name in c

  11. Program to show the implementation of Window-to-Viewport Coordinate Transformaton

  12. Program of displaying graphical menu and operate it using arrow keys

  13. Program to illustrate the use of parameterless function

  14. Program that changes an infix expression to a postfix expression according

  15. Program simulate the working of Pre-Processor

  16. Program to read a Linear System of Equations,then evaluate it by using Guass-Seidel Itrative Method and show the result

  17. Program to show the 3D Reflection Transformation along zx-plane

  18. Program to generate a triangular wave form according to a specified pair of Amplitude and Frequency

  19. Program to print a histogram

  20. Program to computes the n_th term of the fibonacci series using Divide and Conquer Strategy

 
 
Didn't find what you were looking for? Find more on Program to create a circular linked list