Monday, 22 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 known. Thats just damn untrue. While knowing a lot of programming language is good and sometimes, even, essential; it is more important that you know one or two languages very well.
 3. Algorithms
Any good programmer has a good understanding of algorithms. Its not necessary that you know each algorithm by heart (in fact good programmers never learn things by rote) but you must understand when to use what. Algorithms will broaden your understanding and give you new ways to tackle problems. Another important thing is Data Structures. Its more important than algorithm.
4. Coding contests
 Coding contests are good for developing your algorithmic skills and they make you think fast.
5. Design Patterns    
 Any art is learn t by emulating. And therefore, you must emulate the best. Design Patterns are tried and tested architectural (of the software kind) solutions to some commonly encountered software design issues.

Friday, 5 July 2013

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)
    {
        ptr->link = (struct list *) malloc(sizeof(struct list));
        ptr = ptr->link;
        printf("\n Enter the values of the node : %d: ", (i+1));
        scanf("%d", &ptr->info);
        ptr->link = NULL;
        i++;
    }
    printf("\n\n ---------------");
    printf("\n Total nodes = %d",i);
    printf("\n ---------------\n\n");
}

/* Function to display the list */

void  display(struct list *ptr)
{
    ptr = start.link;
    while (ptr)
    {
        printf("\n\n\t\t%d", ptr->info);
        ptr = ptr->link;
    }
}

/* Searching a value */

void search(struct list *ptr)
{
    int i = 1;
    int item;
    ptr = &start;
    prev = &start;
    printf("\n\n ------------------------------------");
    printf("\n Enter the item you want to search:");
    scanf("%d", &item);
    ptr = ptr->link;
    prev= prev->link;


    while(ptr)
    {
        if( item == ptr->info )
        {
            printf("\n\n ===============================");
            printf("\n Item is found at location: %d",i);
            printf("\n ===============================");
            break;
        }
        else
        {
            ptr = ptr->link;
            prev= prev->link;
        }
        i++;
    }
    if(item != ptr->info)
        printf("\n\n ====================");
        printf("\n Item does not exist");
        printf("\n ====================");
}

/* Main Function */

void main()
{
    struct list *ptr = (struct list *)malloc(sizeof(struct list));
    clrscr();
    create_list(ptr);
    printf("\n\n ---------------");
    printf("\n Linked list is:");
    printf("\n ---------------");
    display(ptr);
    search(ptr);
    getch();
}

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)
    {
        ptr->link = (struct list *) malloc(sizeof(struct list));
        ptr = ptr->link;
        printf("\n Enter the values of the node : %d: ", (i+1));
        scanf("%d", &ptr->info);
        ptr->link = NULL;
        i++;
    }
    printf("\n\n ---------------");
    printf("\n Total nodes = %d",i);
    printf("\n ---------------\n\n");
}

/* Function to display the list */

void  display(struct list *ptr)
{
    ptr = start.link;
    while (ptr)
    {
        printf("\n\n\t\t%d", ptr->info);
        ptr = ptr->link;
    }
}

/* Function to insert node at the end */
void insert_last(struct list *ptr)
{
    ptr = start.link;
    prev = &start;

    while(ptr)
    {
        ptr = ptr->link;
        prev= prev->link;
    }
    if(ptr == NULL)
    {
        new1 = (struct list* ) malloc(sizeof(struct list));
        new1->link = ptr ;
        prev->link = new1;
        printf("\n\n ------------------------------------");
        printf("\n Enter the item you want to insert: ");
        scanf("%d",&new1->info);
    }
}
 /* Main Function */

void main()
{

    struct list *ptr = (struct list *) malloc(sizeof(struct list));
    clrscr();
    create_list(ptr);
    printf("\n Linked list is: ");
    printf("\n ----------------------\n");
    display(ptr);
    insert_last(ptr);
    printf("\n ------------------------------------------\n");
    printf("\n Linked list after insertion of last node: \n");
    printf("\n ------------------------------------------\n");
    display(ptr);
    getch();

}

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)
    {
        ptr->link = (struct list *) malloc(sizeof(struct list));
        ptr = ptr->link;
        printf("\n Enter the values of the node : %d: ", (i+1));
        scanf("%d", &ptr->info);
        ptr->link = NULL;
        i++;
    }
    printf("\n\n ---------------");
    printf("\n Total nodes = %d",i);
    printf("\n ---------------\n\n");
}

/* Function to display the list */

void display(struct list *ptr)
{
    ptr = start.link;
    while (ptr)
    {
        printf("\n\n\t\t%d", ptr->info);
        ptr = ptr->link;
    }
}

/* Function to insert node at beginning */

void insert_first(struct list *ptr)
{
    ptr = start.link;
    prev = &start;
    new1 = (struct list* ) malloc(sizeof(struct list));
    new1->link = ptr ;
    prev->link = new1;
    printf("\n\n --------------------------------------");
    printf("\n Enter the item you want to insert: ");
    scanf("%d",&new1->info);

}

/* Main Function */

void main()
{

    struct list *ptr = (struct list *) malloc(sizeof(struct list));
    clrscr();
    create_list(ptr);
    printf("\n Linked list is: ");
    printf("\n ----------------------\n");
    display(ptr);
    insert_first (ptr);
    printf("\n ------------------------------------------\n");
    printf("\n Linked list after insertion of first node: \n");
    printf("\n ------------------------------------------\n");
    display(ptr);
    getch();

}

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)
    {
        ptr->link = (struct list *) malloc(sizeof(struct list));
        ptr = ptr->link;
        printf("\n Enter the values of the node : %d: ", (i+1));
        scanf("%d", &ptr->info);
        ptr->link = NULL;
        i++;
    }
    printf("\n\n ---------------");
    printf("\n Total nodes = %d",i);
    printf("\n ---------------\n\n");
}

/* Function to display the list */

void  display(struct list *ptr)
{
    ptr = start.link;
    while (ptr)
    {
        printf("\n\n\t\t%d", ptr->info);
        ptr = ptr->link;
    }
}

/* Function to delete last node */

void del_last(struct list *ptr)
{

    ptr = start.link;
    prev = &start;

    if (ptr == NULL)
    {
        printf("\n\n\n ---------");
        printf("\n Underflow");
        printf("\n ---------");
    }

    else

        while(ptr->link)
        {
            ptr = ptr->link;
            prev = prev->link;
        }

        prev->link = ptr->link;
        free(ptr);


}
/* Main Function */

void main()
{

    struct list *ptr = (struct list *) malloc(sizeof(struct list));
    clrscr();
    create_list(ptr);
    printf("\n Linked list is: ");
    printf("\n ---------------\n");
    display(ptr);
    del_last(ptr);
    printf("\n ---------------------------------------------\n");
    printf("\n Linked list after deletion of last node: \n");
    printf("\n ---------------------------------------------\n");
    display(ptr);
    getch();

}

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)
    {
        ptr->link = (struct list *) malloc(sizeof(struct list));
        ptr = ptr->link;
        printf("\n Enter the values of the node : %d: ", (i+1));
        scanf("%d", &ptr->info);
        ptr->link = NULL;
        i++;
    }
    printf("\n\n ---------------");
    printf("\n Total nodes = %d",i);
    printf("\n ---------------\n\n");
}

/* Function to delete first node */

void del_first(struct list *ptr)
{
    ptr = start.link;
    prev = &start;

    prev->link = ptr->link;
    free(ptr);

}


/* Function to show list */

void display(struct list *ptr)
{
    ptr = start.link;

        while (ptr)
        {

            printf("\n\n\t\t %d", ptr->info);
            ptr = ptr->link;
        }
}


/* Main Function */

void main()
{

    struct list *ptr = (struct list *) malloc(sizeof(struct list));
    clrscr();
    create_list(ptr);
    printf("\n Doubly linked list is: ");
    printf("\n ----------------------\n");
    display(ptr);
    del_first (ptr);
    printf("\n ------------------------------------------------\n");
    printf("\n Doubly linked list after deletion of first node: \n");
    printf("\n ------------------------------------------------\n");
    display(ptr);
    getch();

}

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");
    printf("\n ==============================================================================\n");
    while( i!=n)
    {
        ptr->link = (struct list* ) malloc(sizeof(struct list));
        ptr = ptr->link;
        printf("\n Input the ptr: %d: ", i+1);
        scanf("%d", &ptr->info);
        ptr->link = NULL;
        i++;
    }
    printf("\n\n -----------------");
    printf("\n Total nodes = %d", i);
    printf("\n -----------------\n");
    ptr = start;
    ptr->info = i;
}

/* Function to insert a node */

void insert(struct list *ptr)
{
    int loc,num = 1;
    int count;
    ptr = ptr->link;
    count = ptr->info;
    ptr = start;
    printf("\n -----------------------------------------------\n");
    printf("\n Enter the loc where you want to insert node: ");
    scanf("%d",&loc);
    while(count)
    {
        if((num) == loc)
        {
            new1 = (struct list* ) malloc(sizeof(struct list));
            new1->link = ptr->link ;
            ptr->link = new1;
            printf("\n -----------------------------------------------\n");
            printf("\n Enter the item you want to insert: ");
            scanf("%d", &new1->info);
            ptr = ptr->link;
        }
        else
        {
            ptr = ptr->link;
            count--;
        }
        num++;
    }
    ptr = start;
    ptr->info = ptr->info+1;
}

/* Function to diplay  header linked list */

void display(struct list *ptr)
{
    int count;
    ptr = start;
    count = ptr->info;
    ptr = ptr->link;
    while (count)
    {

        printf("\n\n\t\t%d", ptr->info);
        ptr = ptr->link;
        count--;
    }
}

/* Main Function */

void main()
{
    struct list *ptr = (struct list *) malloc(sizeof(struct list));
    clrscr();
    create_hlist (ptr);
    printf("\n\n ----------------------");
    printf("\n Header linked list is:");
    printf("\n ----------------------\n");
    display (ptr);
    insert(ptr);
    printf("\n\n\n -----------------------------------");
    printf("\n Header linked list after insertion:");
    printf("\n -----------------------------------\n");
    display (ptr);
    getch();
}