#include"stdio.h"
#include"conio.h"
#include"stdlib.h"
#include"dos.h"
#include"alloc.h"
void addq(int);
void delq();
void disq();
struct node
{
int d;
struct node *next;
};
struct node *front,*rear,*temp;
void main()
{
int ch,ele;
front=rear=temp=NULL;
clrscr();
do
{
printf("Enter\n1.Insert\n2.Remove\n3.Display\n4.Exit\n\nEnter choice here:");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter element here:");
scanf("%d",&ele);
addq(ele);
break;
case 2:
delq();
break;
case 3:
disq();
break;
case 4:
exit(0);
default:
printf("\007\007Wrong Choice");
sleep(5);
}
}while(ch!=4);
getch();
}
void addq(int no)
{
temp=(struct node*)malloc(sizeof(struct node));
temp->d=no;
temp->next=NULL;
if(front==NULL)
{
front=rear=temp;
}
else
{
rear->next=temp;
rear=rear->next;
}
}
void delq()
{
if(front==NULL)
{
printf("\007 Q empty");
}
else
{
printf("\n element removed is %d",front->d);
front=front->next;
}
}
void disq()
{
if(front==NULL)
{
printf("\007\007 Q empty");
}
else
{
temp=front;
while(temp!=NULL)
{
printf("%d, ",temp->d);
temp=temp->next;
}
}
}
Thursday, May 13, 2010
Saturday, May 8, 2010
C Program For reverse a Number
#include
#include
int rev(int);
void main()
{
int no;
clrscr();
printf("Enter a Number");
scanf("%d",&no);
printf("Reverse Of %d is=%d",no,rev(no));
getch();
}
int rev(int no)
{
int r=0;
while(no!=0)
{
r=(r*10)+(no%10);
no/=10;
}
return(r);
}
#include
int rev(int);
void main()
{
int no;
clrscr();
printf("Enter a Number");
scanf("%d",&no);
printf("Reverse Of %d is=%d",no,rev(no));
getch();
}
int rev(int no)
{
int r=0;
while(no!=0)
{
r=(r*10)+(no%10);
no/=10;
}
return(r);
}
C Programming
/*Simplest Program of Doubly Linked List */
#include
#include
#include
#include
#include
void add();
void del();
void dis();
struct node
{
int d;
struct node *next,*pre;
};
struct node *start,*current,*temp,*p,*t;
int ele;
void main()
{
int ch;
clrscr();
start=current=temp=NULL;
do
{
printf("\nEnter\n1.Insert a Node\n2.Delete a Node\n3.Display a Node\n4.Exit\n\nEnter your choice here:");
scanf("%d",&ch);
switch(ch)
{
case 1:
add();
break;
case 2:
del();
break;
case 3:
dis();
break;
case 4:
exit(0);
default:
printf("\007Wrong Choice\007");
sleep(10);
}
}
while(ch!=4);
getch();
}
void add()
{
int q=1,n;
p=start;
t=p->next;
printf("\nEnter the position to insert the node");
scanf("%d",&n);
temp=(struct node *)malloc(sizeof(struct node));
temp->next=temp->pre=NULL;
printf("\n Enter the Value");
scanf("%d",&temp->d);
if(start==NULL)
{
start=current=temp;
}
else if(n==1)
{
temp->next=start;
start->pre=temp;
start=temp;
}
else
{
while(q<=n-2)
{
p=p->next;
t=t->next;
q++;
}
temp->next=t;
t->pre=temp;
p->next=temp;
temp->pre=p;
if(p==current)
{
current=temp;
}
}
}
void del()
{
int q=1,n;
p=start;
t=start->next;
if(start==NULL)
{
printf("\007\nCannot Del List Empty\n\n");
}
else
{
printf("\nEnter the position to Delete the node");
scanf("%d",&n);
if(n==1)
{
start=start->next;
free(p);
}
else
{
while(q<=n-2)
{
p=p->next;
t=t->next;
q++;
}
p->next=t->next;
t->next->pre=p;
if(t==current)
{
current=p;
}
}
}
}
void dis()
{
if(start==NULL)
{
printf("\nCannot Display,list Empty");
}
else
{
int ch1;
printf("\nEnter\n1.Display from Start\n2.Display from End\n\nEnter your choice here");
scanf("%d",&ch1);
if(ch1==1)
{
temp=start;
printf("\n\nList elements from Start\n\n");
while(temp!=NULL)
{
printf("%d, ",temp->d);
temp=temp->next;
}
}
else if(ch1==2)
{
temp=current;
printf("\n\nList elements from End\n\n");
while(temp!=NULL)
{
printf("%d, ",temp->d);
temp=temp->pre;
}
}
else
{
printf("\007\007Wrong Choice!");
}
}
}
Labels:
C Programming,
DLL,
Doubly,
Doubly Linked,
Doubly Linked List,
Linked List,
Praneet,
Praneet Rastogi,
Program,
Programming
Thursday, April 22, 2010
A message to you all...
This blog is a plateform for those who want to be a programmer or who are programmer...
All the "Suggestions and Comments" to make this platform more useful are invited...
All the "Suggestions and Comments" to make this platform more useful are invited...
Labels:
C Programming,
Praneet,
Praneet Rastogi,
Program,
Programmers,
Programming
Subscribe to:
Posts (Atom)