Sunday, August 25, 2013

Data Structures


Definition:
  1)      Data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently.
  2)      Data structure is union of - set of Domains, set of operations & set of axioms.
  3)      Data structure is a concept of C language which reveals how to use Data Types, Functions, Dynamic Memory Allocation in a program in such a way that programmer can write program that saves memory and does more & complete processes.

Using data structure, a program can allocate memory for variables, functions etc. and after its use memory can be de-allocated. Also using DS, program can arrange data in such a way that user can access and process in less time and less memory.

TYPES OF DS

1)      Primitive: Basic, predefined, in built DS. Ex- int, float, chars, logical data, pointers, etc.
2)      Non primitive: Derived from primitive, homogeneous & heterogeneous DS. Ex- struct, etc.
3)      Static: DS for which allocate memory at compile time.
4)      Dynamic: DS for which allocate memory at run time.
5)      Linear: Data arranged in linear pattern.
6)      Non-linear: Data arranged in non-linear pattern. Ex- tree, graph.
7)      Persistent: data can be accessed but can’t be modified. Ex- functions.
8)      Ephemeral: data can be accessed and modified. Ex- stack, queue.

For dynamic memory allocation, it needs functions like malloc(), calloc(), realloc(), free() and prototype of these functions is defined in stdlib.h. Also prototype of exit() is defined in stdlib.h.

One program of Single Link List-

#include<stdio.h>
#include<stdlib.h>

typedef struct node
{
            int data;
            struct node *next;
}NODE;

NODE *create(NODE *);
void display(NODE *);
int main()
{
            NODE *root;
            int ch;
            root=NULL;

while(1)
{           printf("\n\n----> SLL OPR <----            \
                        \n 1 Enter SLL values  \
                        \n 2 Print values          \
                        \n 3 Exit                       \
                        \n Enter choise = ");
            scanf("%d",&ch);
            switch(ch)
            {
                        case 1: root=create(root);
                                    break;
                        case 2: display(root);
                                    break;
                        case 3: exit(0);
            }
}
return 0;
}

NODE *create(NODE *root)
{
            NODE *ptr;
            printf("\n\n CREATE MENU");
            printf("\n\n Enter value - ");
            if(root==NULL)
            {
                        root=(NODE *)malloc(sizeof(NODE));
                        scanf("%d",&root->data);
                        root->next=NULL;
            }
            else
            {
                        for(ptr=root; ptr->next!=NULL; ptr=ptr->next);
                        ptr->next=(NODE *)malloc(sizeof(NODE));
                        scanf("%d",&ptr->next->data);
                        ptr->next->next=NULL;
            }
return (root);
}

void display(NODE *root)
{
            NODE *ptr;
            printf("\n\n----> DISPLAY MENU <----\n\n");
            for(ptr=root; ptr!=NULL; ptr=ptr->next)
                        printf("\t%d",ptr->data);
}

Rest of program for modification, deletion, sorting is as per given in syllabus and written in TC.

This is

Saturday, August 24, 2013

What is GCC ?


Friday, August 23, 2013

Some Useful Links !!!