Java, c, C++, win32, .net, C#, ASP, VB, ADO, and many more
Sunday, August 24, 2008
Tuesday, August 5, 2008
C source code for 2 Linked List Implementation Of Stack
#define TRUE 1
# define FALSE 0
typedef struct stack_element {
int stack_data;
struct stack_element *next;
}stack_inf;
typedef struct stack_element_top{
stack_inf *stack_top;
}stack;
stack *create()
{
stack *s;
s=(stack *)malloc(sizeof(stack));
s->stack_top=NULL;
return(s);
}
int isempty (stack *s)
{
if (s->stack_top == NULL)
return TRUE;
else
return FALSE;
}
void push (stack *s,int x)
{
stack_inf *p;
p=(stack_inf *)malloc(sizeof(stack_inf));
p->stack_data=x;
p->next=NULL;
if(isempty(s))
s->stack_top=p;
else
{
p->next=s->stack_top;
s->stack_top=p;
}
return;
}
int pop(stack *s)
{
stack_inf *p;
int x;
if(isempty(s))
printf(“\nStack is empty !\n”);
else
{
p=s->stack_top;
x=p->stack_data;
s->stack_top=p->next;
free(p);
return(x);
}
}
C source code for An array implementation of the operations of a stack ADT
#define MAX 1000 /* only 1000 elements can be stored in the stack*/
# define TRUE 1
# define FALSE 0
typedef int stack_data;
struct stack_inf{
int top;
stack_data stack_elements[MAX];
};
typedef struct stack_inf stack;
stack s;
void create(stack *s)
{
s->top=-1;
return;
}
int isempty (stack *s)
{
if (s->top == -1)
return(TRUE);
else
return(FALSE);
}
int isfull (stack *s)
{
if (s->top == (MAX -1))
return(TRUE);
else
return(FALSE);
}
stack_data pop (stack *s)
{
int t;
stack_data ret;
if (isempty(s))
printf(“The stack is empty\n”);
else
{
t = s->top;
ret=s->stack_elements[t];
s->top - -;
}
return(ret);
}
void push (stack *s, stack_data x)
{
if (isfull(s))
printf(“Stack is FULL ! No insertion possible\n”);
else
{
++s->top;
s->stack_elements[s->top]=x;
}
}
Sunday, August 3, 2008
C Source code for Implementation of queue using Linked Lists
#define TRUE 1
#define FALSE 0
struct queue_element{
int data;
struct queue_element *next;
};
typedef struct queue_element queue_info;
typedef struct qpointer{
queue_info *front, *rear;
}queue;
queue *q;
queue *create()
{
queue *p;
p=(queue *)malloc(sizeof(queue));
p->front=NULL;
p->rear=NULL;
return(p);
}
int isempty(queue *q)
{
if(q->front == NULL)
return(TRUE);
else
return(FALSE);
}
void insert_queue (queue *q,int item)
{
queue_info *new;
new=(queue_info *) malloc (sizeof (queue_info));
new->next = NULL;
new->data = item;
if (isempty(q))
{
q->front = new;
q->rear = new;
}
else
{
q->rear->next=new;
q->rear=new;
}
return;
}
int delete_queue(queue *q)
{
int item;
queue_info *del;
if (isempty(q))
{
printf(“Queue is empty ! \n”);
return(-1);
}
else
{
del=q->front;
q->front=q->front->next;
item=del->data;
free (del);
if(q->front == NULL)
q->rear=NULL;
return(item);
}
}
C Source code for Implementation of queue using Stacks
# include
#define MAX 5
#define TRUE 1
#define FALSE 0
#define ERROR -1
struct qinfo{
int front,rear;
int noele;
int qelement[MAX];
};
typedef struct qinfo queue;
void create(),insert_queue();
int isfull(),isfull(),delete_queue();
void create(queue *q)
{
q->front=-1;
q->rear=-1;
q->noele=0;
return;
}
int isempty(queue *q)
{
if(q->noele == 0)
return(TRUE);
else
return(FALSE);
}
int isfull(queue *q)
{
if(q->noele == MAX)
return(TRUE);
else
return(FALSE);
}
void insert_queue(queue *q,int item)
{
char stop;
if(isfull(q))
printf("Queue is full \n");
else
{
if(isempty(q))
{
create(q);
q->front++;
q->rear++;
}
else
if(q->rear < (MAX - 1) || q->rear < (q->front - 1))
q->rear++;
else
if(q->rear == (MAX - 1) && q->noele <>
q->rear=0;
q->qelement[q->rear]=item;
q->noele++;
}
return;
}
int delete_queue(queue *q)
{
int data;
if(isempty(q))
{
printf("Queue is empty!!!\n");
return(ERROR);
}
else
{
data=q->qelement[q->front];
if(q->front == (MAX - 1))
q->front=0;
else
q->front++;
q->noele--;
if(isempty(q))
create(q);
return(data);
}
}
Saturday, August 2, 2008
C Code for Removing duplicate nodes from linked list
NODE *pCurrent = *head;
if(pCurrent ==NULL)
return;
else {
while(pCurrent ->next !=NULL) {
if(pCurrent ->data == pCurrent ->next->data) {
NODE *nnext = pCurrent ->next->next;
free(pCurrent ->next);
pCurrent ->next = nnext;
}
else
pCurrent =pCurrent ->next;
}
}
}
C Code for Mirror Image Tree
if (node==NULL) {
return;
}
else {
struct node* temp; // do the subtrees
mirror(node->left); mirror(node->right); // swap the pointers in this node
temp = node->left;
node->left = node->right;
node->right = temp;
}
}