0% found this document useful (0 votes)
11 views

Applications and Implementation in Programs and Security Based

Applications and implementation in programs and security based things to develop a programmer for the world of Engineering

Uploaded by

nandhinidevi0815
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Applications and Implementation in Programs and Security Based

Applications and implementation in programs and security based things to develop a programmer for the world of Engineering

Uploaded by

nandhinidevi0815
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

LIST OF EXPERIMENTS

EXP.NO Name of The Experiment PAGE NO


1. Implementation of singly linked list.

2. Implementation of doubly linked list.

3. Implementation of Circular Linked List

4. C program to represent a polynomial as a linked list and write


functions for polynomial addition.
5. Implementation on Stack Using Array

6. Implementation on Stack Using Linked List

7. C program to implement stack and use it to convert infix to


postfix expression.
8. C program to find factorial using recursion

9. Implementation on Queue Using Array

10. Implementation on Queue Using Linked List

11. Implementation of FCFS Scheduling

12. Implementation of Round Robin Scheduling

13. Implementation of Binary Tree

14. Write a C program for implementing a binary search tree.

15. Write a C program for implementing operations in AVL trees.

16. Implementation of BFS and DFS Traversal Techniques

17. Write a C program to implement Prim’s algorithm using


priority queues to find MST of an undirected graph.
18. Write a C program for implementing hashing technique with
open addressing.
19. Implementation of Merge Sort

20. Implementation of Quick Sort


EX.NO:1

IMPLEMENTATION OF LIST ADT USING LINKED LIST


AIM:

This program is intended to teach the students about the implementation of List
Abstract Data Type using Linked list.

ALGORITHM:

Step 1: Start
Step 2: Create the list.
Step 3: Get the user choice as input. The user can choose the operations Insertion, deletion,
searching and printing the values of the list.
Step 4: if the user selects the insert operation, read the element and position. Locate the
position and create the node. Then Insert the element.
Step 5: if the user selects the delete operation, read the element. Locate the position and
Delete the node and element.
Step 6: if the user selects the search operation, read the element. Search the List. Return the
position if element is found else return -1.
Step 7: if the user selects the print operation, display the List elements.
Step 8: if the user has to continue go to step3 else go to step 9.
Step 9: Stop.

PROGRAM:

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

struct node
{
int data;
struct node *link;
};
typedef struct node NODE;
NODE *start;

void createemptylist(NODE *start)


{
start->link=NULL;
}

void view(NODE *start)


{
printf("\n");
while(start!=NULL)
{
printf("%d->",start->data);
start=start->link;
}
printf("NULL\n");
}

void insertfirst(int val)


{
NODE *ptr;
ptr=(NODE *)malloc(sizeof(NODE));
ptr->data=val;
if(start==NULL)
ptr->link=NULL;
else
ptr->link=start;
start=ptr;
}

void insertlast(int val)


{
NODE *ptr,*temp;
ptr=(NODE *)malloc(sizeof(NODE));
ptr->data=val;
ptr->link=NULL;
if(start==NULL)
start=ptr;
else
{
temp=start;
while(temp->link!=NULL)
temp=temp->link;
temp->link=ptr;
}
}

void int_at_pos(int val,int loc)


{
NODE *ptr,*temp;
int k;
temp=start;
for(k=1;k<(loc-1);k++)
{
temp=temp->link;
if(temp==NULL)
{
printf("NODE IN THE LIST AS LESS THAN \n");
return;
}
}
ptr=(NODE *)malloc(sizeof(NODE));
ptr->data=val;
ptr->link=temp->link;
temp->link=ptr;
}

void delfirst()
{
NODE *ptr;
if(start==NULL)
return;

else
{
ptr=start;
start=start->link;
free(ptr);
}
}

void dellast()
{
NODE *ptr,*temp;
if(start==NULL)
return;
else if(start->link==NULL)
{
ptr=start;
start=NULL;
free(ptr);
}
else
{
ptr=start;
while(ptr->link!=NULL)
{
ptr=start;
while(ptr->link!=NULL)
{
temp=ptr;
ptr=ptr->link;
}
temp->link=NULL;
free(ptr);
}
}
}

void delspecific(NODE * start)


{
NODE *ptr,*temp;
int val;
printf ("\n ENTER THE ELEMENT TO DELETE \n");
scanf("%d",&val);
ptr=start;

if(start==NULL)
{
printf("EMPTY LIST \n");
return;
}
else
{
temp=ptr;
while(ptr!=NULL)
{
if(ptr->data==val)
{
temp->link=ptr->link;
free(ptr);
return;
}
temp=ptr;
ptr=ptr->link;
}
}
}

void main()
{
int opt, item,pos;
clrscr();
createemptylist(start);
do
{
clrscr();
printf("\n***MENU***");
printf("\n1.INSERT AT BEGINNING");
printf("\n2.INSERT AT END");
printf("\n3.INSERT AT SPECIFIC POSITION");
printf("\n4.DELETE AT BEGINNING");
printf("\n5.DELETE AT END");
printf("\n6.DELETE AT SPECIFIC POSITION");
printf("\n7.VIEW");
printf("\n8.EXIT");
printf("\nCHOOSE YOUR OPTION\n");
scanf("\n%d",&opt);

switch(opt)
{
case 1:
printf("ENTER THE VALUE\n");
scanf("%d",&item);
printf("\nBEFORE INSERTION\n");
view(start);
insertfirst(item);
printf("\nAFTER INSERTION\n");
view(start);
break;
case 2:
printf("ENTER THE VALUE\n");
scanf("%d",&item);
printf("\nBEFORE INSERTION\n");
view(start);
insertlast(item);
printf("\nAFTER INSERTION\n");
view(start);
break;
case 3:
printf("ENTER THE VALUE AND POSITION\n");
scanf("%d%d",&item,&pos);
printf("\nBEFORE INSERTION\n");
view(start);
int_at_pos(item,pos);
printf("\nAFTER INSERTION\n");
view(start);
break;
case 4:
printf("\nBEFORE DELETION\n");
view(start);
delfirst();
printf("\nAFTER DELETION\n");
view(start);
break;
case 5:
printf("\nBEFORE DELETION\n");
view(start);
dellast();
printf("\nAFTER DELETION\n");
view(start);
break;
case 6:
printf("\nBEFORE DELETION\n");
view(start);
delspecific(start);
printf("\nAFTER DELETION\n");
view(start);
break;
case 7:
printf("\nTHE ELEMENTS ARE:\n");
view(start);
break;
case 8:
exit(0);
break;
default:
printf("CHOOSE THE CORRECT OPTION\n");
break;
}

getch();
}

while(opt!=8);
}

OUTPUT:

***MENU***
1.INSERT AT BEGINNING
2.INSERT AT END
3.INSERT AT SPECIFIC POSITION
4.DELETE AT BEGINNING
5.DELETE AT END
6.DELETE AT SPECIFIC POSITION
7.VIEW
8.EXIT
CHOOSE YOUR OPTION
3
ENTER THE VALUE AND POSITION
90
3

BEFORE INSERTION

45->56->56->78->NULL

AFTER INSERTION
45->56->90->56->78->NULL

RESULT:
Thus the program to implement List ADT using linked lists was executed and
verified.

EX.NO:2

IMPLEMENTATION OF DOUBLY LINKED LIST

AIM:

This program is intended to teach the students about the implementation of Doubly
Linked list.

ALGORITHM:

Step 1: Start
Step 2: Create the list.
Step 3: Get the user choice as input. The user can choose the operations Insertion,
deletion, searching and printing the values of the list.
Step 4: if the user selects the insert operation, read the element and position. Locate
the position and create the node. Then Insert the element.
Step 5: if the user selects the delete operation, read the element. Locate the position
and Delete the node and element.
Step 6: if the user selects the search operation, read the element. Search the List.
Return the position if element is found else return -1.
Step 7: if the user selects the print operation, display the List elements.
Step 8: if the user has to continue go to step3 else go to step 9.
Step 9: Stop.

PROGRAM:

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

struct node
{
int data;
struct node *plink;
struct node *nlink;
};
typedef struct node NODE;
NODE *start=NULL;

void createemptylist(NODE *start)


{
start->plink=NULL;
start->nlink=NULL;
}

void view(NODE *start)


{
printf("\n");
while(start!=NULL)
{
printf("%d->",start->data);
start=start->nlink;
}
printf("NULL\n");
}

void insertfirst(int val)


{
NODE *ptr;
ptr=(NODE *)malloc(sizeof(NODE));
ptr->data=val;
if(start==NULL)
{
ptr->nlink=NULL;
ptr->plink=NULL;
}

else
ptr->nlink=start;
ptr->plink=NULL;
start->plink=ptr;
start=ptr;
}

void insertlast(int val)


{
NODE *ptr,*temp;
ptr=(NODE *)malloc(sizeof(NODE));
ptr->data=val;
ptr->nlink=NULL;
ptr->plink=NULL;
if(start==NULL)
start=ptr;
else
{
temp=start;
while(temp->nlink!=NULL)
temp=temp->nlink;
temp->nlink=ptr;
ptr->plink=temp;
}
}

void int_at_pos(int val,int loc)


{
NODE *ptr,*temp;
int k;
temp=start;
if(loc==0)
{
ptr=(NODE *)malloc(sizeof(NODE));
ptr->data=val;
ptr->nlink=temp;
temp->plink=ptr;
start=ptr;

}
else
{

for(k=0;k<(loc-1);k++)
{
temp=temp->nlink;
if(temp==NULL)
{
printf("NODE IN THE LIST AS LESS THAN \n");
return;
}
}

ptr=(NODE *)malloc(sizeof(NODE));
ptr->data=val;
ptr->nlink=temp->nlink;
temp->nlink=ptr;
ptr->plink=temp;
temp->nlink->plink=ptr;
}
}

void delfirst()
{
NODE *ptr;
if(start==NULL)
return;
else
{
ptr=start;
start=start->nlink;
start->plink=NULL;
free(ptr);
}
}

void dellast()
{
NODE *ptr,*temp;
if(start==NULL)
return;
else if(start->nlink==NULL)
{
ptr=start;
start=NULL;
free(ptr);

}
else
{
ptr=start;
while(ptr->nlink!=NULL)
{
ptr=start;
while(ptr->nlink!=NULL)
{
temp=ptr;
ptr=ptr->nlink;
}
temp->nlink=NULL;
free(ptr);
}
}
}

void delspecific(NODE *start)


{
NODE *ptr,*temp;
int val;
printf ("\n ENTER THE ELEMENT TO DELETE \n");
scanf("%d",&val);
ptr=start;
if(start==NULL)
{
printf("EMPTY LIST \n");
return;
}
else
{
temp=ptr;
while(ptr!=NULL)
{
if(ptr->data==val)
{
temp->nlink=ptr->nlink;
ptr->nlink->plink=temp;
free(ptr);
return;
}
temp=ptr;
ptr=ptr->nlink;

}
}
}

void main()
{
int opt, item,pos;
clrscr();
createemptylist(start);
do
{
clrscr();
printf("\n***MENU***");
printf("\n1.INSERT AT BEGINNING");
printf("\n2.INSERT AT END");
printf("\n3.INSERT AT SPECIFIC POSITION");
printf("\n4.DELETE AT BEGINNING");
printf("\n5.DELETE AT END");
printf("\n6.DELETE AT SPECIFIC POSITION");
printf("\n7.VIEW");
printf("\n8.EXIT");
printf("\nCHOOSE YOUR OPTION\n");
scanf("\n%d",&opt);
switch(opt)
{
case 1:
printf("ENTER THE VALUE\n");
scanf("%d",&item);
printf("\nBEFORE INSERTION\n");
view(start);
insertfirst(item);
printf("\nAFTER INSERTION\n");
view(start);
break;
case 2:
printf("ENTER THE VALUE\n");
scanf("%d",&item);
printf("\nBEFORE INSERTION\n");
view(start);
insertlast(item);
printf("\nAFTER INSERTION\n");
view(start);
break;
case 3:
printf("ENTER THE VALUE AND POSITION\n");
scanf("%d%d",&item,&pos);
printf("\nBEFORE INSERTION\n");
view(start);
int_at_pos(item,pos);
printf("\nAFTER INSERTION\n");
view(start);
break;
case 4:
printf("\nBEFORE DELETION\n");
view(start);
delfirst();
printf("\nAFTER DELETION\n");
view(start);
break;
case 5:
printf("\nBEFORE DELETION\n");
view(start);
dellast();
printf("\nAFTER DELETION\n");
view(start);
break;
case 6:
printf("\nBEFORE DELETION\n");
view(start);
delspecific(start);
printf("\nAFTER DELETION\n");
view(start);
break;
case 7:
printf("\nTHE ELEMENTS ARE:\n");
view(start);
break;
case 8:
exit(0);
break;

default:
printf("CHOOSE THE CORRECT OPTION\n");
break;
}
getch();

}
while(opt!=8);
}

OUTPUT:

***MENU***
1.INSERT AT BEGINNING
2.INSERT AT END
3.INSERT AT SPECIFIC POSITION
4.DELETE AT BEGINNING
5.DELETE AT END
6.DELETE AT SPECIFIC POSITION
7.VIEW
8.EXIT
CHOOSE YOUR OPTION
2
ENTER THE VALUE
67

BEFORE INSERTION

34->NULL

AFTER INSERTION

34->67->NULL

***MENU***
1.INSERT AT BEGINNING
2.INSERT AT END
3.INSERT AT SPECIFIC POSITION
4.DELETE AT BEGINNING
5.DELETE AT END
6.DELETE AT SPECIFIC POSITION
7.VIEW
8.EXIT
CHOOSE YOUR OPTION
3
ENTER THE VALUE AND POSITION
56
6

BEFORE INSERTION

34->67->NULL
NODE IN THE LIST AS LESS THAN

AFTER INSERTION

34->67->NULL

RESULT:
Thus the program to implement doubly linked list operations are created executed and
verified.
EX.NO:3

IMPLEMENTATION OF POLYNOMIAL ADT

AIM:
This program is intended to teach the students about the implementation of
polynomial ADT.

ALGORITHM:

Step 1: Start
Step 2: Create the list.
Step 3: Get the two polynomials as input
Step 4: if the powers of two polynomials are same add then add the co-efficient and place it in
the result
Step 5: if the user has to continue go to step3 else go to step 5.
Step 6: Stop.

PROGRAM:

#include<stdio.h>
#include<conio.h>
#include<malloc.h>
struct link
{
int coeff;
int pow;
struct link*next;
};
struct link*poly1=NULL,*poly2=NULL,*poly=NULL;
void create(struct link*node)
{
char ch;
do
{
printf("\n enter coeff:");
scanf("%d",&node->coeff);
printf("\n enter power:");
scanf("%d",&node->pow);
node->next=(struct link*)malloc(sizeof(struct link));
node=node->next;
node->next=NULL;
printf("\n continue(y/n):");
ch=getch();
}
while(ch=='y'||ch=='Y');
}
void display(struct link*node)
{
while(node->next!=NULL)
{
printf("%dx^%d",node->coeff,node->pow);
node=node->next;
if(node->next!=NULL)
printf("+");
}
}
void polyadd(struct link *poly1,struct link*poly2,struct link *poly)
{
while(poly1->next&&poly2->next)
{
if(poly1->pow>poly2->pow)
{
poly->pow=poly1->pow;
poly->coeff=poly1->coeff;
poly1=poly1->next;
}
else if(poly1->pow<poly2->pow)
{
poly->pow=poly2->pow;
poly->coeff=poly2->coeff;
poly2=poly2->next;
}
else
{
poly->pow=poly1->pow;
poly->coeff=poly1->coeff+poly2->coeff;
poly1=poly1->next;
poly2=poly2->next;
}
poly->next=(struct link*)malloc(sizeof(struct link));
poly=poly->next;
poly->next=NULL;
}
while(poly1->next||poly2->next)
{
if(poly1->next)
{
poly->pow=poly1->pow;
poly->coeff=poly1->coeff;
poly1=poly1->next;
}
if(poly2->next)
{
poly->pow=poly2->pow;
poly->coeff=poly2->coeff;
poly2=poly2->next;
}

poly->next=(struct link*)malloc(sizeof(struct link));


poly=poly->next;
poly->next=NULL;
}
}
void main()
{
poly1=(struct link*)malloc(sizeof(struct link));
poly2=(struct link*)malloc(sizeof(struct link));
poly=(struct link*)malloc(sizeof(struct link));
clrscr();
printf("\enter the first polynomial:");
create(poly1);
printf("\n First polynomial:");
display(poly1);
printf("\enter the second polynomial:");
create(poly2);
printf("\n second polynomial:");
display(poly2);
polyadd(poly1,poly2,poly);
printf("\n addition of two polynomial:");
display(poly);
getch();
}

OUTPUT:

enter the first polynomial:


enter coeff:3
enter power:4
continue(y/n):
enter coeff:
6
enter power:2
continue(y/n):
enter coeff:
1
enter power:0
continue(y/n):

First polynomial:3x^4+6x^2+1x^0enter the second polynomial:

enter coeff:4
enter power:2
continue(y/n):
enter coeff:2
enter power:1
continue(y/n):
enter coeff:4
enter power:0
continue(y/n):

second polynomial:4x^2+2x^1+4x^0
addition of two polynomial:3x^4+10x^2+2x^1+5x^0

RESULT:
Thus the C program to implement the polynomial ADT function is created and
executed .

EX.NO:4
INFIX TO POSTFIX CONVERSION
USING ARRAY

AIM:

To create a C program to convert an Infix Expression to postfix Expression using


Arrays.

ALGORITHM:

Step 1: Start
Step 2: Get the infix Expression and read one character at a time.
Step 3: if the character is an operand place in output.
Step 4: If the character is an operator place it in stack. Check the precedence of the operator.
If the new operator has higher precedence pop the operator from the stack and place it in
ouput.
Step 5: Display the postfix Expression
Step 8: If the user chooses to continue go to step 3
Step 9: Stop

PROGRAM:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 25
int s[MAX],top=-1,tos=-1,stack[MAX];
char post[MAX],b[MAX];
int per(char a);
int pre(char a)
{
int b;
switch(a)
{
case '(':
b=0;
break;
case '+':
case '-':
b=1;
break;
case '*':
case '/':
b=2;
break;
case '^':
b=3;
break;
}
return b;
}
int alphanum(char a)
{
return((a>='a'&&a<='z')||(a>='A'&&a<='z'));
}
int opr(char a)
{
int b=0;
switch(a)
{
case '+':
case '-':
case '*':
case '/':
case '^':
b=1;
break;}
return b;}
int intopost()
{
char a,in[25];
int i,ti=-1,tp=-1;
s[++top]='(';
printf("\n enter infix expression");
scanf("%s",&in);
while(in[++ti]!='\0')
{
if(alphanum(in[ti]))
{
post[++tp]=in[ti];
}
else if(opr(in[ti]))
{
while(pre(in[ti])<=pre(s[top]))
post[++tp]=s[top--];
s[++top]=in[ti];
}
else if(in[ti]=='(')
{
s[++top]='(';
}
else if(in[ti]==')')
{
while(s[top]!='(')
post[++tp]=s[top--];
top--;
}
else
{
printf(" invalid expression");
exit(1);
}
}
while(s[top]!='(')
post[++tp]=s[top--];
post[++tp]='\0' ;
printf("\n postfix expression is:%s",post);
for(i=0;i<strlen(post);i++)
b[i]=post[i];
}
int main()
{
char a,post[25];
intopost();
}

OUTPUT:
enter infix expression
(a+b)/(c*d)-e
postfix expression is:
ab+cd*/e-

RESULT:
Thus the program to convert Infix expression to postfix expression using Array was
executed and verified.

You might also like