2. Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .
Ltd
6. Leniar Data Structure
• A data structure is a method for organizing
and storing data, which would allow efficient
data retrieval and usage.
• Linear data structure is a structure that
organizes its data elements one after the
other.
• Linear data structures are organized in a way
similar to how the computer’s memory is
organized.
8. Arrays
Declaration of array
For example:
Data type array name[array size];
int age[5];
• Here, the name of array is age. The size of
array is 5,i.e., there are 5 items(elements) of
array age. All element in an array are of the
same type (int, in this case)
9. • Initialization of one-dimensional array:
• Arrays can be initialized at declaration time
in this source code as:
• int age[5]={2,4,34,3,4}; It is not necessary to
define the size of arrays during initialization.
• int age[]={2,4,34,3,4};
• In this case, the compiler determines the size
of array by calculating the number of
elements of an array.
10.
11. queue
• Queue is a data structure which works as FIFO principle.
• FIFO means “First in First out”, i.e the element which we have
inserted first will be deleted first and the element that we have
inserted last will be deleted last.
• You can have c program to implement queue using array, . Two
variables are used to implement queue, i.e “rear” and “front”.
Insertion will be done at rear side and deletion will be performed at
front side. Figure below will show you and will make some concept
of queue.
With simple queue, you can also have circular queue data
structure and dequeue data structure.
• c program for queue using array
12. •
#include<stdio.h>
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
#include<conio.h>
#define MAX 10 void insert(int);
int del(); int queue[MAX], rear=0, front=0;
void display();
int main() { char ch , a='y';
int choice, token;
printf("1.Insert");
printf("n2.Delete");
printf("n3.show or display");
do { printf("nEnter your choice for the operation: ");
scanf("%d",&choice);
switch(choice) { case 1: insert(token);
display(); break; case 2: token=del();
printf("nThe token deleted is %d",token);
display(); break;
case 3: display();
13. •
•
•
•
•
•
•
•
break;
default: printf("Wrong choice");
break; }
printf("nDo you want to continue(y/n):");
ch=getch();
} while(ch=='y'||ch=='Y')
; getch();
} void display() { int i;
•
•
•
•
•
printf("nThe queue elements are:");
for(i=rear;i<front;i++) { printf("%d ",queue[i]);
}}
void insert(int token) { char a; if(rear==MAX) { printf("nQueue full");
return; } do { printf("nEnter the token to be inserted:"); scanf("%d",&token); queue[front]=token;
front=front+1; printf("do you want to continue insertion Y/N"); a=getch(); } while(a=='y'); } int del()
{ int t; if(front==rear) { printf("nQueue empty"); return 0; } rear=rear+1; t=queue[rear-1]; return t;
14. •
•
•
•
•
•
•
•
•
•
•
•
•
return;
} do { printf(" nEnt er the token to be inserted:");
scanf("% d” ,&token);
queue[front]=token;
front=front+1;
printf("do you want to continue insertion Y/N"); a=getch();
} while(a=='y');
} int del() { int t;
if(front==rear) { printf("nQueue empty");
return 0;
} rear=rear+1;
t=queue[rear-1];
return t;
23. If this presentation helped you, please visit our
page facebook.com/baabtra and like it.
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
24. Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550