Announcement:

This is just the beginning of this blog, please don't copy any of my posts.

Showing posts with label C Programming. Show all posts
Showing posts with label C Programming. Show all posts

Thursday, 24 October 2013

[C Program] To Implement Selection Sort

//Program for selection sort
#include<stdio.h>
#include<conio.h>

//Main function
void main()
{
int a[10],n,i,temp,j;
clrscr();
printf("Enter size of array:");
scanf("%d",&n);
printf("\nEnter the elements into array:");
i=0;
while(i<n)
{
scanf(" %d ",&a[i]);
i++;
}
printf("\nEntered array: ");
for(i=0;i<n;i++)
{
printf("%d\t",a[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("\n\nSorted list:   ");
for(i=0;i<n;i++)
{
printf("%d\t",a[i]);
}
getch();
}//end of main

/*Output

Enter size of array:5
                                                                               
Enter the elements into array:54 23 99 11 87

Entered array: 54       23      99      11      87

Sorted list:   11       23      54      87      99 */

[C Program] To Implement and Perform Various Operations on Symmetric Matrix.


//Program for symmetric matrix.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],i,j,m,n,flag=0;
clrscr();
printf("Enter the order for square matrix:");
scanf("%d %d",&m,&n);
printf("\n\nEnter the elements into matrix:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(a[i][j]==a[j][i])
continue;
else
{
flag=1;
goto xyz;
}
}
}

xyz:
if(flag==0)
printf("\nMatrix is Symmetric.");
else
printf("\nMatrix is not symmetric.");
getch();
}

/*Output of Program

Enter the order for square matrix:3 3

Enter the elements into matrix:
1 2 3
2 7 0
3 0 3

Matrix is Symmetric. */

[C Program] for Implementing and performing Various Operations on Stack.


//Program for implementing Stack.

#include<stdio.h>
#include<conio.h>
#define MAX 3

//Defining structure
struct stack
{
int a[MAX];
int top;
};
struct stack s;

//Initializing stack.
void initialize()
{
s.top=-1;
}

//Push function for inserting elements onto stack.
void push(int ele)
{
s.top++;
s.a[s.top]=ele;
}

//Pop function for deleting elements from stack.
int pop()
{
int e;
if(s.top==-1)
{
return(-1);
}
else
{
e=s.a[s.top];
s.top--;
return(e);
}
}

//Displaying the stack.
void display()
{
int i=s.top;
if(s.top==-1)
{
printf("\nStack is empty");
}
else
{
printf("\nElements of stack:\n");
while(i>=0)
{
printf("%d\n",s.a[i]);
i--;
}
}

}

//Main function.
void main()
{
int ch,ele,e;
clrscr();
printf("\n 1.Push 2.Pop 3.Display 4.Exit \n");
initialize();
do
{
printf("\n\nEnter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1: if(s.top==(MAX-1))
printf("\nStack is full");
else
{
printf("\nEnter element to be inserted in the stack:");
scanf("%d",&ele);
push(ele);
}
break;
case 2: e=pop();
if(e>-1)
printf("\nDeleted element:%d",e);
else
printf("\nStack is Empty");
break;
case 3: display();
break;
case 4: exit(0);
}
}while(ch<4);
getch();
}//end of main.

/*Output of Program:

1.Push 2.Pop 3.Display 4.Exit

Enter your choice:1
Enter element to be inserted in the stack:12

Enter your choice:1
Enter element to be inserted in the stack:65

Enter your choice:3
Elements of stack:
65
12

Enter your choice:1
Enter element to be inserted in the stack:34

Enter your choice:3
Elements of stack:
34
65
12

Enter your choice:1
Stack is full

Enter your choice:2
Deleted element:34

Enter your choice:3
Elements of stack:
65
12

Enter your choice:2
Deleted element:65

Enter your choice:2
Deleted element:12

Enter your choice:2
Stack is Empty

Enter your choice:4*/

[C Program] To Perform Various Operations on Queue.



//Program for operations on queue.

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

//Defining the structure.
struct queue
{
int data[3];
int front;
int rear;
}q;

//Initializing the queue.
void initialize()
{
q.rear=-1;
q.front=-1;
}

//Insertion of elements into queue.
void enqueue()
{
if (q.rear==2)
{
printf("\n Queue is full");
}
else
{
int ele;
printf("\nEnter the element:");
scanf("%d",&ele);
if(q.front==-1)
{
q.front++;
}
q.rear++;
q.data[q.rear]=ele;
}
}

// Deletion of elements from queue.
int dequeue()
{
int v;
if(q.front==-1||q.front>q.rear)
{
printf("\n Queue is empty:");
return(-1);
}
else
{
v=q.data[q.front];
q.front++;
return(v);
}
}

//Displaying the queue.
void display()
{
int i=q.front;
if(q.front>q.rear)
printf("\n Queue is empty:");
else
{
while(i<=q.rear)
{
printf("  %d",q.data[i]);
i++;
}
}
}

//Main Function
void main()
{
int i,data[3],ch,v;
clrscr();
initialize();
printf("\n 1.Insert 2.Delete 3.Display 4.Exit:");
do
{
printf("\n\nEnter the choice:");
scanf("%d",&ch);
switch(ch)
{

case 1: enqueue();
break;
case 2: v=dequeue();
   if(v==-1)
   break;
   printf("Deleted element:%d",v);
   break;
case 3: display();
   break;
case 4:  exit(0);
}
}while(ch<4);
getch();
}
//end of main

/*Output of Program:

 1.Insert 2.Delete 3.Display 4.Exit:

Enter the choice:1
Enter the element:10

Enter the choice:1
Enter the element:20

Enter the choice:1
Enter the element:30

Enter the choice:1
Queue is full

Enter the choice:3
Elements in queue:  10  20  30

Enter the choice:2
Deleted element:10

Enter the choice:3
Elements in queue:  20  30

Enter the choice:1
Queue is full

Enter the choice:2
Deleted element:20

Enter the choice:2
Deleted element:30

Enter the choice:2
Queue is empty

Enter the choice:3
Queue is empty

Enter the choice:4*/

[C Program] to Implement Pointer to Function

//Program to implement pointer to function

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

void copy(int arr[],int b)
{
int i;
for(i=0;i<b;i++)
{
if(i%2==0)
arr[i]=0;
}
}
void main()
{
int j,a[10],n;
void(*ptr)(int[],int);
clrscr();
ptr=&copy;
printf("Enter the size of an array:");
scanf("%d",&n);
printf("\n\nEnter %d elements into array:",n);
for(j=0;j<n;j++)
{
scanf("%d",&a[j]);
}
printf("\n\nEntered array: ");
for(j=0;j<n;j++)
{
printf("%d\t",a[j]);
}
ptr(a,n);
printf("\n\nUpdated array:  ");
for(j=0;j<n;j++)
{
printf("%d\t",a[j]);
}
getch();
}

/*Output of Program

Enter the size of an array:5
                                                                     
Enter 5 elements into array:12 23 34 45 67                                    
                                                                               
Entered array: 12       23      34      45      67                            
                                                                               
Updated array:  0       23      0       45      0 */

[C Program] to Pass Pointer to the Function


//Program to pass pointer to the function.
#include<stdio.h>
#include<conio.h>

//Declaring the swap function.
void swap(int *ptr,int *ptr1);

//Main function.
void main()
{
int a,b;
clrscr();
printf("Enter value of a:");
scanf("%d",&a);
printf("\nEnter value of b:");
scanf("%d",&b);
swap(&a,&b);
printf("\nAfter swapping, values of a & b:%d & %d respectively\n",a,b);
getch();
}//end of main

//Definition of swap function.
void swap(int *ptr,int *ptr1)
{
int temp;
temp=*ptr;
*ptr=*ptr1;
*ptr1=temp;
}

/*Output of Program

Enter value of a:67

Enter value of b:89

After swapping, values of a & b:89 & 67 respectively */                                   

[C Program] To Perform Insertion Sort

//Program for insertion sort

#include<stdio.h>
#include<conio.h>
void insertion(int [], int size);
int main()
{
int a[30],i,size;
clrscr();
printf("Enter total no. of elements : ");
scanf("%d",&size);
printf("Enter elements:");
for(i=0; i<size; i++)
{

scanf("%d",&a[i]);
}
insertion(a,size);
printf("\nSorted elements:\n\n");
for(i=0; i<size; i++)
printf(" %d",a[i]);
getch();
return 0;
}

void insertion(int a[], int n)
{
int i,j,tmp;
for(i=0;i<n;i++)
{

for(j=i-1;j>-1;j--)
{

if(a[j]>a[j+1])
{
tmp=a[j];
a[j]=a[j+1];
a[j+1]=tmp;
}
else
break;
}
}
}

/*Output of Program:

Enter the array size:6

Enter the elements into array:31  56  80  111  65  71

Entered array:  31      56      80      111     65      71

Sorted list:       31      56      65      71      80      111*/

[C Program] To Perform Multiplication of Two Matrices

//Program for multiplication of two matrix.
#include<stdio.h>
#include<conio.h>

//Main Function
void main()
{
int i,j,k,n,a[10][10],b[10][10],c[10][10];
clrscr();

printf("Enter the order for matrix:");
scanf("%d",&n);

//Defining 1st matrix
printf("\nEnter elements for 1st matrix: \n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}

//Defining 2nd matrix
printf("Enter elements for 2nd matrix:\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&b[i][j]);
}
}

//Initializing the 3rd i.e resultant matrix
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
c[i][j]=0;
}
}

//Multiplication of two matrices
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
for(k=0;k<n;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}

//Printing the resultant matrix
printf("Multiplication of 2 matrices:\n\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("\t %d",c[i][j]);
}
printf("\n\n");
}
getch();
}//end of main.

/*Output

Enter the order for matrix:2
                                                                               
Enter elements for 1st matrix:                                                
1 3                                                                            
4 2                                                                            
Enter elements for 2nd matrix:                                                
6 4                                                                            
1 3                                                                            
Multiplication of 2 matrices:                                                  
                                                                               
          9       13                                                            
                                                                               
       26      22
 */

[C Program] to Implement Linear Search


//Program for Linear Search
#include<stdio.h>
#include<conio.h>

//Main Function
void main()
{
int a[5],i,n,key,flag=0;
clrscr();
printf("\nEnter the array size:");
scanf("%d",&n);
printf("\nEnter the elements into array:\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("\nEnter the element to be searched:");
scanf("%d",&key);
for(i=0;i<n;i++)
{
if(a[i]==key)
{
printf("\nElement is present in the list at %d location.",i);
flag=1;
}
}
if(flag==0)
{
printf("\nElement is not present in the list.");
}
getch();
}//end of main

/*Output

Enter the array size:5                                                        
                                                                               
Enter the elements into array:                                                
1 2 6 4 8                                                                      
                                                                               
Enter the element to be searched:2                                            
                                                                               
Element is present in the list at 1 location. */

[C Program] for Implementation of Insertion Sort

//Program for insertion sort

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

//Insertion fuction
void insertion(int a[10],int n)
{
int temp,i,j,k;
for(i=0;i<n;i++)
{
for(j=0;j<i;j++)
{
if(a[j]>a[i])
{
temp=a[j];
a[j]=a[i];
for(k=i;k>j;k--)
{
a[k]=a[k-1];
}
a[k+1]=temp;
}
}
}
}

//Main function
void main()
{
int a[10],i,n;
clrscr();
printf("Enter the array size:");
scanf("%d",&n);
printf("\nEnter the elements into array:");
for(i=0;i<n;i++)
{
scanf("%d\t",&a[i]);
}
printf("\nEntered array:  ");
for(i=0;i<n;i++)
{
printf("%d\t",a[i]);
}
insertion(a,n);
printf("\n\nSorted list:    ");
for(i=0;i<n;i++)
{
printf("%d\t",a[i]);
}
getch();
}
//end of main

/*Output

Enter the array size:6
                                                                             
Enter the elements into array:31 56 80 111 65 71

Entered array:  31      56      80      111     65      71                    
                                                                             
Sorted list:    31      56      65      71      80      111 */

[C Program] to implement Hash Table

//Program to implement hash table.
#include<stdio.h>
#include<conio.h>
int hash[11][2] ;
void main()
{
int k,m=7,i,j,ch,v,h;
clrscr();
printf ("1.Insert 2.Retrive 3.Display 4.Exit") ;
do
{
printf("\n\nEnter choice:");
scanf("%d",&ch);
switch (ch)
{
case 1: printf("\nEnter key & value:");
scanf("%d %d",&k,&v);
h=k%m;
while(hash[h][1]!=0)
{
h=(h+1)%m;
}
hash[h][0]=k;
hash[h][1]=v;
break;
case 2: printf("\n\nEnter key:");
scanf("%d",&k);
h=k%m;
printf("\n\nValue:%d",hash[h][1]) ;
break;
case 3: printf("\nYour Hash Table:\n\n");
for(i=0;i<10;i++)
{
for(j=0;j<2;j++)
{
printf("%d\t",hash[i][j]);
}
printf("\n\n");
}
printf("\n");
break;
case 4: exit(0);
}
}while(ch<5);
getch();
}

/*Output:

1.Insert 2.Retrive 3.Display 4.Exit

Enter choice:1

Enter key & value:8 101

Enter choice:1

Enter key & value:1 103

Enter choice:1

Enter key & value:10 105

Enter choice:1

Enter key & value:13 107

Enter choice:1

Enter key & value:9 108

Enter choice:3

Your Hash Table:

0       0

8       101

1       103

10      105

9       108

0       0

13      107

0       0

0       0

0       0

Enter choice:2

Enter key:1

Value:101

Enter choice:4*/

[C Program] for Implementing Doubly Linear Linked List


//Program for implementing Doubly Linear Linked List.
#include<stdio.h>
#include<conio.h>
#include<alloc.h>

//Structure definition
typedef struct dll
{
int data;
struct dll *next,*prev;
}node;

node *head,*t,*temp;

//Creating head node
node *create()
{
node *head;
head=(node *)malloc(sizeof(node));
head->data=-1;
head->next=NULL;
head->prev=NULL;
printf("\nHead node is created...\n");
return(head);
}

//Inserting nodes into doubly linked list
void insert(node *head)
{
node *temp,*t;
int v;
temp=(node *)malloc(sizeof(node));
printf("\n\nEnter data for new node:");
scanf("%d",&v);
temp->data=v;
temp->next=NULL;
temp->prev=NULL;
t=head;
while(t->next!=NULL)
{
t=t->next;
}
t->next=temp;
temp->prev=t;
}

//Displaying the doubly linked list
void display(node *head)
{
node *temp;
temp=head->next;
while(temp->next!=NULL)
{
printf("%d\t",temp->data);
temp=temp->next;
}
printf("%d\t",temp->data);
}

//Delition of node from doubly linked list
void Delete(node *head)
{
int c;
node *temp,*t;
temp=head;
printf("\n\nEnter the data to be deleted from list:");
scanf("%d",&c);
while(temp->next!=NULL)
{
if(temp->next->data==c)
{
t=temp->next;
temp->next=t->next;
t->next->prev=temp;
free(t);
}
else
{
temp=temp->next;
}
}
}

//Reversing the doubly linked list
void reverse(node *head)
{
int a[10],i=0;
node *temp;
temp=head;
while(temp->next!=NULL)
{
temp=temp->next;
}
while(temp->prev!=NULL)
{
printf("%d\t",temp->data);
temp=temp->prev;
}
}

//Reverting the doubly linked list
void revert(node *head)
{
node *p,*q,*r,*t;
p=head->next;
t=head;
q=NULL;
while(p!=NULL)
{
r=q;
q=p;
p=p->next;
q->next=r;
p->prev=r;
q->prev=t;
}
t->next=q;
display(head);
}

//Main function
void main()
{
int ch;
node *head;
clrscr();
printf("*******Doubly Linear Linked List*******");
do
{
printf("\n\nMenues:");
printf("\n\n1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit");
printf("\n\nEnter Your Choice:");
scanf("%d",&ch);
switch(ch)
{
case 1: head=create();
break;
case 2: insert(head);
break;
case 3: Delete(head);
break;
case 4: reverse(head);
break;
case 5: revert(head);
break;
case 6: display(head);
break;
case 7: exit(0);
}
}while(ch<7);
getch();
}

/* Output of Program:

*******Doubly Linear Linked List*******

Menues:

1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit

Enter Your Choice:1

Head node is created...

Menues:

1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit

Enter Your Choice:2

Enter data for new node:11

Menues:

1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit

Enter Your Choice:2

Enter data for new node:22

Menues:

1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit

Enter Your Choice:2

Enter data for new node:33

Menues:

1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit

Enter Your Choice:2

Enter data for new node:44

Menues:

1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit

Enter Your Choice:2

Enter data for new node:55

Menues:

1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit

Enter Your Choice:2

Enter data for new node:66

Menues:

1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit

Enter Your Choice:6
11      22      33      44      55      66


Menues:

1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit

Enter Your Choice:3

Enter the data to be deleted from list:44

Menues:

1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit

Enter Your Choice:6
11      22      33      55      66

Menues:

1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit

Enter Your Choice:4
66      55      33      22      11

Menues:

1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit

Enter Your Choice:6
11      22      33      55      66

Menues:

1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit

Enter Your Choice:5
66      55      33      22      11

Menues:

1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit

Enter Your Choice:6
66      55      33      22      11

Menues:

1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit

Enter Your Choice:3

Enter the data to be deleted from list:66

Menues:

1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit

Enter Your Choice:6
55      33      22      11

Menues:

1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit

Enter Your Choice:7*/

[C Program] for implementing Circular queue.

//Program for implementing Circular queue.

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

//Defining the structure.
struct cque
{
int data[3];
int front;
int rear;
}q;
int size=3;

//Initializing the circular queue.
void initialize()
{
q.rear=-1;
q.front=-1;
}

//Enqueue Function for inserting elements into circular queue.
void cque_add()
{
int p;
p=cque_full();
if(p)
{
printf("\n Que is Full");
}
else
{        int ele;
printf("\n Enter the element:");
      scanf("%d",&ele);
if(q.front==-1)
{
q.front=0;
}
q.rear=(q.rear+1)%size;
q.data[q.rear]=ele;
}
}

//Dequeue Function for deleting elements from circular queue.
int cque_delete()
{
int v,x;
x=cque_empty();
if(x)
{
printf("\n Que is Empty.");
return(-1);
}
else
{
v=q.data[q.front];
    q.data[q.front]=-1;
if(q.front==q.rear)
{
q.front=-1;
q.rear=-1;
}
else
{
q.front=(q.front+1)%size;
}
return(v);
}
}

//Queue empty condition.
int cque_empty()
{
if(q.front==-1)
    return(1);
else
return(0);
}

//Queue full condition.
int cque_full()
{
if(q.front==(q.rear+1)%size)
    return(1);
else
return(0);
}

//Display Function for displaying circular queue.
void display()
{
int n,i=q.front;
n=cque_empty();
if(n)
printf("\n Que is Empty");
else
{
printf("\nThe elements in queue:");
do
{    
if(q.data[i]!=-1)
printf("  %d ",q.data[i]);
i=(i+1)%size;
}while(i!=q.front);
   }

}

//Main Function
void main()
{
int ch,v,ele,data[3];
clrscr();
initialize();
printf("1.Insert 2.Delete 3.Display 4.Exit\n");
do
{
printf("\n\n Enter the choice:");
scanf("%d",&ch);
switch(ch)
{
case 1: cque_add();
break;
case 2: v=cque_delete();
if(v!=-1)
printf("\nDeleted element:%d",v);
break;
case 3: display();
break;
case 4: exit(0);
}
}while(ch<4);
getch();
}//end of main

/*Output of Program:

1.Insert 2.Delete 3.Display 4.Exit

 Enter the choice:1
Enter the element:12

Enter the choice:1
Enter the element:24

Enter the choice:1
Enter the element:45

Enter the choice:1
Que is Full          
                                                     
Enter the choice:3
The elements in queue:  12   24   45    

Enter the choice:2      
Deleted element:12

Enter the choice:3                                                          
The elements in queue:  24   45    
                                         
Enter the choice:1                                    
Enter the element:87

Enter the choice:3
The elements in queue:  24   45   87

Enter the choice:2
Deleted element:24

Enter the choice:2
Deleted element:45

Enter the choice:2
Deleted element:87

Enter the choice:2
Que is Empty.

Enter the choice:3
Que is Empty

Enter the choice:4*/

[C Program] for Implementing Singly Circular Linked List.


//Program for implementing Singly Circular Linked List.

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

//Structure definition
typedef struct cll
{
int data;
struct cll *next;
}node;

node *head,*t,*temp;

//Creating head node
node * create()
{
node *head;
head=(node *)malloc(sizeof(node));
head->data=-1;
head->next=head;
printf("\nHead node is created...\n");
return(head);
}

//Inserting nodes into circular linked list
void insert(node *head)
{
node *temp,*t;
int v;
temp=(node *)malloc(sizeof(node));
printf("\n\nEnter data for new node:");
scanf("%d",&v);
temp->data=v;
temp->next=head;
t=head;
while(t->next!=head)
{
t=t->next;
}
t->next=temp;
}

//Displaying the circular linked list
void display(node *head)
{
node *temp;
temp=head->next;
while(temp->next!=head)
{
printf("%d\t",temp->data);
temp=temp->next;
}
printf("%d\t",temp->data);
}

//Delition of node from circular linked list
void Delete(node *head)
{
int c;
node *temp,*t;
temp=head;
printf("\n\nEnter the data to be deleted from list:");
scanf("%d",&c);
while(temp->next!=head)
{
if(temp->next->data==c)
{
t=temp->next;
temp->next=t->next;
free(t);
}
else
{
temp=temp->next;
}
}
}

//Reversing the circular linked list
void reverse(node *head)
{
int a[10],i=0;
node *temp;
temp=head;
while(temp->next!=head)
{
a[i]=temp->next->data;
i++;
temp=temp->next;
}
a[i]=temp->data;
for(i=i-1;i>=0;i--)
{
printf("%d\t",a[i]);
}
}

//Reverting the circular linked list
void revert(node *head)
{
node *p,*q,*r;
p=head->next;
q=head;
while(p!=head)
{
r=q;
q=p;
p=p->next;
q->next=r;
}
head->next=q;
display(head);
}

//Main function
void main()
{
int ch;
node *head;
clrscr();
printf("*******Singly Circular Linked List*******");
do
{
printf("\n\nMenues:");
printf("\n\n1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit");
printf("\n\nEnter Youe Choice:");
scanf("%d",&ch);
switch(ch)
{
case 1: head=create();
break;
case 2: insert(head);
break;
case 3: Delete(head);
break;
case 4: reverse(head);
break;
case 5: revert(head);
break;
case 6: display(head);
break;
case 7: exit(0);
}
}while(ch<7);
getch();
}


/* Output of Program:

*******Singly Circular Linked List*******

Menues:

1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit

Enter Youe Choice:1

Head node is created...

Menues:

1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit

Enter Youe Choice:2

Enter data for new node:11

Menues:

1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit

Enter Youe Choice:2

Enter data for new node:22

Menues:

1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit

Enter Youe Choice:2

Enter data for new node:33

Menues:

1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit

Enter Youe Choice:6
11      22      33

Menues:

1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit

Enter Youe Choice:2

Enter data for new node:44

Menues:

1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit

Enter Youe Choice:2

Enter data for new node:55

Menues:

1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit

Enter Youe Choice:2

Enter data for new node:66

Menues:

1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit

Enter Youe Choice:6
11      22      33      44      55      66

Menues:

1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit

Enter Youe Choice:3

Enter the data to be deleted from list:33

Menues:

1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit

Enter Youe Choice:6
11      22      44      55      66

Menues:

1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit

Enter Youe Choice:4
66      55      44      22      11

Menues:

1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit

Enter Youe Choice:5
66      55      44      22      11

Menues:

1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit

Enter Youe Choice:6
66      55      44      22      11

Menues:

1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit

Enter Youe Choice:3

Enter the data to be deleted from list:55

Menues:

1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit

Enter Youe Choice:6
66      44      22      11

Menues:

1.Create 2.Insert 3.Delete 4.Reverse 5.Revert 6.Display 7.Exit

Enter Youe Choice:7 */

[C Program] To Implement Program for Bubble sort

//Program for Bubble sort

#include<stdio.h>
#include<conio.h>
//Main function
void main()
{
int i,a[10],n,j,temp;
clrscr();
printf("\nEnter the size of array:");
scanf("%d",&n);
printf("\n\nEnter the elements into array:");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("\nEntered array:  ");
for(i=0;i<n;i++)
{
printf("%d\t",a[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(a[j]>a[i])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("\n\nSorted list:    ");
for(i=0;i<n;i++)
{
printf("%d\t",a[i]);
}
getch();
}//end of main

/*Output

Enter the size of array:7

Enter the elements into array:12 88 5 100 32 77 50

Entered array:  12      88      5       100     32      77      50

Sorted list:    5       12      32      50      77      88      100 */

Copyright @ 2013 Pune University Bachelor of Engineering . Designed by Pankaj Gaikar | Love for The Tricks Machine