Applications and Implementation in Programs and Security Based
Applications and Implementation in Programs and Security Based
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 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);
}
}
}
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
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;
else
ptr->nlink=start;
ptr->plink=NULL;
start->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 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
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;
}
OUTPUT:
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:
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.