Wednesday, July 22, 2015

Dynamic Memory Allocation - A simple example

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

int main()
{
    int *data;
    printf("hit enter to create memory");
    getch();
    data=(int*)malloc(sizeof(int));

    if(data==NULL)
    {
        printf("\nError! memory not allocated.");
        exit(0);
    }
    printf("\nEnter data to store: ");
    scanf("%d",data);
    printf("data stored is =%d",*data);

    return 0;
}

Friday, June 24, 2011

ARRAY IMPLEMENTATION OF QUEUE

#include<stdio.h>
#include<conio.h>

int q[50],frnt,rear,choice;

void view();
void enqueue();
void dequeue();

void main()
{
frnt=-1;

Wednesday, June 22, 2011

TO COUNT NUMBER OF NODES IN BINARY SEARCH TREE


//PROGRAM FOR COUNTING NUMBER OF NODES IN BINARY SEARCH TREE
#include<stdio.h>
#include<conio.h>


struct node
{
int data;
struct node *left;
struct node *right;
}*root,*t;

SINGLY LINKED LIST








#include<stdio.h>
#include<conio.h>


struct node
{
int info;
struct node *next;
};


struct node* creation();
void display(struct node*);

INSERTION SORT


#include<stdio.h>
#include<conio.h>


void ins(int [],int);


void main()
{
int ar[10],n,i;
clrscr();
scanf(" %d",&n);
for(i=0;i<n;i++)
 scanf("%d",&ar[i]);

DOUBLY LINKED LIST


#include<stdio.h>
#include<conio.h>


struct node
{
int info;
struct node *flink;
struct node *blink;
};


struct node* creation();
void display(struct node*);
struct node* insfirst(struct node*);
struct node* inslast(struct node*);

DEPTH FIRST SEARCH


#include<stdio.h>
#include<conio.h>


int v[10];
void dfs(int [][10],int,int);


void main()
{
int ar[10][10],n,i,j,k;
clrscr();
printf("numberof nodes\n");
scanf(" %d",&n);

CIRCULAR LINKED LIST


#include<stdio.h>
#include<conio.h>


struct node
{
int info;
struct node *next;
};


struct node* creation();
void display(struct node*);
struct node* insfirst(struct node*);
struct node* inslast(struct node*);
struct node* insbyele(struct node*);
struct node* insbypos(struct node*);
struct node* delatlast(struct node*);
struct node* delbyele(struct node*);
struct node* delbypos(struct node*);
struct node* delfirst(struct node*);

Monday, June 13, 2011

Binary Search


#include<stdio.h>
#include<conio.h>


void bsearch(int [],int,int,int);


void main()
{
int ar[10],n,i,k;
clrscr();
scanf(" %d",&n);
for(i=0;i<n;i++)
 scanf("%d",&ar[i]);

Breadth First Search


#include<stdio.h>
#include<conio.h>


int v[10];
void bfs(int [][10],int);


void main()
{
int ar[10][10],n,i,j,k;
clrscr();
printf("numberof nodes\n");
scanf(" %d",&n);