Posts

Showing posts from July, 2013

How to be a good Programmer?

This is the question you always want to answer to someone but you didn't get it yet yourself. First I clear one thing that i am not a good programmer and not the writer at all but i can say i am still learning. Yes I am better than quite a few people when it comes to programming, but that's merely because they are lazy and like to sit on idly all day and never bother about programming. Their horrible skills make my less horrible skills look marvelous. Things that's help you to be a good programmer mention below  they are what I have wanted to be and I am not. So lets dive in. 1.Decide why you want to become a good programmer this is the main question you have to ask yourself  Is it because you want a job, preferably in a high paying software firm? Great. Then you are set to reach NOWHERE. All good programmers I know are good because they loved what they did. 2. Programming languages Very often people equate good coding skills with number of programming langauges k...

THIS PROGRAM SEARCHS AN ITEM FROM SIMPLE LINKED LIST

#include<stdio.h> #include<malloc.h> struct list {     int info;     struct list *link; }; int i; int num; struct list start, *prev, *new1; void search(struct list *); void create_list(struct list *); void display(struct list *);  /* Function to create linked list */  void create_list(struct list *ptr) {     int n;     ptr = &start;      /* Ptr points to the start pointer */     printf("\n How many nodes you want to create: ");     scanf("%d",&n);     i=0;     printf("\n\n ==============================================================================\n");     printf("\n Note That:\n -----------\n Enter numeric data in node\n");     printf("\n ==============================================================================\n");     while( i!=n)     {  ...

THIS PROGRAM INSERTS A NODE AT THE END OF SIMPLE LINKED LIST

#include<stdio.h> #include<malloc.h> struct list {     int info;     struct list *link; }; int i; int num; struct list start, *prev, *new1; void insert_last(struct list *); void create_list(struct list *); void display(struct list *);  /* Function to create linked list */  void create_list(struct list *ptr) {     int n;     ptr = &start;      /* Ptr points to the start pointer */     printf("\n How many nodes you want to create: ");     scanf("%d",&n);     i=0;     printf("\n\n ==============================================================================\n");     printf("\n Note That:\n -----------\n Enter numeric data in node\n");     printf("\n ==============================================================================\n");     while( i!=n)     { ...

THIS PROGRAM INSERTS A NODE AT THE BEGINNING OF SIMPLE LINKED LIST

#include<stdio.h> #include<malloc.h> struct list {     int info;     struct list *link; }; int i; int num; struct list start, *prev, *new1; void insert_first(struct list *); void create_list(struct list *); void display(struct list *); /* Function to create linked list */  void create_list(struct list *ptr)  {     int n;     ptr = &start;      /* Ptr points to the start pointer */     printf("\n How many nodes you want to create: ");     scanf("%d",&n);     i=0;     printf("\n\n ==============================================================================\n");     printf("\n Note That:\n -----------\n Enter numeric data in node\n");     printf("\n ==============================================================================\n");     while( i!=n)     { ...

THIS PROGRAM DELETES LAST NODE FROM SIMPLE LINKED LIST

#include<stdio.h> #include<malloc.h> struct list {     char info;     struct list *link; }; int i; int num ; struct list start, *prev; void del_last(struct list *); void display(struct list *); void create_list(struct list *); /* Function to create linked list */  void create_list(struct list *ptr) {     int n;     ptr = &start;      /* Ptr points to the start pointer */     printf("\n How many nodes you want to create: ");     scanf("%d",&n);     i=0;     printf("\n\n ==============================================================================\n");     printf("\n Note That:\n -----------\n Enter numeric data in node\n");     printf("\n ==============================================================================\n");     while( i!=n)     {   ...

THIS PROGRAM DELETES FIRST NODE FROM SIMPLE LINKED LIST

#include<stdio.h> #include<malloc.h> struct list {     int info;     struct list *link; }; int i; struct list start, *prev; void create_list(struct list *); void display(struct list *); void del_first(struct list *); /* Function to create linked list */  void create_list(struct list *ptr)  {     int n;     ptr = &start;      /* Ptr points to the start pointer */     printf("\n How many nodes you want to create: ");     scanf("%d",&n);     i=0;     printf("\n\n ==============================================================================\n");     printf("\n Note That:\n -----------\n Enter numeric data in node\n");     printf("\n ==============================================================================\n");     while( i!=n)     {     ...

THIS PROGRAM CREATES A HEADER LINKED LIST

#include<stdio.h> #include<malloc.h> struct list {     int info;     struct list *link; }; int i; int num; struct list *start, *new1; void insert(struct list *); void create_hlist(struct list *); void display (struct list *); /* Function to create a header linked list */ void create_hlist(struct list *ptr) {     int n;     start->link = NULL;  /* Empty list1 */     ptr = start;      /* Point to the header ptr of the list1 */     ptr->link = (struct list* ) malloc(sizeof(struct list)); /* Create header ptr */     printf("\n How many nodes you want to create: ");     scanf("%d",&n);     i=0;     printf("\n\n ==============================================================================\n");     printf("\n Note That:\n -----------\n Enter numeric data in node\n");  ...

THIS PRORAM PERFORMS INSERTOIN AT THE END OF DOUBLY LINKED LIST

#include<stdio.h> #include<malloc.h> struct dlist {     char info[20];     struct dlist *link;     struct dlist *prev; }; int i; struct dlist  start, *new1; void insert_last (struct dlist *); void create_dlist (struct dlist *); void display (struct dlist *); /* Function to create doubly linked list */  void create_dlist(struct dlist *ptr) {     int n;     start.link = NULL;  /* Empty list */     start.prev = NULL;     ptr = &start;      /* Ptr points to the start pointer */     printf("\n\n\n How many nodes you want to create: ");     scanf("%d",&n);     printf("\n\n ==============================================================================\n");     printf("\n Note That:\n -----------\n Enter string values in nodes\n");     printf("\n ===========...

THIS PROGRAM DELETES THE LAST NODE FROM DOUBLY LINKED LIST

#include<stdio.h> #include<malloc.h> struct dlist {     int info;     struct dlist *link;     struct dlist *prev; }; int i ; struct dlist start, *prev; void del_last (struct dlist *); void create_dlist (struct dlist *); void display (struct dlist *);  /* Function to  create doubly linked list */ void create_dlist(struct dlist *ptr) {     int n;     start.link = NULL;  /* Empty list */     start.prev = NULL;     ptr = &start;      /* Ptr points to the start pointer */     printf("\n How many nodes you want to create: ");     scanf("%d",&n);     printf("\n\n ==============================================================================\n");     printf("\n Note That:\n -----------\n Enter numeric data in nodes\n");     printf("\n =======================...

THIS PROGRAM DELETES A NODE FROM GIVEN LOCATION OF DOUBLY LINKED LIST

#include<stdio.h> #include<malloc.h> struct dlist {     int info;     struct dlist *link;     struct dlist *prev; }; int i ; struct dlist start; void del_node (struct dlist *); void create_dlist (struct dlist *); void display (struct dlist *); /* Function to  create doubly linked list */ void create_dlist(struct dlist *ptr) {     int n;     start.link = NULL;  /* Empty list */     start.prev = NULL;     ptr = &start;      /* Ptr points to the start pointer */     printf("\n How many nodes you want to create: ");     scanf("%d",&n);     printf("\n\n ==============================================================================\n");     printf("\n Note That:\n -----------\n Enter numeric data in node\n");     printf("\n =====================================...

THIS PROGRAM CREATES A SIMPLE LINKED LIST

#include<stdio.h> #include<malloc.h> struct list {     int info;     struct list *link; }; int i; struct list start; void create_list(struct list *); void display(struct list *); /* Function to create linked list */  void create_list(struct list *ptr) {     int n;     ptr = &start;      /* Ptr points to the start pointer */     printf("\n How many nodes you want to create: ");     scanf("%d",&n);     i=0;     printf("\n\n ==============================================================================\n");     printf("\n Note That:\n -----------\n Enter numeric data in node\n");     printf("\n ==============================================================================\n");     while( i!=n)     {         ptr->link = (struct lis...

THIS PROGRAM INSERTS A NODE AT GIVEN LOCATION IN SIMPLE LINKED LIST

#include<stdio.h> #include<malloc.h> struct list {     int info;     struct list *link; }; int i; int num; struct list start, *prev, *new1; void insert_node(struct list *); void create_list(struct list *); void display(struct list *);  /* Function to create linked list */  void create_list(struct list *ptr)  {     int n;     ptr = &start;      /* Ptr points to the start pointer */     printf("\n How many nodes you want to create: ");     scanf("%d",&n);     i=0;     printf("\n\n ==============================================================================\n");     printf("\n Note That:\n -----------\n Enter numeric data in node\n");     printf("\n ==============================================================================\n");     while( i!=n)   ...

THIS PROGRAM INSERTS AN ITEM INTO SORTED LINKED LIST

#include<stdio.h> #include<malloc.h> struct list {     int info;     struct list *link; }; int i; int num; struct list start, *prev, *new1; void insert_node(struct list *); void create_list(struct list *); void display(struct list *); /* Function to create linked list */  void create_list(struct list *ptr)  {     int n;     ptr = &start;      /* Ptr points to the start pointer */     printf("\n How many nodes you want to create: ");     scanf("%d",&n);     i=0;     printf("\n\n ==============================================================================\n");     printf("\n Note That:\n -----------\n Enter numeric data in node in ASCENDING ORDER\n");     printf("\n ==============================================================================\n");     while( i!=n) ...

THIS PROGRAM DELETES A NODE AT GIVEN LOCATION FROM SIMPLE LINKED LIST

#include<stdio.h> #include<malloc.h> struct list {     int info;     struct list *link; }; int i; int num ; struct list start, *prev; void  del_node(struct list *); void  create_list(struct list *); void display(struct list *); /* Function to create linked list */  void create_list(struct list *ptr)  {     int n;     ptr = &start;      /* Ptr points to the start pointer */     printf("\n How many nodes you want to create: ");     scanf("%d",&n);     i=0;     printf("\n\n ==============================================================================\n");     printf("\n Note That:\n -----------\n Enter numeric data in node\n");     printf("\n ==============================================================================\n");     while( i!=n)     {...

THIS PROGRAM DELETES AN ITEM FROM SIMPLE LINKED LIST

#include<stdio.h> #include<malloc.h> struct list {     int info;     struct list *link; }; int i; int num ; struct list start, *prev; void del_node(struct list *); void  create_list(struct list *); void display(struct list *); /* Function to create linked list */ void create_list(struct list *ptr)  {     int n;     ptr = &start;      /* Ptr points to the start pointer */     printf("\n How many nodes you want to create: ");     scanf("%d",&n);     i=0;     printf("\n\n ==============================================================================\n");     printf("\n Note That:\n -----------\n Enter numeric data in node\n");     printf("\n ==============================================================================\n");     while( i!=n)     {  ...

THIS PROGRAM CREATES STRING TYPE LINKED LIST

#include<stdio.h> #include<malloc.h> struct list {     char info[20];     struct list *link;     struct list *prev; }; int i ; struct list start; void create_list (struct list *); void display (struct list *);  /* Function to create linked list */  void create_list(struct list *ptr) {     int n;     start.link = NULL;  /* Empty list */     start.prev = NULL;     ptr = &start;      /* Ptr points to the start pointer */     printf("\n\n\n How many nodes you want to create: ");     scanf("%d",&n);     printf("\n\n ==============================================================================\n");     printf("\n Note That:\n -----------\n Enter string values in nodes\n");     printf("\n ====================================================================...

THIS PROGRAM PERFORMS INSERTION AT THE BEGINNING OF DOUBLY LINKED LIST

#include<stdio.h> #include<malloc.h> struct dlist {     char info[20];     struct dlist *link;     struct dlist *prev; }; int i; struct dlist  start, *new1; void insert_first (struct dlist *); void create_dlist (struct dlist *); void display (struct dlist *); /* Function to create doubly linked list */ void create_dlist(struct dlist *ptr) {     int n;     start.link = NULL;  /* Empty list */     start.prev = NULL;     ptr = &start;      /* Ptr points to the start pointer */     printf("\n\n\n How many nodes you want to create: ");     scanf("%d",&n);     printf("\n\n ==============================================================================\n");     printf("\n Note That:\n -----------\n Enter string values in nodes\n");     printf("\n ================...

THIS PROGRAM DELETES FIRST NODE OF DOUBLY LINKED LIST

#include<stdio.h> #include<malloc.h> struct dlist {     char info[20];     struct dlist *link;     struct dlist *prev; }; int i ; struct dlist start; void del_first (struct dlist *); void create_dlist (struct dlist *); void display (struct dlist *);  /* Function to create doubly linked list */  void create_dlist(struct dlist *ptr) {     int n;     start.link = NULL;  /* Empty list */     start.prev = NULL;     ptr = &start;      /* Ptr points to the start pointer */     printf("\n\n\n How many nodes you want to create: ");     scanf("%d",&n);     printf("\n\n ==============================================================================\n");     printf("\n Note That:\n -----------\n Enter string values in nodes\n");     printf("\n ===================...

WRITE A PROGRAM TO CREATES CIRCULAR HEADER LINKED LIST

#include<stdio.h> #include<malloc.h> struct list {     int info;     struct list *link; }; int i; int number; struct list *start, *new1; void create_list(struct list *); void display(struct list *); /* Function to create a circular header linked list */ void create_list( struct list *ptr) {     int n;     ptr = start;      /*ptr points to the header node */     ptr->link = (struct list *) malloc(sizeof(struct list));     i = 0;     printf("\n\n\n how many nodes you want to create: ");     scanf("%d",&n);     printf("\n\n =======================================================\n");     printf("\n Note That:\n -----------\n Enter numeric data in node\n");     printf("\n =======================================================\n");     while(i!=n)     { ...

WRITE A PROGRAM TO CREATES A SIMPLE DOUBLY LINKED LIST

#include<stdio.h> #include<malloc.h> struct dlist {     int info;     struct dlist *link;     struct dlist *prev; }; int num ; struct dlist start; void create_dlist (struct dlist *); void display (struct dlist *); /* Function to creates doubly linked list */ void create_dlist(struct dlist *ptr) {     int n,i=0;     start.link = NULL;  /* Empty list */     start.prev = NULL;     ptr = &start;      /* Ptr points to the start pointer */     printf("\n How many nodes you want to create: ");     scanf("%d",&n);     printf("\n\n =======================================================\n");     printf("\n Note That:\n -----------\n Enter numeric data in node\n");     printf("\n =======================================================\n");     while( i!=n...

Program to Print elements of linear array.

//Header Files #include<stdio.h> #include<conio.h> int arr[10],n,j; void main() { clrscr(); printf("Enter size of array:"); scanf("%d", &n); printf("\n Enter array elements...."); for(int i=0;i<=n-1;i++)     scanf("%d",&arr[i]); printf("\n Printing of Elements..."); j=0; while(j<=n-1) {     printf("\n");     printf("%d", arr[j]);     j=j+1; } getch(); }

Program to delete an element from the array

//Header Files #include<stdio.h> #include<conio.h> #include<process.h> int arr[10],n,i,j,k,item,loc; void main() { clrscr(); printf("Enter size of array:"); scanf("%d", &n); if(n>10) {     printf("Entered value exceed the limit of array");     getch();     exit(0); } printf("\n Enter array elements...."); for(i=0;i<=n-1;i++)     scanf("%d",&arr[i]); printf("Enter the location of the element to be deleted..."); scanf("%d",&loc); item=arr[loc]; for(j=loc;j<=n-2;j++)     arr[j]=arr[j+1]; printf("\n Array after Deletion..."); k=0; while(k<=n-2) {     printf("\n");     printf("%d", arr[k]);     k=k+1; } getch(); }

Program to insert an element in an array

//Header Files #include<stdio.h> #include<conio.h> #include<process.h> int arr[10],n,i,j,k,item,loc; void main() { clrscr(); printf("Enter size of array:"); scanf("%d", &n); if(n>10) {     printf("Entered value exceed the limit of array");     getch();     exit(0); } printf("\n Enter array elements...."); for(i=0;i<=n-1;i++)     scanf("%d",&arr[i]); printf("Enter the element to be inserted..."); scanf("%d",&item); printf("Enter its location..."); scanf("%d",&loc); for(j=n-1;j>=loc;j--)     arr[j+1]=arr[j]; arr[loc]=item; printf("\n Array after Insertion..."); k=0; while(k<=n) {     printf("\n");     printf("%d", arr[k]);     k=k+1; } getch(); }

Program to Sort(in ascending order) set of numbers using BUBBLE SORT

#include<stdio.h> #include<conio.h> #include<process.h> #define true 1 #define false 0 int arr[10],n,i,j,temp; void main() { clrscr(); printf("Enter size of array:"); scanf("%d", &n); if(n>10) {     printf("Entered value exceed the limit of array");     getch();     exit(0); } printf("\n Enter array elements...."); for(i=0;i<=n-1;i++)     scanf("%d",&arr[i]); //LOGIC of BUBBLE SORT for(i=0;i<n-1;i++) {     for(j=0;j<(n-1)-i;j++)     {         if(arr[j]>arr[j+1])         {             temp=arr[j];             arr[j]=arr[j+1];             arr[j+1]=temp;         }     } } printf("\n Sorted Array...."); for(i=0;i<=n-1;i++)...

Write a program to two show Factorial of a number

#include<iostream.h> int rec(int); main() {     int a ,fact;     cout<<"enter any number";     cin>>a;     fact=rec(a);     cout<<fact; } int rec(int x) {     int f;     if (x==1)     return(1);     else     f=x*rec(x-1);     return(f); }

Write a program to show the concept of Merging in Data structure

#include<stdio.h> #include<conio.h> void main() { int a[10],n,k,i,j,item; printf("enter n="); scanf("%d",&n); printf("enter array elements="); for(i=1;i<=n;i++) { scanf("%d",&a[i]); } printf("enter element to be inserted="); scanf("%d",&item); printf("enter location of new element="); scanf("%d",&k); j=n; while(j>=k) { a[j+1]=a[j]; j--; } a[k]=item; n=n+1; printf("\nnew array is\n"); for(i=1;i<=n;i++) { printf("%d\n",a[i]); } }

Write a program to show the concept of merging of tow array

#include<stdio.h> #include<conio.h> void main() { int a[10],b[10],c[20],i,r,s,m; int na=1,nb=1,nc=1; printf("enter no. of array element of A\n"); scanf("%d",&r); printf("enter array elements of A\n"); for(i=1;i<=r;i++); { scanf("%d",&a[i]); } printf("enter no. of array element of B\n"); scanf("%d",&s); printf("enter array elements of B\n"); for(i=1;i<=s;i++) { scanf("%d",&b[i]); } while(na<=r&&nb<=s) { if(a[na]<b[nb]) { c[nc]=a[na]; nc=nc+1; nb=nb+1; } else {     c[nc]=b[nb];     nc=nc+1;     nb=nb+1; } } if(na>r) for(i=nb;i<=s;i++) { c[nc]=b[i]; nc=nc+1; } else { for(i=na;i<=r;i++) { c[nc]=a[i]; nc=nc+1; } printf("merged array is\n"); for(i=1;i<=s+r;i++) { printf("%d\n",c[i]); } } }

Write a program to show the PUSH method in Data Structure

#include<stdio.h> #include<conio.h> void main() {     int a[10],max=10, i, n, tos , item;     printf("enter no. of elements=");     scanf("%d",&n);     printf("enter array elements\n");         for(i=1;i<=n;i++)     {         scanf("%d",&a[i]);     }     tos=n;     if(tos>=max)     {         printf("overflow");         exit;         }     else         {         printf("enter item to be inserted=");         scanf("%d",&item);         tos=tos+1;         a[tos]=item;         printf("new s...

Write a program to show the concept of Array of Object in C++

#include<iostream.h> #include<conio.h> #include<iomanip.h> class biodata {     public:     char name[20];     int roll;     public:     void get()     {         cout<<"enter name and roll no. "<<"\n";         cin>>name>>roll;     }     public:     void put()     {         cout<<name<<setw(4)<<roll;         cout<<"\n";     } }; void main() { int i,j; cout<<"enter no. of entries"; cin>>j; class biodata obj[20]; for (i=1; i<=j ; i++) {     obj[i].get(); } cout<<"\n"; for (i=1; i<=j ; i++) {     obj[i].put(); } }        

Write a program to show the concept of POP operation in Data Structure

#include<stdio.h> #include<conio.h> void main() {     int a[10],min=0, i, n, tos , item;     printf("enter no. of elements=");     scanf("%d",&n);     printf("enter array elements\n");     for(i=1;i<=n;i++)     {         scanf("%d",&a[i]);     }     tos=n;     if(tos==min)     {         printf("underflow");         exit;         }     else         {         printf("top element is always deleted\n");     item=a[tos];     tos=tos-1;         printf("new stack\n");         for(i=1;i<=tos;i++)         {  ...

Write a program to show the concept of static member function in C++

#include<iostream.h> #include<conio.h> #include<iomanip.h> class account {     static int count;     public:     static void display()     {         count++;         cout<<"the value of count="<<count<<endl;     } }; int account::count=50; void main() {     account obj1, obj2;     account::display();     account obj3;     account::display(); }

Write a program to show the concept of Inline Function in C++

#include<iostream.h> #include<conio.h> inline float area(float r) {     return(3.14*r*r); } void main() {     float radius, a ;     cout<<"enter the radius of circle:";     cin>>radius;     a=area(radius);     cout<<"the area of circle="<<a<<"\n"; }

Write a program to show the concept of Constant Member Function in C++

#include<iostream.h> #include<conio.h> class date {     int day;      int month;      int year;      public:      void getdata(int a , int b ,int c)//define function      {          day=a;          month=b;          year=c;      }      void display(void)const//define const function      {          cout<<"date is "<<day<<"-"<<month<<"-"<<year;         cout<<"\n";      } };//end of class definition void main() {     date birthday;     birthday.getdata(15 ,11, 19);     birthday.display(); }

Write a program to show the concept of Friend Function in c++

#include<iostream.h> #include<conio.h> class two;//forward declaration class one {     int m;     public:     void getdata()     {         cout<<"enter the value for m:";         cin>>m;     }     friend int sum(one,two); };//end of class one definiton class two {     int n;     public:     void getdata()     {         cout<<"enter the value for n:";         cin>>n;     }     friend int sum(one,two); };//end of class two int sum(one a, two b)//definition of friend function {     return(a.m + b.n); } void main() {     one x;      two y;      x.getdata();      y.getdata(...

Linier Searching technique in Data structure program with flowchart and algorithm

Image
ALGORITHM VARIABLES: §   A:     array name. §   N:    number of elements in array. §   Item:       value to be searched. §   Loc: location of item to be searched.     ALGORITHM: STEP 1:     Set a [n+1] = item STEP 2:     Set LOC = 1 STEP 3:     Repeat while a [loc] != item                  LOC = LOC + 1 STEP 4:     If LOC = N+1 then,                  Search is successful                  else                  LOC = 0 & search is unsuccessful ...