Leniar datastructure

559 views

Published on

Leniar datastructure

Published in: Education, Technology
  • Be the first to comment

  • Be the first to like this

Leniar datastructure

  1. 1. 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
  2. 2. Typing Speed Week Target Achieved 1 22 2 25 24 3 30 25 4 30 28
  3. 3. Jobs Applied # Company Designation Applied Date 1 AfiInfotec SoftwareDeveloper 21/8/2013 2 CodeLogic SoftwareDeveloper 23/8/2013 3 Current Status
  4. 4. Linear data structure
  5. 5. 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.
  6. 6. Example For Linear data structure Array, Stcks, Linked list, Queue
  7. 7. 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)
  8. 8. • 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.
  9. 9. 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
  10. 10. • #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();
  11. 11. • • • • • • • • 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;
  12. 12. • • • • • • • • • • • • • 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;
  13. 13. STACK
  14. 14. Simple program using Stack • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • #include<stdio.h> #include<stdlib.h> #define MAX_SIZE 5 int stack[MAX_SIZE]; void push(); int pop(); void traverse(); int is_empty(); int top_element(); int top = -1; main() { int element, choice; while(1) { printf("Stack Operations.n"); printf("1. Insert into stack (Push operation).n"); printf("2. Delete from stack (Pop operation).n"); printf("3. Print top element of stack.n"); printf("4. Check if stack is empty.n"); printf("5. Traverse stack.n"); printf("6. Exit.n"); printf("Enter your choice.n"); scanf("%d",&choice); switch ( choice ) { case 1: if ( top == MAX_SIZE - 1 ) printf("Error: Overflownn"); else { printf("Enter the value to insert.n"); scanf("%d",&element); push(element); } break;
  15. 15. Application of Stack
  16. 16. end
  17. 17. 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
  18. 18. 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

×