Saturday, May 9, 2009

BEST WEBSITES USEFULL TO EVERY ONE

http://ecmrocks.synthasite.com/resources/Best_Websites_list.xls

PROGRAM FOR IMPLEMENTING QUEUE USING LINKED LIST

#include
#include
#include
#define NULL 0
struct queue
{
int info;
struct queue *next;
};
typedef struct queue node;
node *first,*list,*front,*rear;
void add();
void del();
void print();
void main()
{
int ch;
front=rear=NULL;
do
{
printf("\n 1->add");
printf("\n 2->del");
printf("\n 3->exit");
printf("\n Enter choice");
scanf("%d",&ch);
switch(ch)
{
case 1: add();
print();
break;
case 2: del();
print();
break;
case 3: exit(0);
break;
default: printf("Invalid choice");
}
}while(ch!=3);
}
void add()
{
first=(node *)malloc(sizeof(node));
printf("Enter element");
scanf("%d",&first->info);
first->next=NULL;
if(rear==NULL)
{
rear=first;
front=first;
}
else
rear->next=first;
rear=first;
}

void del()
{
if(front==NULL)
{
printf("\nList is empty\n");
getch();
}
else
{
printf("The popped element is %d \n ",front->info);
if(front==rear)
{
front=NULL;
rear=NULL;
}
else
front=front->next;
}
}

void print()
{
list=front;
if(list==NULL)
{
printf("\nList is empty\n");
}
else
{
printf("\nfront->");
while(list!=rear)
{
printf("%d->",list->info);
list=list->next;
}
printf("%d->",list->info);
printf("rear\n");
}
}

PROGRAM FOR IMPLEMENTING STACK USING LINKED LIST

#include
#include
#include
#define NULL 0
struct stack
{
int info;
struct stack *next;
};
typedef struct stack node;
node *first,*list,*root;
void push();
void pop();
void print();
void main()
{
int ch;
root=NULL;
do
{
printf("\n 1->push");
printf("\n 2->pop");
printf("\n 3->print");
printf("\n 4->exit");
printf("\n Enter ur choice");
scanf("%d",&ch);
switch(ch)
{
case 1: push();
break;
case 2: pop();
break;
case 3: print();
break;
case 4: exit(0);
break;
}
}while(ch!=4);
}
void push()
{
first=(node *)malloc(sizeof(node));
printf("Enter element");
scanf("%d",&first->info);
first->next=root;
root=first;
}
void pop()
{
if(root==NULL)
printf("\n List is empty\n");
else
{
printf("The popped element is %d\n",root->info);
root=root->next;
}
}
void print()
{
list=root;
if(list==NULL)
printf("\nList is empty\n");
else
{
printf("\n The stack elements are");
while(list!=NULL)
{
printf("\n %d",list->info);
list=list->next;
}
}
}

PROGRAM FOR IMPLEMENTING CIRCULAR LINKED LIST

#include
#include
#include
struct cir
{
int info;
struct cir *next;
};
typedef struct cir node;
node *first,*temp,*new1,*list,*prev,*cur,*p;
void creat()
{
int ele;
printf("Type -1 to stop");
printf("\n Enter ele \t");
scanf("%d",&ele);
while(ele!=-1)
{
new1=(node *)malloc(sizeof(node));
new1->info=ele;
if(first==NULL)
{
new1->next=new1;
first=new1;
}
else
{
new1->next=first->next;
first->next=new1;
}
printf("enter ele\t");
scanf("%d",&ele);
}
}
void count()
{
int c=0;
temp=first;
first=first->next;
while(first!=temp)
{
++c;
first=first->next;
}
++c;
printf("No of nodes in circular list=%d",c);
}
void print()
{
node *start;
temp=first;
start=first->next;
printf("the circulat list is");
while(start!=temp)
{
printf("%d->",start->info);
start=start->next;
}
printf("%d",start->info);
}

PROGRAM FOR IMPLEMENTING DOUBLE LINKED LIST

#include
#include
#include
#define NULL 0
typedef struct dlist
{
int info;
struct dlist *left;
struct dlist *right;
}node;
node *root,*first,*prev,*list,*start,*temp,*end,*list1,*last;
int ele;
void create()
{
printf("Type -1 to stop");
printf("\n Enter element");
scanf("%d",&ele);
while(ele!=-1)
{
first=(node *)malloc(sizeof(node));
first->info=ele;
first->left=NULL;
first->right=NULL;
if(root==NULL)
root=first;
else
{
prev->right=first;
first->left=prev;
}
prev=first;
end=first;
scanf("%d",&ele);
}
}
void print()
{
list=root;
list1=end;
if(root==NULL)
printf("\n List is empty");
else
{
printf("\n contents of list in forward direction\n");
printf("root->");
while(list!=NULL)
{
printf("%d->",list->info);
list=list->right;
}
printf("NULL\n");
}
if(end==NULL)
printf("\n List is empty");
else
{
printf("\n contents of list in backward direction\n");
printf("end->");
while(list1!=NULL)
{
printf("%d->",list1->info);
list1=list1->left;
}
printf("NULL\n");
}
}
void delet()
{
int item;
temp=start=root;
if(root==NULL)
printf("Empty list");
else
{
printf("Enter the element to be deleted\n");
scanf("%d",&item);
if(root->info==item)
{
root=root->right;
root->left=NULL;
}
else
{
while((item!=temp->info)&&(temp!=NULL))
{
start=temp;
temp=temp->right;
}
start->right=temp->right;
temp->right->left=start;
}
}
}
void main()
{
int ch;
root=NULL;
clrscr();
do
{
printf("\n 1->create");
printf("\n 2->deletion");
printf("\n 3->exit");
printf("Enter the choice");
scanf("%d",&ch);
switch(ch)
{
case 1: create();
print();
break;
case 2: delet();
print();
break;
case 3: exit(0);
break;
}
}while(ch!=3);
getch();
}

PROGRAM FOR IMPLEMENTING SINGLR LINKED LIST

#include
#include
#include
#define NULL 0
struct slist
{
int info;
struct slist *next;
};
typedef struct slist node;
node *root,*new1,*prev,*list,*start,*temp;
int ele;
void create()
{
printf("Type -999 to stop");
scanf("%d",&ele);
while(ele!=-999)
{
new1=(node *)malloc(sizeof(node));
new1->info=ele;
new1->next=NULL;
if(root==NULL)
root=new1;
else
prev->next=new1;
prev=new1;
scanf("%d",&ele);
}
}
void print()
{
list=root;
if(root==NULL)
printf("list is empty");
else
{
printf("\n contents of list");
printf("root->");
while(list!=NULL)
{
printf("%d->",list->info);
list=list->next;
}
printf("NULL");
}
}

void delet()
{
int item;
node *p;
printf("Enter the element to be deleted");
scanf("%d",&item);
if(root->info==item)
{
p=root;
root=root->next;
free(p);
}
else
{
temp=root;
while((item!=temp->info)&&(temp!=NULL))
{
prev=temp;
temp=temp->next;
}
if(item==temp->info)
{
prev->next=temp->next;
free(temp);
}
}
}



void main()
{
int ch;
root=NULL;
do
{
printf("\n 1->creation");
printf("\n 2->deletion");
printf("\n 3->exit");
printf("\n Enter the choice");
scanf("%d",&ch);
switch(ch)
{
case 1: create();
print();
break;
case 2: delet();
print();
break;
case 3: exit(0);
break;
default: printf("Invalid choice");
}
} while(ch!=3);
getch();
}

Wednesday, May 6, 2009

PROGRAM FOR EVELUATING SINGLE LINKED LIST

#include
#include
#include
#define NULL 0
struct slist
{
int info;
struct slist *next;
};
typedef struct slist node;
node *root,*nu,*prev,*list,*start,*temp;
int ele;
void create()
{
printf("Enter -1 to stop\n");
scanf("%d",&ele);
while(ele!=-1)
{
nu=(node*)malloc(sizeof(node));
nu->info=ele;
nu->next=NULL;
if(root==NULL)
{
root=nu;
prev=nu;
}
else
{
prev->next=nu;
prev=nu;
}
scanf("%d",&ele);
}
}
void display()
{
list=root;
if(root==NULL)
printf("The list is empty\n");
else
{
printf("\n Contents of list");
while(list!=NULL)
{
printf("%d,",list->info);
list=list->next;
}
printf("NULL\n");
}
}
void deletion()
{
int item;
node *p;
printf("Enter the element to be deleted\n");
scanf("%d",&item);
if(root->info==item)
{
p=root;
root=root->next;
free(p);
}
else
{
temp=root;
while((item!=temp->info)&&(temp!=NULL))
{
prev=temp;
temp=temp->next;
}
if(item==temp->info)
{
prev->next=temp->next;
free(temp);
}
}
}
void main()
{
int ch;
root=NULL;
clrscr();
do
{
printf("\n Press 1 for entering elements into list\n Press 2 to delete an element from the list\n Press 3 to exit\n");
printf(" Enter your choice\n");
scanf("%d",&ch);
switch(ch)
{
case 1:create();
display();
break;
case 2:deletion();
display();
break;
case 3:exit(0);
break;
}
}while(ch!=3);
}