0% found this document useful (0 votes)
168 views28 pages

Cs6212 Programming and Data Structures Laboratory I Laboratory Manual

This document contains the laboratory manual for the course CS6212 - Programming and Data Structures Laboratory I. It lists 14 exercises that cover topics like arrays, strings, sorting, searching, stacks, queues, linked lists, trees and file handling. For each exercise, it provides the aim, algorithm and a table to enter the test inputs, expected outputs and actual outputs to check if the program is working as expected. The exercises implement classic data structures and algorithms in C programming language.

Uploaded by

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

Cs6212 Programming and Data Structures Laboratory I Laboratory Manual

This document contains the laboratory manual for the course CS6212 - Programming and Data Structures Laboratory I. It lists 14 exercises that cover topics like arrays, strings, sorting, searching, stacks, queues, linked lists, trees and file handling. For each exercise, it provides the aim, algorithm and a table to enter the test inputs, expected outputs and actual outputs to check if the program is working as expected. The exercises implement classic data structures and algorithms in C programming language.

Uploaded by

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

CS6212-PROGRAMMING AND DATA STRUCTURES LABORATORY I

CS6212 PROGRAMMING AND


DATA STRUCTURES LABORATORY
I
LABORATORY MANUAL

SARANATHAN COLLEGE OF ENGINEERING

Page 1

CS6212-PROGRAMMING AND DATA STRUCTURES LABORATORY I

LIST OF EXERCISES:
1. Greatest of n numbers using array
2 a. Sorting of n numbers using function
2 b. String Manipulations String Copy, Concatenation, Split
2 c. Alphabetic Arrangement of Strings using function
2 d. Sum and Average of m to n Numbers using pointers.
3.a. Implementation and operation of a linked list using structure in C
3 b.Implementation of Doubly Linked List.
4 a. Read & Write operations in File using sequential access
4 b. Read & Write operations in File using random access
5 a. Implementation of Stack ADT using Array
5 b. Implementation of Queue ADT using Array
5 c. Implementation of Stack ADT using Linked List
5 d. Implementation of Queue ADT using Linked List
5 e. Stack Application - Infix to Postfix Conversion
5 f. Implementation of Polynomial ADT.
6 a. Implementation of Insertion sort
6 b. Implementation of Selection sort
6 c. Implementation of Shell sort
6 d. Implementation of Bubble sort
6 e. Implementation of Merge sort
6 f. Implementation of Quick sort
7 a. Implementation of Linear Search using array
SARANATHAN COLLEGE OF ENGINEERING

Page 2

CS6212-PROGRAMMING AND DATA STRUCTURES LABORATORY I


7 b. Implementation of Binary Search using array

EX NO: 1

GREATEST OF N NUMBERS USING ARRAY

AIM:
To write a C program to find the greatest of n numbers using array.

ALGORITHM:

RESULT:
INPUT

EXPECTED
OUTPUT

SARANATHAN COLLEGE OF ENGINEERING

ACTUAL OUTPUT

RESULT

Page 3

CS6212-PROGRAMMING AND DATA STRUCTURES LABORATORY I

EX NO: 2a

SORTING OF N NUMBERS USING FUNCTION

AIM:
To write a C program to sort n numbers using function.

ALGORITHM:

RESULT:
INPUT

EXPECTED
OUTPUT

SARANATHAN COLLEGE OF ENGINEERING

ACTUAL OUTPUT

RESULT

Page 4

CS6212-PROGRAMMING AND DATA STRUCTURES LABORATORY I

EX NO: 2b STRING MANIPULATIONS STRING COPY, CONCATENATION, SPLIT

AIM:
To write a C program to perform string manipulation.

ALGORITHM:

RESULT:
INPUT

EXPECTED
OUTPUT

SARANATHAN COLLEGE OF ENGINEERING

ACTUAL OUTPUT

RESULT

Page 5

CS6212-PROGRAMMING AND DATA STRUCTURES LABORATORY I


EX NO: 2c ALPHABETIC ARRANGEMENT OF STRINGS USING FUNCTION
AIM:
To write a C program to arrange the strings in alphabetic order using function.

ALGORITHM:

RESULT:
INPUT

EXPECTED
OUTPUT

ACTUAL OUTPUT

RESULT

EX NO: 2d SUM AND AVERAGE OF M TO N NUMBERS USING POINTERS


SARANATHAN COLLEGE OF ENGINEERING

Page 6

CS6212-PROGRAMMING AND DATA STRUCTURES LABORATORY I


AIM:
To write a C program to find the sum and average between two numbers using pointers.

ALGORITHM:

RESULT:
INPUT

EXPECTED
OUTPUT

ACTUAL OUTPUT

RESULT

EX NO: 3 IMPLEMENTATION AND OPERATION OF A LINKED LIST USING


STRUCTURE IN C
SARANATHAN COLLEGE OF ENGINEERING

Page 7

CS6212-PROGRAMMING AND DATA STRUCTURES LABORATORY I


AIM:
To write a C program to implement the operation of linked list using structures in C.

ALGORITHM:
Step 1: Start
Step 2:Read the value of ch
Step 3:If ch=1 call create list function
Step 4:If ch=2 call insertlist function
Step 5:If ch=3 call deletefirst function
Step 6:If ch=4 call viewlist function
Step 7:Repeat step 3 while (ch!=5)
Step 8:Stop
ALGORITHM FOR CREATE LIST
Step 1: Read value of item
Step 2:Allocate the memory for new node
Step 3:Assign values to new node data part
Step 4:Assign new node address part as null
ALGORITHM FOR INSERT LIST
Step 1: Read the value of item
Step 2:Allocate the memory for new node
Step 3:Assign values of data field as null else make link fields of all new nodes to point
Step 4:Set the external pointer from the starting node to new node

ALGORITHM FOR DELETE FIRST


Step 1:If the link is empty then return else check whether the list contains more than one element
SARANATHAN COLLEGE OF ENGINEERING

Page 8

CS6212-PROGRAMMING AND DATA STRUCTURES LABORATORY I


Step 2:Move the start pointer to the next node
Step 3:Free the first node
ALGORITHM FOR VIEW LIST
Step 1:Using the for loop
Step 2:Print the linked list elements
Step 3:Stop

RESULT:
INPUT

EX NO: 3b

EXPECTED
OUTPUT

ACTUAL OUTPUT

RESULT

IMPLEMENTATION OF DOUBLY LINKED LIST.

AIM:
To write a C program to implement the Doubly linked list.
SARANATHAN COLLEGE OF ENGINEERING

Page 9

CS6212-PROGRAMMING AND DATA STRUCTURES LABORATORY I

ALGORITHM:
Step 1:Start
Step 2:Read the value of ch
Step 3:If ch=1 call create list function
Step 4:If ch=2 call insert list function
Step 5:If ch=3 call delete firstt function
Step 6:If ch=4 call view list function
Step 7:If ch=5 call the exit function
Step 8:Repeat step 2 while (ch!=5)
Step 9:Stop
ALGORITHM FOR CREATE LIST
Step 1:Read the value of item
Step 2:Allocate the memory for newly assigned nodes
Step 3:Assign the data to the data field
Step 4:Assign forward and backward link as Null
ALGORITHM FOR INSERT LIST
Step 1:Read the value of item
Step 2:Allocate a new node and assign the item to the data part
Step 3:If head is NULL then Assign link of new node to head and blink of new node to
NULL
Step 4: Return

ALGORITHM FOR DELETE FIRST


Step 1:Check the head node as null return empty
SARANATHAN COLLEGE OF ENGINEERING

Page 10

CS6212-PROGRAMMING AND DATA STRUCTURES LABORATORY I


Step 2:Else change the head pointer to the head pointer link
Step 3:Return
ALGORITHM FOR VIEW LIST
Step 1:Using the for loop
Step 2:Print the list elements.
Step 3:Stop

RESULT:
INPUT

EXPECTED
OUTPUT

ACTUAL OUTPUT

RESULT

EX NO: 4a READ & WRITE OPERATIONS IN FILE USING SEQUENTIAL ACCESS


AIM:
To write a C program to access the file sequentially.
SARANATHAN COLLEGE OF ENGINEERING

Page 11

CS6212-PROGRAMMING AND DATA STRUCTURES LABORATORY I


ALGORITHM:
Step1: Create file pointers and create file1.
Step2: Open the file1 in read mode and open the file 2 in write mode.
Step3: while file pointer of file1 not EOF read and write in file 2.
Step4: Close the files
Step5: Stop.

RESULT:
INPUT

EXPECTED
OUTPUT

ACTUAL OUTPUT

RESULT

EX NO: 4b READ AND WRITE OPERATIONS IN FILE USING RANDOM ACCESS


AIM:
To write a C program to access the file randomly.
ALGORITHM:

SARANATHAN COLLEGE OF ENGINEERING

Page 12

CS6212-PROGRAMMING AND DATA STRUCTURES LABORATORY I

RESULT:
INPUT

EXPECTED
OUTPUT

ACTUAL OUTPUT

RESULT

EX NO: 5a IMPLEMENTATION OF STACK ADT USING ARRAY


AIM:
To write a C program to implement stack ADT using array.
ALGORITHM:
A) Push Operation:
SARANATHAN COLLEGE OF ENGINEERING

Page 13

CS6212-PROGRAMMING AND DATA STRUCTURES LABORATORY I


Step:1 To push an element into the stack, check whether the top of the stack is greater than or
equal to the maximum size of the stack.
Step 2: If so, then return stack is full and element cannot be pushed into the stack.
Step:3 Else, increment the top by one and push the new element in the new position of top.
B) Pop Operation:
Step1:To pop an element from the stack, check whether the top of the stack is equal to -1.
Step2: If so, then return stack is empty and element cannot be popped from the stack.
Step3:Else, decrement the top by one.
C) Returning Top
Step:1 Return S[top].

RESULT:
INPUT

EXPECTED
OUTPUT

SARANATHAN COLLEGE OF ENGINEERING

ACTUAL OUTPUT

RESULT

Page 14

CS6212-PROGRAMMING AND DATA STRUCTURES LABORATORY I

EX NO: 5b

IMPLEMENTATION OF QUEUE ADT USING ARRAY

AIM:
To write a C program to implement queue ADT using array.
ALGORITHM:
Enqueue:
Step 1: Check if queue is not full.
Step 2: If it is full then return queue overflow and item cannot be inserted.
Step 3: If not, check if rear value is -1, if so then increment rear and by 1; if not increment front
by 1.
Step 4. Store the item in the new value of front.
Dequeue:
Step 1: Check if queue is not empty.
Step 2: If it is empty, return queue underflow and dequeue operation cannot be done.
Step 3: If not, check if rear and front are equal, if so assign -1 to front and rear; if not decrement
front by 1.

RESULT:
INPUT

EXPECTED
OUTPUT

SARANATHAN COLLEGE OF ENGINEERING

ACTUAL OUTPUT

RESULT

Page 15

CS6212-PROGRAMMING AND DATA STRUCTURES LABORATORY I

EX NO: 5c

IMPLEMENTATION OF STACK ADT USING LINKED LIST

AIM:
To write a C program to implement stack ADT using linked list.
ALGORITHM:
A) Push Operation:
1. To push an element into the stack, assign the element to be inserted in the data field of the new
node.
2. Assign the reference field of the new node as NULL.
3. Check if top is not NULL, if so, then assign the value of top in the reference field of
new node.
4. Assign the address of the new node to the top.
B) Pop Operation:
1. To pop an element from the stack, check whether the top of the stack is NULL.
2. If so, then return stack is empty and element cannot be popped from the stack.
3. Else, assign the top value to a temporary node.
4. Now assign the value in the reference field of the node pointed by top to the top value.
5. Return the value in the data field of the temporary node as the element deleted and
delete the temporary node.
C) Returning Top
Step:1 Return top node.

SARANATHAN COLLEGE OF ENGINEERING

Page 16

CS6212-PROGRAMMING AND DATA STRUCTURES LABORATORY I

RESULT:
INPUT

EXPECTED
OUTPUT

SARANATHAN COLLEGE OF ENGINEERING

ACTUAL OUTPUT

RESULT

Page 17

CS6212-PROGRAMMING AND DATA STRUCTURES LABORATORY I

EX NO: 5d

IMPLEMENTATION OF QUEUE ADT USING LINKED LIST

AIM:
To write a C program to implement queue ADT using linked list.
ALGORITHM:
Enqueue:
Step1: Create a new node and allocate memory space for the new node.
Step2: Assign the element to be inserted in the data field of the new node.
Step3: Assign NULL to the address field of the new node.
Step4: Check if rear and front pointers are NULL.
Step5: If so, then make the front and rear pointers to point to new node.
Step6: If not, then assign address of the new node as the rear pointer value.
Dequeue:
Step1: Check if queue is not empty.
Step2: If it is empty, return queue underflow and dequeue operation cannot be done.
Step3: If not, assign the front->next value as the new front pointer and free the deleted node.

RESULT:
INPUT

EXPECTED
OUTPUT

SARANATHAN COLLEGE OF ENGINEERING

ACTUAL OUTPUT

RESULT

Page 18

CS6212-PROGRAMMING AND DATA STRUCTURES LABORATORY I

EX NO: 5e

STACK APPLICATION - INFIX TO POSTFIX CONVERSION

AIM:
To write a C program to implement infix to postfix conversion.
ALGORITHM:
Step 1:Read the infix expression and find the length of the expression
Step 2:If the current character is open parenthesis ( then push it into the stack
Step 3:When the current character is an operand then add it to the result
Step 4When the current character is operator check the priority of scanned operator with top of
the stack. If the priority of the scanned character is greater than top of the stack
Step 5: If the element of the current operator is less than or equal to the top of the stack then
i) pop the top character from the stack
ii) push the scanned operator into the stack
Step 6: When the current character is closing parenthesis then pop all the characters above
opening parenthesis if any from the stack
Step7: Return the result
Step 8: End
RESULT:
INPUT

EXPECTED
OUTPUT

SARANATHAN COLLEGE OF ENGINEERING

ACTUAL OUTPUT

RESULT

Page 19

CS6212-PROGRAMMING AND DATA STRUCTURES LABORATORY I

EX NO: 5f

IMPLEMENTATION OF POLYNOMIAL ADT.

AIM:
To write a C program to perform operation of polynomial ADT.

ALGORITHM:
Step 1:while poly1 and poly2 are not null repeat step 2
Step 2:if power of the two term are equal then add the coefficients of poly1 and poly2 and create
list poly3 and advance the pointers of poly1 and poly2 else goto step 3
Step 3:copy remaining terms from the non empty polynomial in to the poly3.
Step 4:return the poly 3 list.
Step5:Stop.

RESULT:
INPUT

EXPECTED
OUTPUT

SARANATHAN COLLEGE OF ENGINEERING

ACTUAL OUTPUT

RESULT

Page 20

CS6212-PROGRAMMING AND DATA STRUCTURES LABORATORY I

EX NO: 6a

IMPLEMENTATION OF INSERTION SORT

AIM:
To write a C program to implement the insertion sort.

ALGORITHM:
Step1:Get the n elements to be sorted.
Step2: The ith element is compared from (i-1)th to 0th element and placed in proper position
according to ascending value.
Step 3: Repeat the above step until the last element.
Step 4: print the list.
Step 5: Stop.

RESULT:
INPUT

EXPECTED
OUTPUT

SARANATHAN COLLEGE OF ENGINEERING

ACTUAL OUTPUT

RESULT

Page 21

CS6212-PROGRAMMING AND DATA STRUCTURES LABORATORY I

EX NO: 6b

IMPLEMENTATION OF SELECTION SORT

AIM:
To write a C program to implement the selection sort.

ALGORITHM:

RESULT:
INPUT

EXPECTED
OUTPUT

SARANATHAN COLLEGE OF ENGINEERING

ACTUAL OUTPUT

RESULT

Page 22

CS6212-PROGRAMMING AND DATA STRUCTURES LABORATORY I

EX NO: 6c

IMPLEMENTATION OF SHELL SORT

AIM:
To write a C program to implement the shell sort.

ALGORITHM:

RESULT:
INPUT

EXPECTED
OUTPUT

SARANATHAN COLLEGE OF ENGINEERING

ACTUAL OUTPUT

RESULT

Page 23

CS6212-PROGRAMMING AND DATA STRUCTURES LABORATORY I

EX NO: 6d

IMPLEMENTATION OF BUBBLE SORT

AIM:
To write a C program to implement the bubble sort.

ALGORITHM:
Step 1:Get the n elements to be sorted.
Step 2: Compare the first two elements of the array and swap if necessary.
Step 3 Then, again second and third elements are compared and swapped if it is necessary and
continue this process until last and second last element is compared and swapped.
Step 4: Repeat the above two steps n-1 times and print the result.
Step5: Stop.

RESULT:
INPUT

EXPECTED
OUTPUT

SARANATHAN COLLEGE OF ENGINEERING

ACTUAL OUTPUT

RESULT

Page 24

CS6212-PROGRAMMING AND DATA STRUCTURES LABORATORY I

EX NO: 6e

IMPLEMENTATION OF MERGE SORT

AIM:
To write a C program to implement the merge sort.

ALGORITHM:

RESULT:
INPUT

EXPECTED
OUTPUT

SARANATHAN COLLEGE OF ENGINEERING

ACTUAL OUTPUT

RESULT

Page 25

CS6212-PROGRAMMING AND DATA STRUCTURES LABORATORY I


EX NO: 6f

IMPLEMENTATION OF QUICK SORT

AIM:
To write a C program to implement the quick sort.

ALGORITHM:
Step1:Pick an element, called a pivot, from the list.
Step2:Reorder the list so that all elements which are less than the pivot come before the pivot
and so that all elements greater than the pivot come after it.
Step3:After this partitioning, the pivot is in its final position. This is called the partition
operation.
Step4:Recursively sort the sub-list of lesser elements and the sub-list of greater elements
Step 5: Print the list.
Step 6: Stop

RESULT:
INPUT

EX NO: 7a

EXPECTED
OUTPUT

ACTUAL OUTPUT

RESULT

IMPLEMENTATION OF LINEAR SEARCH USING ARRAY

SARANATHAN COLLEGE OF ENGINEERING

Page 26

CS6212-PROGRAMMING AND DATA STRUCTURES LABORATORY I

AIM:
To write a C program to implement the linear search.

ALGORITHM:
Linear Search
Step1: Read n numbers and search value.
Step2: If search value is equal to first element then print value is found.
Step3: Else search with the second element and so on.
Step4: Stop

RESULT:
INPUT

EXPECTED
OUTPUT

SARANATHAN COLLEGE OF ENGINEERING

ACTUAL OUTPUT

RESULT

Page 27

CS6212-PROGRAMMING AND DATA STRUCTURES LABORATORY I


EX NO: 7b

IMPLEMENTATION OF BINARY SEARCH USING ARRAY

AIM:
To write a C program to implement the binary search.

ALGORITHM:
Step1: Read n numbers and search value.
Step2: calculate middle=(lower bound+higher bound)/2
Step 3: If search value is equal to middle element then print value is found.
Step3: If search value is less than middle element then repeat Step 2 with higher bound middle-1
search left half of list else repeat Step 2 with lower bound middle+1 search right half of list.
Step 4: Stop

RESULT:
INPUT

EXPECTED
OUTPUT

SARANATHAN COLLEGE OF ENGINEERING

ACTUAL OUTPUT

RESULT

Page 28

You might also like