Professional Documents
Culture Documents
SRIPERUMBUDUR.
LAB MANUAL
CS16361 PROGRAMMING AND DATA STRUCTURES
LABORATORY
YEAR : II Yr B.E (Common to EC and EE)
SEMESTER : 3
Prepared by Approved by
Signature
Name Ms S.Poorani Dr R.Anitha
Designation Assistant Professor /CS HOD/CS
D
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
AIM:
ALGORITHM:
Start.
Accept the number, n
Find the sum of factors of n and store in Sum
If sum equals to n then n is perfect number else n is not perfect number.
Stop
RESULT:
Thus a C program is implemented for perfect number verification
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
AIM:
ALGORITHM:
Start.
Read radius of circle r, side of square a, length l and breadth b of rectangle, height h and base
bas of triangle.
Call the function cir(r), squ(a), rec(l,b), tri(h,bas).
Print the areas.
Stop.
Function cir(r)
Start
Return 3.14*r*r.
Stop.
Function squ(a)
Start
Return a*a.
Stop.
Function rec(l,b)
Start
Return l*b.
Stop.
Function tri(h,bas)
Start
Return o.5*h*bas.
Stop.
Enter the radius if circle, side of square, length and breadth of rectangle , height and base of
triangle respectively 123434
Area of circle=3.140000
Area of square=4
Area of rectangle=12
Area of triangle=6.00000
RESULT:
Hence area of four geometric shape is found using functions.
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
AIM:
To design a calculator using switch statement
ALGORITHM:
Start.
Get two operands and the operator character from the user.
If the operator is ‘+‘ then add the operands.
If the operator is ‘-‘ then subtract one operand from the other operand.
If the operator is ‘*‘ then multiply the operands
If the operator is ‘/‘ then divide one operand by the other.
If the entered character is not matching any of these above four operators then print the
default statement ―Enter the correct operator‖
Stop.
RESULT:
Hence a calculator is designed using switch statement.
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
AIM:
To find numbers divisible number by 5
ALGORITHM:
Start
Read the value of n.
Initialize variable i to 1
Repeat loop n times
if i%5=0 print i , else print “ ”
Stop
RESULT:
LAB MANUAL
AIM:
ALGORITHM:
Start.
Accept the number, N
Assign max to 0.
Extract digit by digit and sum the digits in a variable sum.
Find the reverse of the number N by extracting the last digit, multiplying by 10 and reducing
the number and store the reverse number in a variable rev
Extract digit by digit and compare it with max and store the largest digit in max.
Print sum, rev, max.
Stop
RESULT:
Hence sum of digits, reverse of number and largest of digits is found.
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
AIM:
To find Armstrong number from 1 to 1000
ALGORITHM:
Start
Make a loop Declare variable i=1 Increment i by 1 up to 1000
Find the sum of the cube of the individual digits of the number i and store in SUM1.
If SUM1 equals to i then print I else print “ ”
Stop
RESULT:
LAB MANUAL
AIM:
To find ‘n’ prime numbers
ALGORITHM:
Start
Read the value of n.
To print the value 2 on screen.
Make a loop Declare variable i=3 Increment i by 1 upto n
Using another loop Declare variable j=2 From j=2 to j<i; divide i by j If i % j = = 0 then
print the number else print (― ―)
Stop
RESULT:
LAB MANUAL
AIM:
To find largest element in a array.
ALGORITHM:
1.Start
2.Read the value of n,a[n].
3.Call the function lar(a[n],n).
4.Print max.
5.Stop.
Function lar(a[10],n)
1.Start.
2. Make a loop Declare variable i=0 Increment i by 1 upto n.
3.if max is less than a[i],store a[i] in max.
4.Return max.
5.Stop.
RESULT:
LAB MANUAL
AIM:
To perform matrix addition.
ALGORITHM:
1.Start.
2. Accept the number of rows and columns (m,n , p,q) for the 2 matrices a & b.
3. If m!=p && n!=q then write “Matrix addition is not possible.” goto Step .
4. Accept the elements of the 2 matrices.
5.call the function add(a,b,m,n)
6. Stop
Function add( a[10][10],b[10][10],m,n)
1.Start
2. Repeat Steps 5 to 8 for i = 1 to m.
3. Repeat Steps 6 to 7 for j = 1 to q.
4. c[i][j]=a[i][j]+b[i][j]
5.Continue looping for j.
6.Continue looping for i.
7. Display “ The resultant matrix is”
8. Display the matrix c.
9.stop.
LAB MANUAL
RESULT:
Hence sum of matrix is found.
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
AIM:
To perform matrix multiplication.
ALGORITHM:
1.Start.
2.Accept the number of rows and columns (m,n , p,q) for the 2 matrices a & b.
3.If n<>p then write “Matrix multiplication is not possible.” And goto Step 6.
4..Accept the elements of the 2 matrices.
5.call te function mul(a,b,n,m1,n1)
6.Stop.
Function mul
1.start
2.Repeat Steps 6 to 11 for i = 1 to m.
3.Repeat Steps 7 to 10 for j = 1 to q.
4.Repeat Steps 8 & 9 for k = 1 to n.
5.c[i][j]=c[i][j]+a[i][k]* b[k][j].
6.Continue looping for k.
7.Continue looping for j.
8.Continue looping for i.
9.Display “ The resultant matrix is”
10.Display the matrix c.
LAB MANUAL
RESULT:
LAB MANUAL
AIM:
ALGORITHM:
1.Start.
2. Accept the number of rows and columns (m,n ) of matrices a .
3. Accept the elements of the 2 matrices.
4.call the function tro(a,m,n)
6. Stop
Function tra( a[10][10],m,n)
1.Start
2. Repeat Steps 5 to 8 for i = 1 to m.
3. Repeat Steps 6 to 7 for j = 1 to q.
4. c[i][j]=a[i][j]
5.Continue looping for j.
6.Continue looping for i.
7. Display “ The resultant matrix is”
8. Display the matrix c.
9.stop
SAMPLE INPUT OUTPUT:
RESULT:
Hence matrix transpose is found.
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
STRINGS
AIM:
To find number of digits, vowels, consonants and white spaces in a given line.
ALGORITHM:
Start.
Read a line ‘str’.
Initialise the variables d,c,v,s to 0.
Call the function len(str) and store the value in l.
for i=0 to l-1 repeat step 6 to 8.
Store str[i] to ch.
Call the function non(ch).
If k=0 increment s by one. else if k=1 increment d by 1.
else if k=2 increment v by 1 else increment c by 1.
Print s,d,v,c.
Stop.
function len
Start.
Assign 0 to len,I to 0.
Assign first character to ch .
Repeat step 5 and step 6 while ch not equal to '\0'.
Increment len by 1 and I by 1.
Assign ch to str[i] character.
Return len.
Stop.
function non
Start.
2: if ch is “ “ , return 0;;else if ch is a digit return 1;E
Else if ch is a vovel return 2.
Stop
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
RESULT:
Hence number of digits, consonants, vowels and white spaces in line is determined.
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
AIM:
To verify whether the given string is a palindrome or not.
ALGORITHM:
Start.
Read string ‘str’.
Call the function len.
for i=0 to len-1 do
Swap the ith and (n-1-i)th character and store it on a another string ‘str1’.
if the function cmp returns 1 else go to step 8.
Print it is palindrome.
Print it is not palindrome.
Stop
function len
Start.
Assign 0 to len,I to 0.
Assign first character to ch .
Repeat step 5 and step 6 while ch not equal to '\0'.
Increment len by 1 and I by 1.
Assign ch to str[i] character.
Return len.
Stop.
function cmp
Start.
Assign first character of str and str1 to ch and ch1 respectively.
Assign flag to 1
for i=0 to l-1 repeat step 5 to 7
if not equal to ch1
Set flag to 0
Assign ch and ch1 to str[i] and str1 character respectively.
Return flag.
Stop
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
enter a string-
good
good is not palindrome
RESULT:
Hence the given string is verified as a palindrome or not.
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
AIM:
To perform string reverse without using library functions of C.
ALGORITHM:
Start.
Read string str
Call the function len
for i=0 to len-1 do
Swap the ith and (n-1-i)th character
Print reversed string str
Stop
function len
Start.
Assign 0 to len,I to 0.
Assign first character to ch .
Repeat step 5 and step 6 while ch not equal to '\0'.
Increment len by 1 and I by 1.
Assign ch to str[i] character.
Return len.
Stop
RESULT:
Hence string reverse without using library functions of C is performed.
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
AIM:
To find a substring in a given string.
ALGORITHM:
Start
Read string ‘str’ and the sub sring’str1’
Call the function len(str) and store the value in l
Call the function len(str1) and store the value in l1
for i=0 to len-1 repeat
Assign k=0
for j=0 to l1-1 repeat
Store the l1 consecutive characters in str1 ftom the kth position of str
Increment k by 1.
if the called function cmp return 1
Print sub string is present; else print sub string is not present.
Stop.
function len
Start.
Assign 0 to len,I to 0.
Assign first character to ch .
Repeat step 5 and step 6 while ch not equal to '\0'.
Increment len by 1 and I by 1.
Assign ch to str[i] character.
Return len.
Stop.
function cmp
Start.
Assign first character of str and str1 to ch and ch1 respectively.
Assign flag to 1
for i=0 to l-1 repeat step 5 to 7
if not equal to ch1
Set flag to 0
Assign ch and ch1 to str[i] and str1 character respectively.
Return flag.
Stop
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
RESULT:
Hence a substring in a string is found.
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
ALGORITHM:
Start
Read string str
Call the function len
for i=0 to len-1 do
Print the called function up(str[i])
Stop
function len
Start.
Assign 0 to len,I to 0.
Assign first character to ch .
Repeat step 5 and step 6 while ch not equal to '\0'.
Increment len by 1 and I by 1.
Assign ch to str[i] character.
Return len.
Stop.
function up
Start
if ch>=65 and ch<=91 return ch; else return ch-32.
Stop.
RESULT:
Hence the given string is converted to its upper case without using library functions of C.
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
AIM:
ALGORITHM:
Start
Accept the number of names, n, in the array.
for i = 0 to n-1 do step 4
Read a(i)
for i = 0 to n-1 do steps 6 to 10
for j = 0 to n-i-1 steps 7 to 10
if (strcmp(a(j),a(j+1)) >0) do steps 8 to 10
strcpy(temp, a(j))
strcpy(a(j) , a(j+1))
strcpy(a(j+1) , temp)
for i = 0 to n-1 do step 12
Write a(i)
Stop
bangaolre
delhi
mumbai
RESULT:
Hence the n strings are sorted alphabetically.
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
AIM:
To print the Fibonacci series using functions and pointers.
ALGORITHM:
Start.
Accept the limit ,n
Call the function by the reference of n as , fib(&n)
Print the series
Stop
function fib(*n)
Start
if *n==0 return 0
else if n==1 return 1
else do
store the value of *n-1 and *n-2 in i and k
f(i)=fib(&i)+fib(&k)
5. return f(i)
6. Stop
Fibonacci series
0 1 1 2 3 5 8 13
RESULT:
Hence Fibonacci series using functions and pointers is printed.
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
AIM:
To compute factorial of the given number recursively using functions and pointers.
ALGORITHM:
Start
Enter the number,n for which the factorial has to be calculated
Call the function by passing the references of n, fact(&n)
Print the factorial of the number
Stop
function fact(*n)
Start
if *n==1 return 1
else do step 4,5
Store the value of *n-1 in ‘i’
Compute f=(i+1)*fact(&i)
Return f
Stop
enter a number : 4
factorial of number 4 is 24
RESULT:
Hence factorial of the given number is computed recursively using functions and pointers.
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
AIM:
To perform arithmetic operations using functions and pointers.
ALGORITHM:
Start.
Read two numbers.
Call the function by the reference of a and b as , add(&a, &b) , sub(&a, &b) , mul(&a, &b),
div(&a, &b).
Print the values.
Stop.
LAB MANUAL
RESULT:
Hence the arithmetic operations is performed using functions and pointers.
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
AIM:
To print the transpose of a matrix using dynamic memory allocation.
ALGORITHM:
1.Start.
2. Accept the number of rows and columns (man ) of matrices a .
3.create the dynamic memory of the matrix a and b where b is the transpose of a
4. Accept the elements of the matrices a.
5.Repeat Steps 6 to 7 for i = 1 to n.
6. Repeat Steps 7 for j = 1 to m.
7. assign the *(a+j*n+i) to *(b+i*m+j)
8.print the elements of matrix b
9.Stop
RESULT:
Hence the transpose of a matrix is printed using dynamic memory allocation.
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
AIM:
ALGORITHM:
Declare the functions create, insert, delete, display, islast, find prev.
If choice equal to 1 then read the number and position. Call insert ()
LAB MANUAL
Traverse the pointer p through the list till the previous position
Traverse through the list using pointer p till the last node and check for the number no
If the number is found print the position else print “element not found ”
Traverse through the list and find whether the given number is last or not
Traverse through the list using pointer p till the previous node to the number no
LAB MANUAL
Assign p = l->next
If the number is in first position then assign l = p->next and free p and return
Assign temp=p->next
void print ()
Assign p = l->next
Traverse through the list using the pointer and print the list
creation
12
43
56
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
09
1.INSERT
2.DELETE
3.SEARCH
4.DISPLAY
5.EXIT
INSERTION
1.INSERT
2.DELETE
3.SEARCH
4.DISPLAY
5.EXIT
LAB MANUAL
1.INSERT
2.DELETE
3.SEARCH
4.DISPLAY
5.EXIT
DISPLAY
35 12 100 43 56
1.INSERT
2.DELETE
3.SEARCH
4.DISPLAY
5.EXIT
SEARCH
element found!!
position is 4
1.INSERT
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
DELETE
3.SEARCH
4.DISPLAY
5.EXIT
bye!!
RESULT:
Thus the C program to implement singly linked list is written and executed successfully.
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
AIM:
ALGORITHM:
If choice equal to 1 then read the number and position and call insert ()
LAB MANUAL
Assign p = l
Assign tmp->data = no
Assign tmp->prev = p
Traverse through the list using pointer p till the last node and check for the number no
If the number is found print the position else print “element not found ”
Assign p = l->next
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
Traverse through the list till last, using pointer p and if p->data = no then goto 4 else
continue traversing
void print ()
Assign p = l->next
Traverse through the list using the pointer and print the list
creation
34
55
67
33
10
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
1.INSERT
2.DELETE
3.SEARCH
4.DISPLAY
5.EXIT
INSERTION
1.INSERT
2.DELETE
3.SEARCH
4.DISPLAY
5.EXIT
DELETION
1.INSERT
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
2.DELETE
SEARCH
4.DISPLAY
5.EXIT
DISPLAY
12 34 55 11 67 10
1.INSERT
2.DELETE
3.SEARCH
4.DISPLAY
5.EXIT
element found!!
position is 4
1.INSERT
2.DELETE
3.SEARCH
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
4.DISPLAY
5.EXIT
bye!!
RESULT:
Thus the C program to implement a doubly linked list is written and executed
successfully.
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
AIM:
ALGORITHM:
If choice equal to 1 then read the number and position and call insert ()
LAB MANUAL
Assign p = l
Assign tmp->data = no
Assign tmp->prev = p
Traverse through the list using pointer p till the last node and check for the number no
If the number is found print the position else print “element not found ”
LAB MANUAL
Assign p = l->next
Traverse through the list till last, using pointer p and if p->data = no then goto 4 else
continue traversing
void print ()
Assign p = l->next
Traverse through the list using the pointer and print the list
creation
34
55
67
33
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
10
select the operation
1.INSERT
2.DELETE
3.SEARCH
4.DISPLAY
5.EXIT
INSERTION
INSERT
2.DELETE
3.SEARCH
4.DISPLAY
5.EXIT
DELETION
LAB MANUAL
1.INSERT
2.DELETE
3.SEARCH
4.DISPLAY
5.EXIT
DISPLAY
12 34 55 11 67 10
1.INSERT
2.DELETE
3.SEARCH
4.DISPLAY
5.EXIT
element found!!
position is 4
1.INSERT
2.DELETE
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
3.SEARCH
4.DISPLAY
5.EXIT
bye!!
RESULT:
Thus the C program to implement a circular linked list is written and executed successfully.
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
Sequential access
AIM:
To write bank customer details into a file and to sequentially access the customer details
ALGORITHM:
Get the customer details like account number, name and balance from the user.
Write the account number, name and balance of each customer into the file.
Exit
Read the customer details account number, name and balance from the file.
Check whether the balance is zero, credit or debit balance based on the option for each
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
Enter the account number, name and balance of customer 1 : 123 AAA 0
Enter the account number, name and balance of customer 2 : 456 BBB -80
Enter the account number, name and balance of customer 3 : 789 CCC 100
Enter the account number, name and balance of customer 4 : 147 DDD -60
Enter the account number, name and balance of customer 5 : 258 EEE 1000
Exit
123 AAA 0
LAB MANUAL
Exit
Exit
Exit
4
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
Bye!
RESULT:
Thus the C program to write bank customer details into a file and to sequentially access
the customer details from the file is written and executed successfully.
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
Random access
AIM:
To write bank customer details into a file and to randomly access the customer details
ALGORITHM:
Get the customer details like name and balance from the user and the account number
Write the account number, name and balance of each customer into the file.
Read the customer detail name and balance from the file based on the account number
using fseek().
LAB MANUAL
3 CCC 100
RESULT:
Thus the C program to write bank customer details into a file and to randomly access
the customer details from the file is written and executed successfully
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
LAB MANUAL
LAB MANUAL
3
2
1
Want to continue:(Y/N):y
1.Push.
2.Pop.
3.Display.
4.Exit.
Enter the choice:2
The item poped out is 3
Want to continue:(Y/N):n
RESULT:
Thus the program to implement stack using arrays has been implemented and the output is
verified.
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
LAB MANUAL
LAB MANUAL
LAB MANUAL
LAB MANUAL
Stop.
Sample output:
1.Push.
2.Pop.
3.Display.
4.Exit.
Enter the choice:1
Enter the item:1
Want to continue:(Y/N):y
1.Push.
2.Pop.
3.Display.
4.Exit.
Enter the choice:1
Enter the item:2
Want to continue:(Y/N):y
1.Push.
2.Pop.
3.Display.
4.Exit.
Enter the choice:1
Enter the item:3
Want to continue:(Y/N):y
1.Push.
2.Pop.
3.Display.
4.Exit.
Enter the choice:3
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
3
2
1
Want to continue:(Y/N):y
1.Push.
2.Pop.
3.Display.
4.Exit.
Enter the choice:2
Popped Element:3
Want to continue:(Y/N):y
1.Push.
2.Pop.
3.Display.
4.Exit.
Enter the choice:3
2
1Want to continue:(Y/N):n
RESULT:
Thus the program to implement stack using linked list has been implemented and the output
is verified.
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
Ex no 10 a CIRCULAR QUEUE
AIM:
To write a C Program to implement a Circular Queue and its Various Operations.
Algorithm:
Step 1: Start
Step 2: Insertion, Deletion and Display functions are performed as per user's commands
Step 3: Stop
void insert()
Step 1: Start
Step 2: if((front==0&&rear==max-1)||(front>0&&rear==front-1)), do step 2.1
2.1: Print QUEUE OVERFLOW
Step 3: else do steps 3.1-3.3
3.1: Input an element
3.2: if(rear==max-1&&front>0), do steps 3.2.1-3.2.2
3.2.1: rear=0
3.2.2: q[rear]=x
3.3: else do step 3.3.1
3.3.1: if((front==0&&rear==-1)||(rear!=front-1)), do step 3.3.1.1
3.3.1.1: q[++rear]=x;
Step 4: Stop
void delet()
Step 1: Start
Step 2: if((front==0)&&(rear==-1)), do steps 2.1-2.3
2.1: Print QUEUE UNDERFLOW
2.2: getch()
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
2.3: exit()
Step 3: if(front==rear), do steps 3.1-3.2
3.1: a=q[front]
3.2: rear=-1, front=0
Step 4: else do steps 4.1-4.3
4.1: if(front==max-1), do steps 4.1.1-4.1.2
4.1.1: a=q[front]
4.1.2: front=0
4.2: else a=q[front++]
4.3: Print the deleted element
Step 5: Stop
void display()
Step 1: Start
Step 2: if((front==0)&&(rear==-1)), do steps 2.1-2.3
2.1: Print QUEUE UNDERFLOW
2.2: getch()
2.3: exit()
Step 3: if(front>rear), do steps 3.1-3.4
3.1: i=0
3.2: while(i<=rear), do step 3.2.1-3.2.2
3.2.1: Print q[i]
3.2.2: i++
3.3: j=front
3.4: while(j<=max), do steps 3.4.1-3.4.2
3.4.1: Print q[j]
3.4.2: j++
3.4: Print the locations of rear and front
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
LAB MANUAL
3 2
rear is at 2
front is at 3
RESULT:
Program to implement a circular queue has been executed and the output has been verified.
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
LAB MANUAL
Stop.
Sample output:
1.Enqueue.
2.Dequeue
3.Display.
4.Exit.
Enter the choice:1
Enter the item:1
Want to continue:(Y/N):y
1.Enqueue.
2.Dequeue
3.Display.
4.Exit.
Enter the choice:1
Enter the item:2
Want to continue:(Y/N):y
1.Enqueue.
2.Dequeue
3.Display.
4.Exit.
Enter the choice:1
Enter the item:3
Want to continue:(Y/N):y
1.Enqueue.
2.Dequeue
3.Display.
4.Exit.
Enter the choice:3
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
3
2
1
Want to continue:(Y/N):y
1.Enqueue.
2.Dequeue
3.Display.
4.Exit.
Enter the choice:2
Deleted Element:1
Want to continue:(Y/N):y
|1.Enqueue.
2.Dequeue
3.Display.
4.Exit.
Enter the choice:3
3
2
Want to continue:(Y/N):n
RESULT:
Thus the program to implement queue using linked list has been implemented and the output
is verified.
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
ALGORITHM:
LAB MANUAL
3.exit
2
RESULT:
Thus the C program to implement a double ended queue in which insertion and deletion
is possible in both the ends is written and executed successfully.
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
SAMPLE INPUT: 20 46 15 10 76
SAMPLE OUTPUT: 10 15 20 46 76
LAB MANUAL
SAMPLE OUTPUT:
Arr= 5 10 20 30 40
LAB MANUAL
LAB MANUAL
SAMPLE OUTPUT: 12 16 50 72 98
LAB MANUAL
LAB MANUAL
SAMPLE INPUT: 12 15 67 98 50 72
SAMPLE OUTPUT: 12 15 50 67 72 98
RESULT: Hence a program was written in C and executed to implement quick sort.
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
LAB MANUAL
SAMPLE OUTPUT: 10 34 56 60 70
LAB MANUAL
SAMPLE INPUT: 10 50 90 40 30
SAMPLE OUTPUT: 10 30 40 50 90
LAB MANUAL
AIM:
Function seq(a,s,n)
1. Initialize variables big and small to a[0] and posn to –1 respectively.
2. Execute a loop for i = 1 to n do step 3
3. If (s equal to a(i)) then set posn as i+1
4. Return posn
RESULT:
Thus the C program to search an element in an array using linear search is written and
executed successfully.
FT/GN/68A/02/30.06.16
SRI VENKATESWARA COLLEGE OF ENGINEERING
LAB MANUAL
AIM:
Function bin(a,s,n)
1. Initialize left = 0 right = n.
2. Check whether left is less than or equal to right, then goto step 3.
3. Compute mid = floor((right-left)/2)+left.
4. Check whether if value is equal to a[mid], then set left as mid +1.
5. Check whether if value is less than a[mid], then set right as mid-1.
6. If element is found return mid.
7. If element is not found return -1.
RESULT:
Thus the C program to search an element in an array using binary search is written and
executed successfully.