leniar datastructure

Post on 20-Jan-2015

358 Views

Category:

Education

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

Leniar datastructure

TRANSCRIPT

Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring PartnerBaabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd

Week Target Achieved

1 22

2 25 243 30 25

4 30 28

Typing Speed

Jobs Applied# Company Designation Applied Date Current Status

1 AfiInfotec SoftwareDeveloper 21/8/2013

2 CodeLogic SoftwareDeveloper 23/8/2013

3

Linear data structure

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.

Example For Linear data structure

Array, Stcks, Linked list, Queue

Arrays

Declaration of array

• 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)

For example:Data type array name[array size]; int age[5];

• 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.

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

• #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();

• 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;

• 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;

STACK

Simple program using Stack

Application of Stack

end

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

Contact Us

Emarald Mall (Big Bazar Building)Mavoor Road, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550

NC Complex, Near Bus StandMukkam, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550

Start up VillageEranakulam,Kerala, India.

Email: info@baabtra.com

top related