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 !!!

Sunday, September 16, 2012

CONDITIONAL AND SWITCH


            In GCC, conditional and switch programming is as like Windows (TC).

CONDITIONAL PROGRAMMING
            Conditional program has structure in Windows (TC) as

if(condition1)
{
            statements;
}
else if(conditon2)
{
            statements;
}
else
{
            statements;
}

This is same structure for GCC.

SWITCH-CASE PROGRAMMING
            switch-case programming has structure in Windows (TC) as

switch(choice)
{
            case 1: statements;
                        break;
            case 2: statements;
                        break;
            case 3: statements;
                        break;
            .
            .
            .
}

This is also same structure for GCC.

Let’s check some examples of these…
  1)    CONDITONAL PROGRAM

#include<stdio.h>
#include<string.h>
int main()
{
      float age=0.0;
      char concetion[10]="NULL";

      printf("\n\n Concetion Rate Board");
      printf("\n\n Enter your age : ");
      scanf("%f",&age);
      if(age<=18)
                  strcpy(concetion,"FULL");
      else if(age>=60)
                  strcpy(concetion,"HALF");
      else
                  strcpy(concetion,"NO");
      printf("\n You have %s concetion",concetion);
      printf("\n");
return 0;
}

  2)    switch-case program

#include<stdio.h>
#include<stdlib.h>
int main()
{
            int choise=0;
            float amount=0.0;
            printf("\n Transaction Unit");
            printf("\n 1-Deposite        \
                        \n 2-widrowal \
                        \n 3-exit        \
                        \n Enter your choice (1/2) : ");
            scanf("%d",&choise);
            switch(choise)
            {
            case 1: printf("\n\n Enter amount you want to Deposite : ");
                        scanf("%f",&amount);
                        printf(" Your %.2f amount is Deposited !!!",amount);
                        break;

            case 2: printf("\n\n Enter amount you want to Widraw : ");
                        scanf("%f",&amount);
                        printf(" Your %.2f amount is Widrawed !!!",amount);
                        break;

            case 3: printf("\n\n You have entered option to exit.");
                        exit(0);

            default: printf("\n\n You have entered incorrect option !!!");

            }
            printf("\n");
return 0;
}

Saturday, September 8, 2012

Header Files

"Header file" is a file which contains prototypes or declarations of certain required functions or macros or variables. Functions -those declared in header files- has a benefit that those can be reused,recalled. Because of "Header file concept", programming became easy; otherwise in past, programmer need to write whole code for each function or macro or variables or concepts, each time !!!!!

For example, in C compiler-GCC, prototype of printf(), scanf() functions is declared(written) in stdio.h file. But in FORTRAN language, because of absence of "header files", programmer wrote complete coding of scanning, printing, exiting and all processes -each time.

The C Pre-Processor links those functions to their header files and replaces those functions with their complete prototype. Header files need to included at the starting of C code.
All header files are located in "/usr/include" directory

GCC contain all ANSI  approved header files only. But most of other compilers, create and put their own header files. You can include or install other .h files in GCC. All header files in GCC and Borland TC are given below. Hope they will help you !!!


STANDARD
OR GCC
BORLAND


assert.h
alloc.h
complex.h
bios.h
ctype.h
conio.h
errno.h
dir.h
fenv.h
dirent.h
float.h
dos.h
inttypes.h
fnkeys.h
iso646.h
graphics.h
limits.h
generic.h
locale.h
io.h
math.h
process.h
setjmp.h
share.h
signal.h
sys\stat.h
stdarg.h
TurboC.h
stdbool.h

stddef.h

stdint.h

stdio.h

stdlib.h

string.h

tgmath.h

time.h

wchar.h

wctype.h