Академический Документы
Профессиональный Документы
Культура Документы
Lab Manual
Subject
Data Structure
Session:-2018-2019
Semester:-I
G. H. Raisoni College of Engineering, Nagpur
(An Autonomous Institute under UGC Act 1956)
Department of First Year
Data Structures Practical List
Subject Name: Data Structure
Year/Semester: I/I
Sr. No. Name of Experiment CO
1 Introduction to Project & Requirement Gathering. CO1
2 Project Table Identifications: Table Names, Table Attributes, CO1
Primary Keys, Foreign Keys, Integrity Constraints, Data Types,
Referencing
3 Data Entry: Designing of database Schema, Data Entry on to CO1
Tables, Alteration of table structure of alteration of scheme based
on requirement. Data validation against use cases and test cases
4 Implementation of Array CO2
5 Implementation of Singly Linked List for insertion, deletion CO3
operation.
6 Implementation of Singly Linked List for Searching, sorting CO3
operation.
7 Implementation of Stack on the required data storage. CO4
8 Implementation of Queue on the required data storage. CO4
9 Implementation of Efficient Sorting techniques to sort data. CO4
10 Implementation of Efficient Searching techniques to search on run CO4
time requirement data.
The structure of the system can be divided into 3 main logical components:
Ordering System- provides the functionality for customers to place their order and
supply necessary details.
Order Retrieval System-This is a final logical component. Allows restaurant to keep
track of all orders placed. This component takes care of order retrieving and displaying
order information.
Pentium Processor
60 MB of free hard-drive space
128 MB of RAM
Software Interface:
Activity Diagram :
This section lists the activity diagram and describes the flow of the activities in the system.
A detailed description is then given after the figure for each activity. Figure # 3 provides
the overview of the activity of the Online Food Order System application.
All users of the system, are provided with below menu options:
Customers of the Ordering system will interact with the application through an easy to use
top
navigation menu.
“Home” menu option: allows the users to see all food items offered with nice images as
well as
select an item to place an order.
“Menu”menu option: a „Drop-Down‟ menu, allows users to see all food items per
category. Item
can then be added to the cart using a single button click.
- Once, Check Out button is selected, user will be prompted for the Sign In/Sign Up
process if not logged in else user will be presented with a simple “Payment
Information” form. User will be asked to provide all required details in displayed text
boxes and make appropriate Dropdown selections. Then, all this information can be
saved using a „Save‟ button.
- User will then be presented with a “Review Order” page, which will display Payment
Information along with Order details to review. User can then use a „Check Out‟ button
toplace an order.
- Once order is placed, user will be presented with appropriate Order confirmation
success/failure message.
“MyAccount”: a “Drop Down” menu will display the user orders, Sign In and Sign Out
option.
The application will automatically fetch new orders from the database at regular intervals
and display the order numbers.
Under “MyAcoount‟ menu a customer will be able to see only his/her order whereas a
Restaurant Employee or an Admin can see all users orders.
To view the details of an order, the user must click on that order number, which will
display all order details This structure can intuitively be expanded and collapsed to
display only the desired information.
PRACTICAL No : 2 and 3
Aim- Project Table Identifications: Table Names, Table Attributes, Primary Keys,
Foreign Keys, Integrity Constraints, Data Types, Referencing
Commands:
create table course (
cnum varchar(5) not null, cname varchar(40) not null, primary key (cnum) )
insert into professor values (1, 'Weddell, Grant', 'DC3346', 'Computer Science')
insert into professor values (2, 'Ilyas, Ihab', 'DC3348', 'Computer Science')
create table student ( snum integer not null, sname varchar(20) not null, year integer not
null, primary key (snum) )
create table class ( cnum varchar(5) not null, term varchar(5) not null, section integer not
null, pnum integer not null, primary key (cnum, term, section), foreign key (cnum)
references course (cnum), foreign key (pnum) references professor (pnum) )
create table enrollment ( snum integer not null, cnum varchar(5) not null, term varchar(5)
not null, section integer not null, primary key (snum, cnum, term, section), foreign key
(snum) references student (snum), foreign key (cnum, term, section) references class
(cnum, term, section) )
create table mark ( snum integer not null, cnum varchar(5) not null, term varchar(5) not
null, section integer not null, grade integer not null, primary key (snum, cnum, term,
section), foreign key (snum, cnum, term, section) references enrollment (snum, cnum,
term, section) )
create table schedule ( cnum varchar(5) not null, term varchar(5) not null, section integer
not null, day varchar(10) not null, time varchar(5) not null, room varchar(10) not null,
primary key (cnum, term, section, day, time), foreign key (cnum, term, section) references
class (cnum, term, section) )
Aim: Write a program to implement Login module of the project using character
Array.
Program:
char password[10]={"codechamp"};
void main()
{
printf("\nEnter Password:");
while(ch!=13)
{
ch=getch();
printf("Password match");
gotoxy(17,10);
OUTPUT:-
PRACTICAL No: 5
Implementation of Linked List
Aim: To write a program to implement the basic operations on Singly Linked List
Algorithm:
1. Start
2. Read the value of ch
3. If ch =1 then read item of number
set n as malloc to size, set n of into as num and next as list
4. If ch=2 to check if list =0 then print “Empty list”
else if n is list then delete the node n
5. If ch=3 then read position value and set n as malloc size and read num value and
store in n.
6. If ch =4 then check list as NULL or not. If NULL then print “ Empty list”
Else check I not equal to pos then print info of p then delete the node p
7. If ch=5 then set n and allocate malloc size and read num.
Else next not as Null then n as next of p
8. If ch=6 then check pos Null and print “Empty list”
Else delete the node p
9. stop
Logical Description
The singly-linked list is the most basic of all the linked data structures. A singly-linked list
is simply a sequence of dynamically allocated objects, each of which refers to its successor
in the list. Despite this obvious simplicity, there are myriad implementation variations.
Program Code
struct node
{
int data;
struct node *link;
}*head;
typedef struct node node;
void maintain(void);
void create(node *);
void insertion(node *);
void deletion(node *);
void display(node *);
int count=0;
#include"stdio.h"
#include"alloc.h"
main()
{
head=malloc(sizeof(node));
create(head);
maintain();
getch();
return;
}
void maintain()
{
int n;
clrscr();
printf(" MAINTANENCE\n\n1. Insertion\n2. Deletion\n3. Display\n4. Exit");
printf("\n\nYour choice: ");
scanf("%d",&n);
switch(n)
{
case 1:
{
insertion(head);
break;
case 2:
{
deletion(head);
break;
}
case 3:
{
display(head);
break;
}
case 4:
{
exit();
}
}
}
MAINTANENCE
1. Insertion
2. Deletion
3. Display
4. Exit
Your choice: 1
INSERTION
1. Insertion at first
2. Insertion at last
3. Insertion inbetween
Your choice: 1
int main()
{
int arr[] = {12, 56, 2, 11, 1, 90};
int list_size, i;
getchar();
return 0;
}
do
{
swapped = 0;
ptr1 = start;
Output:
#include<stdio.h>
#include<stdlib.h>
struct Node
{
int data;
struct Node* next;
};
Node *newNode(int x)
{
struct Node* temp = new Node;
temp->data = x;
temp->next = NULL;
return temp;
}
return slow;
}
do
{
// Find middle
Node* mid = middle(start, last);
// If middle is empty
if (mid == NULL)
return NULL;
// Driver Code
int main()
{
Node *head = newNode(1);
head->next = newNode(4);
head->next->next = newNode(7);
head->next->next->next = newNode(8);
head->next->next->next->next = newNode(9);
head->next->next->next->next->next = newNode(10);
int value = 7;
if (binarySearch(head, value) == NULL)
printf("Value not present\n");
else
printf("Present");
return 0;
}
Output:
Input : Enter value to search : 7
Output : Found
1. Start
2. Declare an one dimensional array variable
3. Using Switch case statement select one appropriate operation
a. PUSH:
i. Read an element
ii. Store it at the top of the stack
iii. Increment the TOS
b. POP
i. Read the element from the top of the stack
ii. Display it
iii. Decrement the TOS
c. PEEK
i. Read the element from the top of the stack
ii. Display it
4. Stop
Logical Description
The program implements the Stack using one dimensional array. Initially an array variable
is declared, and variable TOS is to point the top of the stack is also declared. PUSH
operation is done by reading an element from the user and storing it at TOS position. POP
operation retrieves the value at TOS and removes the element; TOS now points the next
element. PEEK operation retrieves the element but it is not deleted from the stack.
Program Code
/*Stack Using Arrays*/
#include<stdio.h>
#include<conio.h>
#define SIZE 4
int a[SIZE],top=0,ch=1,i,n;
void display();
void create();
void push();
void pop();
void peek();
void main()
{
clrscr();
printf("\n\t\tStack Using Arrays");
printf("\n\t\t------------------");
printf("\n\t\t 1.Create");
printf("\n\t\t 2.Push");
printf("\n\t\t 3.Pop");
printf("\n\t\t 4.Peek");
printf("\n\t\t 5.Exit\n");
do
{
printf("\t\tEnter Your Choice :");
scanf("%d",&ch);
switch(ch)
{
case 1: create();break;
case 2: push();break;
case 3: pop();break;
case 4: peek();break;
default: printf("\t\tExit");
break;
}
}while(ch!=5);
getch();
}
void create()
{
if(top==0)
{
printf("\t\tNumber of Element:");
scanf("%d",&n);
if(n>SIZE)
printf("\t\tSize of Stack is Large\n");
else
{
printf("\t\tPushing Element :");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
top=n;
display();
}
}
else
{
printf("\tStack Already Exists");
}}
void push()
{
if(top==SIZE)
printf("\t\tStack Overflow\n");
else
{
printf("\t\tPushing Element :");
scanf("%d",&a[++top]);
display();
}}
void pop()
{
if(top==0)
printf("\t\tStack Underflow\n");
else
{
printf("\t\tPop Element :%d\n",a[top--]);
display();
}}
void display()
{
if(top==0)
printf("\t\tStack is Empty");
else
{
printf("\t\tStack Contains :");
for(i=top;i>=1;i--)
printf("%d ",a[i]);
}
printf("\n");
}
void peek()
{
if(top==0)
printf("\t\tStack Empty\n");
else
printf("\t\tTop Element is %d\n",a[top]);
}
OUTPUT:-
1. Push
2. Pop
3. Peek
4. Display
5. Exit
1. Push
2. Pop
3. Peek
4. Display
5. Exit
1. Push
2. Pop
3. Peek
4. Display
5. Exit
Enter your option: 1
Enter the element to be pushed into the stack: 34
Choose the option
1. Push
2. Pop
3. Peek
4. Display
5. Exit
Enter your option: 4
The elements in the stack are: 12
15
34
Choose the option
1. Push
2. Pop
3. Peek
4. Display
5. Exit
1. Push
2. Pop
3. Peek
4. Display
5. Exit
1. Push
2. Pop
3. Peek
4. Display
5. Exit
Algorithm:
1. Start
2. Read ch and n value
3. check (ch!=4) and if (rear =n) then read value
4. Assign value to q(rear) and increment the rear, else Display as queue if full
5. if (front=rear) then print front value of queue and increment front
Else Display as queue is empty
6. if (rear=0) then assign front to I and write q[i].
Else Display as queue is empty
7. Go to step 3
8. stop
Logical Description
A collection of items in which only the earliest added item may be accessed. Basic
operations are add (to the tail) or enqueue and delete (from the head) or dequeue. Delete
returns the item removed. Also known as "first-in, first-out" or FIFO.
Program Code
#include<stdio.h>
#include<conio.h>
void main()
{
int q[50],i,j,n,op,front,rear,no;
clrscr();
printf("Enter the size of the queue:");
scanf("%d",&n);
printf("QUEUE OPERATIONS:\n1.Insert\n2.Delete\n3.Display\n4.Exit\n");
printf("Enter the operation to be performed:");
scanf("%d",&op);
front=0;rear=-1;
while(op!=4){
switch(op)
{
case 1:{
if(rear==n-1)
printf("\nQueue is full!\n");
else
{
printf("Enter the element to be inserted:");
scanf("%d",&no);
q[++rear]=no;
printf("\n%d is inserted!",no);
}
break; }
case 2: {
if(front==0 && rear==-1)
printf("\nQueue is empty!");
else
{
printf("\n%d is deleted!",q[front]);
q[front]=0;
for(j=front;j<rear;j++)
q[j]=q[j+1];
rear=rear-1;
}
break; }
case 3: {
printf("\nQueue is:\n");
for(i=front;i<=rear;i++)
printf("%d\t",q[i]);
break; }
}
printf("\nEnter the operation to be performed:");
scanf("%d",&op);
}
getch(); }
OUTPUT
12 is inserted!
Enter the operation to be performed:1
Enter the element to be inserted:32
32 is inserted!
Enter the operation to be performed:3
Queue is:
12 32
Enter the operation to be performed:2
12 is deleted!
Enter the operation to be performed:3
Queue is:
32
Enter the operation to be performed:2
32 is deleted!
Enter the operation to be performed:2
Queue is empty!
Enter the operation to be performed:3
Queue is:
Algorithm
1. low =l, high = h, key a[(l+h)/2]
2. Repeat through step 7 while (low <= high)
3. Repeat step 4 while (a[low] < key)
4. low = low +1
5. Repeat step 6 while (a[high] > key)
6. high = high – 1
7. If (low <= high)
a) temp = a[low]
b) a[low] = a[high]
c) a[high] = temp
d) low = low + 1
e) high = high + 1
8. If (l < high) quicksort (a,l,high)
9. If (h>low) quicksort (a,low,h)
10. Exit
quick sort
#include<stdio.h>
#include<conio.h>
#define max 100 int
a[max],n,i,l,h; void
main()
{
void input(void);
input();
getch();
}
void input(void)
{
void output(int a[],int n);
void quick_sort(int a[],int l,int h); printf("How many
elements in the array : "); scanf("%d",&n);
printf("\n");
printf("Enter the elemennts : \n");
for(i=0;i<=n-1;i++)
{
scanf("%d",&a[i]);
}
l=0;
h=n-1;
quick_sort(a,l,h);
printf("Sorted Array :\n "); output(a,n);
}
void quick_sort(int a[],int l, int h)
{
int temp,key,low,high;
low=l;
high=h;
key=a[(low+high)/2]; do
{
while(key>a[low])
{
low++;
}
while(key<a[high])
{
high--;
}
if(low<=high)
{
temp=a[low];
a[low++]=a[high];
a[high--]=temp;
}
} while(low<=high);
if(l<high)
quick_sort(a,l,high);
if(low<h)
quick_sort(a,low,h);
}
void output(int a[],int n)
{
for(i=0;i<=n-1;i++)
{printf("%d\n",a[i]);}
}
Output of program:
PRACTICAL No : 10
Implementation of Efficient Searching techniques to Search on run time
requirement data.
Algorithm
1. Set k := 1 & loc : = 0
2. Repeat step 3 & 4 while loc : = 0 &k < = n
3. If (item = data[k])
loc : = k
Else
K=k+1
4. If loc : = 0 ,then Print
“no. not found” Else
Print “loc is the location of item”
5. Exit
linear search
#include<stdio.h>
#include<conio.h>
void main()
{
int a[100],n,i,item,loc=-1; clrscr();
printf("\nEnter the number of element:"); scanf("%d",&n);
printf("Enter the number:\n");
for(i=0;i<=n-1;i++)
{
scanf("%d",&a[i]);
}
printf("Enter the no. to be search\n"); scanf("%d",&item);
for(i=0;i<=n-1;i++)
{
if(item==a[i])
{
loc=i;
break;
}
}
if(loc>=0)
{ printf("\n%dis found in position%d",item,loc+1); else
printf("\nItem does not exits"); getch();
}
Algorithm To Search An Element Using Binary Search
1. low = 1,high = n
2. Repeat step 3 to 5 while low <= high
3. mid = (low + high)
4. If a[mid] = x
Print “ found at mid”
Return
5. If (a[mid] < x)
low = mid + 1
Else
High = mid – 1
6. Print “x not found”
7. Exit
//binary search
#include<stdio.h>
#include<conio.h> void main()
{
int a[100],i,loc,mid,beg,end,n,flag=0,item; clrscr();
printf("How many elements"); scanf("%d",&n);
printf("Enter the element of the array\n");
for(i=0;i<=n-1;i++)
{
scanf("%d",&a[i]);
}
printf("Enter the element to be searching\n");
scanf("%d",&item);
loc=0; beg=0; end=n-1;
while((beg<=end)&&(item!=a[mid]))
{
mid=((beg+end)/2);
if(item==a[mid])
{
printf("search is successfull\n"); loc=mid;
printf("position of the item%d\n",loc+1); flag=flag+1;
}
else
{
if(item<a[mid])
end=mid-1;
beg=mid+1;
}
if(flag==0)
{
printf("search is not successfull\n");
}
getch();
}
Output of program: