/* 1. WAP TO PERFORM PUSH,POP,AND DISPLAY OPERATION ON A STACK USING LINEAR ARRAY */

Size: px
Start display at page:

Download "/* 1. WAP TO PERFORM PUSH,POP,AND DISPLAY OPERATION ON A STACK USING LINEAR ARRAY */"

Transcription

1 /* 1. WAP TO PERFORM PUSH,POP,AND DISPLAY OPERATION ON A STACK USING LINEAR ARRAY */ #include<stdio.h> #include<conio.h> int i,top,ch,s[3],item; void push(),pop(),dis(); main() top=-1; ch=0; while(ch!=4) printf("\nenter the menu for stack operation\n"); printf("\n1:insert\n2:delete\n3:display\n4:exit\n"); printf("input ur choice\n"); scanf("%d",&ch); switch(ch) case 1: push(); case 2: pop(); case 3: dis(); case 4: exit(0); default: printf("invalid choice\n"); return 0; void push() int item; if(top==3-1) printf("stack Overflow\n"); printf("enter an item to be pushed:"); scanf("%d",&item); top+=1; s[top]=item; void pop() if(top==-1) printf("stack Undeflow\n");

2 printf("item poped is %d\n",s[top--]); void dis() if(top==-1) printf("stack is empty\n"); printf("\nstack contains...\n"); for(i=0; i<=top; i++) printf("%d\t",s[i]);

3 /* 2. WAP TO PERFORM PUSH,POP AND DISPLAY OPERATIONS ON A STACK USING POINTERS */ #include<stdio.h> #include<conio.h> #define size 3 int i,num,ch,s[3],item[size]; struct stack int items[size]; int top; st; void push(struct stack*); void pop(struct stack*); void disp(struct stack*); main() st.top=-1; ch=0; while(ch!=4) printf("\nenter the menu for stack operation\n"); printf("\n1:push\n2:pop\n3:display\n4:exit\n"); printf("input ur choice\n"); scanf("%d",&ch); switch(ch) case 1:push(&st); case 2:pop(&st); case 3:disp(&st); case 4:exit(0); default: printf("invalid choice\n"); return 0; void push(struct stack *st) int item; if(st->top==size-1) printf("stack Overflow\n"); printf("enter an item to be pushed:"); scanf("%d",&item); st->top+=1; st->items[st->top]=item;

4 void pop(struct stack *st) if(st->top==-1) printf("stack Undeflow\n"); printf("item popped is %d\n",st->items[st->top--]); void disp(struct stack *st) if(st->top==-1) printf("stack is empty\n"); printf("\nstack contains...\n"); for(i=0; i<=st->top; i++) printf("%d\t",st->items[i]);

5 /* 3. i) Write a program to convert a postfix exp to infix exp */ #include<stdio.h> #include<string.h> void push(char item[],int *top,char s[20][20]) *top+=1; strcpy(s[*top],item); char *pop(int *top,char s[20][20]) char *item; item=s[*top]; *top-=1; return item; void pos_to_in(char postfix[], char infix[]) char s[20][20],symbol,temp[2],*op1,*op2; int i,top; top=-1; for(i=0; i<strlen(postfix); i++) symbol=postfix[i]; temp[0]=symbol; temp[1]='\0'; switch(symbol) case '+': case '-': case '*': case '/': case '$': default: op2=pop(&top,s); op1=pop(&top,s); strcpy(infix,"("); strcat(infix,op1); strcat(infix,temp); strcat(infix,op2); strcat(infix,")"); push(infix,&top,s); push(temp,&top,s);

6 main() char postfix[25],infix[25]; printf("enter ur postfix expr\n"); scanf("%s",postfix); pos_to_in(postfix,infix); printf("\nthe equivalent postfix is %s\n",infix); getch(); return 0;

7 /*3.ii) Write a program to convert a infix exp to postfix exp*/ #include<string.h> #include<stdio.h> int index=0,pos=0,lenght,top=-1; char infix[25],postfix[25],stack[25],temp,symbol; main() printf("enter ur infix expr\n"); scanf("%s",infix); in_to_pos(infix,postfix); printf("\nthe equivalent postfix is %s\n",postfix); return 0; in_to_pos(char infix[],char postfix[]) lenght=strlen(infix); push('#'); while(index < lenght) symbol=infix[index]; switch(symbol) case '(': push(symbol); case ')': temp=pop(); while(temp!='(') postfix[pos]=temp; pos++; temp=pop(); case '+': case '-': case '*': case '/': case '$': while(preced(stack[top]) >= preced(symbol) ) temp=pop(); postfix[pos++]=temp; push(symbol);

8 default: postfix[pos++]=symbol; index++; while(top > 0) temp=pop(); postfix[pos++]=temp; push(char symb) top+=1; stack[top]=symb; pop() char symb; symb=stack[top]; top-=1; return symb; int preced(char symb) int p; switch(symb) case '$': p=3; case '*': case '/': p=2; case '+': case '-': p=1; case '#': p=-1; return p;

9 /*4. WAP TO PERFORM AN EVALUATION OF AN POSTFIX EXPRESSION. */ #include<stdio.h> #include<ctype.h> int stack[25],top=-1; main() char postfix[25]; int i=0,value[20],result; printf("enter a valid postfix expr\n"); scanf("%s",postfix); while(postfix[i]!='\0') if(isalpha(postfix[i])) printf("enter the value %c\n",postfix[i]); scanf("%d",&value[i]); i++; result=eval_postfix(postfix,value); printf("the result of %s=%d\n",postfix,result); int eval_postfix(char postfix[],int data[]) int i=0,op1,op2,res; char ch; while(postfix[i]!='\0') ch=postfix[i]; if(isalpha(ch)) push(data[i]); op2=pop(); op1=pop(); switch(ch) case '+': push(op1+op2); case '-': push(op1-op2); case '/': push(op1/op2); case '*': push(op1*op2); case '$': push(op1^op2);

10 i++; res=pop(); return res; int push(int num) top+=1; stack[top]=num; int pop() int num; num=stack[top--]; return num;

11 /*5. WAP TO PERFORM INSERT,DELETE AND DISPLAY OPERATIONS ON A QUEUE USING LINEAR ARRAY. */ #include<stdio.h> #include<conio.h> int i,front,rear,ch,s[3],item; void insert(),delet(),dis(); main() front=0; rear=-1; ch=0; while(ch!=4) printf("\nenter the menu for queue operation\n"); printf("\n1:insert\n2:delete\n3:display\n4:exit\n"); printf("input ur choice\n"); scanf("%d",&ch); switch(ch) case 1: insert(); case 2: delet(); case 3: dis(); case 4: exit(0); default: printf("invalid choice\n"); return 0; void insert() int item; if(rear==3-1) printf("queue is overflow\n"); printf("enter an item to be inserted:"); scanf("%d",&item);

12 rear+=1; s[rear]=item; void delet() if(front>rear) printf("queue is empty\n"); printf("item to be deleted is %d\n",s[front++]); void dis() if(front>rear) printf("queue is empty\n"); printf("\nqueue contains...\n"); for(i=front; i<=rear; i++) printf("%d\t",s[i]);

13 /*6. WAP TO PERFORM INSERT,DELETE AND DISPLAY OPERATIONS ON A QUEUE USING POINTERS. */ #include<stdio.h> #include<conio.h> #define size 3 int i,num,ch,s[3],item[size]; struct queue int items[size]; int front,rear; q; void insert(struct queue *); void delet(struct queue *); void dis(struct queue *); main() q.front=0; q.rear=-1; ch=0; while(ch!=4) printf("\nenter the menu for queue operation\n"); printf("\n1:insert\n2:delete\n3:display\n4:exit\n"); printf("input ur choice\n"); scanf("%d",&ch); switch(ch) case 1: insert(&q); case 2: delet(&q); case 3: dis(&q); case 4: exit(0); default: printf("invalid choice\n"); return 0; void insert(struct queue *q)

14 int item; if(q->rear==size-1) printf("queue Overflow\n"); printf("enter an item to be pushed:"); scanf("%d",&item); q->rear+=1; q->items[q->rear]=item; void delet(struct queue *q) if(q->front>q->rear) printf("queue Undeflow\n"); printf("item to be deleted is %d\n",q->items[q->front++]); void dis(struct queue *q) if(q->front>q->rear) printf("queue is empty\n"); printf("\nqueue contains...\n"); for(i=q->front; i<=q->rear; i++) printf("%d\t",q->items[i]);

15 /* 7. Program to implement Singly linked list to perform addition, deletion & insertion */ #include <stdio.h> #include <conio.h> #include <alloc.h> void create(); void insert(); void delet(); void display(); struct node int data; struct node *link; ; struct node *first=null,*last=null,*next,*prev,*cur; void create() cur=(struct node*)malloc(sizeof(struct node)); printf("\nenter THE DATA: "); scanf("%d",&cur->data); cur->link=null; first=cur; last=cur; void insert() int pos,c=1; cur=(struct node*)malloc(sizeof(struct node)); printf("\nenter THE DATA: "); scanf("%d",&cur->data); printf("\nenter THE POSITION: "); scanf("%d",&pos); if((pos==1) &&(first!=null)) cur->link = first; first=cur; next=first; while(c<pos) prev=next; next=prev->link;

16 c++; if(prev==null) printf("\ninvalid POSITION\n"); cur->link=prev->link; prev->link=cur; void delet() int pos,c=1; printf("\nenter THE POSITION : "); scanf("%d",&pos); if(first==null) printf("\nlist IS EMPTY\n"); if(pos==1 && first->link==null) printf("\n DELETED ELEMENT IS %d\n",first->data); free(first); first=null; if(pos==1 && first->link!=null) cur=first; first=first->link; cur->link=null; printf("\n DELETED ELEMENT IS %d\n",cur->data); free(cur); next=first; while(c<pos) cur=next; next=next->link; c++;

17 cur->link=next->link; next->link=null; if(next==null) printf("\ninvalid POSITION\n"); printf("\n DELETED ELEMENT IS %d\n",next->data); free(next); void display() cur=first; while(cur!=null) printf("\n %d",cur->data); cur=cur->link; void main() int ch; printf("\n\nsingly LINKED LIST"); do printf("\n\n1.create\n2.insert\n3.delete\n4.exit"); printf("\n\nenter YOUR CHOICE : "); scanf("%d",&ch); switch(ch) case 1: create(); display(); case 2: insert(); display(); case 3: delet();

18 display(); case 4: exit(0); default: printf("invalid choice..."); while(1);

19 /*8. WAP to Reverse a single linked list */ #include<malloc.h> struct node int value; struct node *next; ; int main() int item,n; struct node * head; struct node * tail; struct node * temp; struct node * prev; struct node * current; struct node * next; temp=(struct node*)malloc(sizeof(struct node)); head=temp; printf("enter the size of list\n"); scanf("%d",&n); printf("enter the list to be reversed\n"); temp = (struct node *)malloc(sizeof(struct node)); scanf("%d",&item); temp->value = item; head = temp; n--; while(n!=0) temp->next = (struct node *)malloc(sizeof(struct node)); temp = temp->next; scanf("%d",&item); temp->value = item; --n; temp->next = NULL; tail = temp; temp = head; while(temp) printf(" %d\n", temp->value); temp = temp->next;

20 printf("reversing the linked list\n"); prev = NULL; current = next = head; while(current) next = current->next; current->next = prev; prev = current; current = next; temp = tail; while(temp) printf(" %d\n", temp->value); temp = temp->next; return 0;

21 /*9. WAP to accept two singly linked lists & create a new singly linked lists which contains the element that are common in both the lists*/ #include<stdio.h> # include<conio.h> # include <malloc.h> struct node int data; struct node *link; ; struct node *k; void main() int size1,size2,i, num; struct node *ptr,*ptr2,*result,*temp; struct node * concat(struct node *,struct node *); void display(struct node *); void add(struct node **,int ); ptr=null; ptr2 =NULL; result=null; printf("enter the size of 1st list \n"); scanf("%d",&size1); printf("enter the elements\n"); for(i=1;i<=size1;i++) scanf("%d",&num); add(&ptr,num); printf("enter the size of 2st list \n"); scanf("%d",&size2); printf("enter the elements\n"); for(i=1;i<=size2;i++) scanf("%d", &num); add(&ptr2, num); result = concat(ptr,ptr2); printf("common elements in the lists\n"); if(result==null) printf("no common elements\n"); display(result);

22 /* add an node to the list*/ void add(struct node **q,int num) struct node *temp; temp = *q; if(*q==null) *q=malloc(sizeof(struct node)); temp = *q; while((temp->link)!=null) temp=temp->link; temp->link = malloc(sizeof(struct node)); temp=temp->link; temp->data = num; temp->link = NULL; /* display the elements in the list*/ void display(struct node *pt) while(pt!=null) printf(" %d\n",pt->data); pt=pt->link; /* concatenation of lists*/ struct node *concat(struct node *p, struct node *q) struct node *x,*r,*i,*j; if(p==null) printf("no common elements\n");

23 if(q==null) printf("no common elements\n"); x=p; i=q; j=i; while(x!=null) while(i->link!=null && x->data!=i->data) i=i->link; if(i->link==null) x=x->link; i=j; if(x->data==i->data) add(&k,x->data); x=x->link; i=j; return(k);

24 /* 10. WAPto create double linked list to perform addition, deletion, and insertion operation. */ #include<stdio.h> #include<alloc.h> struct node int info; struct node *llink; struct node *rlink; ; typedef struct node *NODE; NODE getnode() NODE x; x=(node)malloc(sizeof(struct node)); if(x==null) printf("out of memory"); return x; NODE insert_front(int item,node head) NODE temp,cur; temp=getnode(); temp->info=item; cur=head->rlink; head->rlink=temp; temp->llink=head; temp->rlink=cur; cur->llink=temp; return head; NODE insert_rear(int item,node head) NODE temp,cur; temp=getnode(); temp->info=item; cur=head->llink; head->llink=temp; temp->rlink=head; /*temp->rlink=cur; */ cur->rlink=temp; return head;

25 NODE delete_front(node head) NODE cur,next; if(head->rlink==head) printf("queue is empty\n"); return head; cur=head->rlink; next=cur->rlink; head->rlink=next; next->llink=head; printf("item deleted=%d\n",cur->info); free(cur); return head; NODE delete_rear(node head) NODE cur,prev; if(head->llink==head) printf("dequeue is empty\n"); return head; cur=head->llink; prev=cur->llink; head->llink=prev; prev->rlink=head; printf("the node to be deletad is %d\n ",cur->info); free(cur); return head; void display(node head) NODE temp; if(head->rlink==head) printf("deque is empty\n"); printf("contents of deque are\n"); temp=head->rlink; while(temp!=head)

26 printf("%d\t",temp->info); temp=temp->rlink; printf("\n"); void main() NODE head; int choice,item; head=getnode(); head->rlink=head; head->llink=head; do printf("1.insert front\t2.insert rear\t3.delete front\n4.delete rear\t5.display\t6.exit\n"); printf("enter your choice\n"); scanf("%d",&choice); switch(choice) case 1:printf("Enter the item to be inserted at the front\n"); scanf("%d",&item); head=insert_front(item,head); case 2:printf("Enter the item\n"); scanf("%d",&item); head=insert_rear(item,head); case 3:head=delete_front(head); case 4:head=delete_rear(head); case 5:display(head); default:exit(0); while(choice!=6);

27 /* 11. WAP TO create, add, remove and display elementsfrom circular linked lists */ #include <stdio.h> #include <malloc.h> struct node int info; struct node *link; *last; main() int choice,n,m,po,i; last=null; while(1) printf("1.create List\n"); printf("2.add at begining\n"); printf("3.add after \n"); printf("4.delete\n"); printf("5.display\n"); printf("6.quit\n"); printf("enter your choice : "); scanf("%d",&choice); switch(choice) case 1: printf("how many nodes you want : "); scanf("%d",&n); for(i=0; i < n;i++) printf("enter the element : "); scanf("%d",&m); create_list(m); case 2: printf("enter the element : "); scanf("%d",&m); addatbeg(m); case 3: printf("enter the element : ");

28 scanf("%d",&m); printf("enter the position after which this element is inserted : "); scanf("%d",&po); addafter(m,po); case 4: if(last == NULL) printf("list underflow\n"); continue; printf("enter the number for deletion : "); scanf("%d",&m); del(m); case 5: display(); case 6: exit(0); default: printf("wrong choice\n"); /*End of switch*/ /*End of while*/ /*End of main()*/ create_list(int num) struct node *q,*tmp; tmp= malloc(sizeof(struct node)); tmp->info = num; if(last == NULL) last = tmp; tmp->link = last; tmp->link = last->link; /*added at the end of list*/ last->link = tmp; last = tmp; /*End of create_list()*/ addatbeg(int num)

29 struct node *tmp; tmp = malloc(sizeof(struct node)); tmp->info = num; tmp->link = last->link; last->link = tmp; /*End of addatbeg()*/ addafter(int num,int pos) struct node *tmp,*q; int i; q = last->link; for(i=0; i < pos-1; i++) q = q->link; if(q == last->link) printf("there are less than %d elements\n",pos); /*End of for*/ tmp = malloc(sizeof(struct node) ); tmp->link = q->link; tmp->info = num; q->link = tmp; if(q==last) /*Element inserted at the end*/ last=tmp; /*End of addafter()*/ del(int num) struct node *tmp,*q; if( last->link == last && last->info == num) /*Only one element*/ tmp = last; last = NULL; free(tmp); q = last->link; if(q->info == num) tmp = q;

30 last->link = q->link; free(tmp); while(q->link!= last) if(q->link->info == num) /*Element deleted in between*/ tmp = q->link; q->link = tmp->link; free(tmp); printf("%d deleted\n",num); q = q->link; /*End of while*/ if(q->link->info == num) /*Last element deleted q->link=last*/ tmp = q->link; q->link = last->link; free(tmp); last = q; printf("element %d not found\n",num); /*End of del()*/ display() struct node *q; if(last == NULL) printf("list is empty\n"); q = last->link; printf("list is :\n"); while(q!= last) printf("%d ", q->info); q = q->link; printf("%d\n",last->info); /*End of display()*/

31 /*12. WAP TO IMPLEMENT STACK USING LISTS. */ #include<stdio.h> typedef struct stack int data; struct stack *ptr; node; main() node *top; int data,rpt=1,choice; top=null; printf("\n using single linked list\n"); while(rpt) printf("\n1.push\n2.pop\n3.display\n4.exit\n"); printf("\n enter ur choice\n"); scanf("%d",&choice); switch(choice) case 1:printf("\n enter data\n"); scanf("%d",&data); push(data,&top); case 2:if(top==NULL) printf("\nstack underflow\n"); data=pop(&top); printf("\ndeleted item=%d",data); case 3:display(&top); case 4:exit(0); printf("\ndo u want to continue(type 1 or 0)\n"); scanf("%d",&rpt); node *getnode(int data)

32 node *temp; temp=(node*)malloc(sizeof(node)); if(temp==null) printf("cannot allocate memory\n"); temp->data=data; temp->ptr=null; return(temp); push(int data,node **top) node *newnode; newnode=getnode(data); newnode->ptr=*top; *top=newnode; pop(node **top) node *temp; int data; data=(*top)->data; temp=*top; *top=(*top)->ptr; free(temp); return(data); display(node **listptr) node *temp; temp=*listptr; if(temp==null) printf("\nstack is empty\n"); while(temp!=null) printf("%d\t",temp->data); temp=temp->ptr;

33 /*13. WAP FOR IMPLEMENTATION OF QUEUES USING LISTS */ #include<stdio.h> typedef struct queue int data; struct queue *ptr; Q; Q *front,*rear; Q *getnode(q *temp) temp=(q*)malloc(sizeof(q)); temp->ptr=null; return(temp); insert() Q *new; new=null; new=getnode(new); printf("\nenter data\n"); scanf("%d",&new->data); if(front==null) front=rear=new; rear->ptr=new; rear=rear->ptr; Q *delete() Q *temp; temp=front; if(front==null) printf("\nqueue underflow\n"); printf("the deleted element is %d\n",temp->data); front=front->ptr; free(temp); return(front);

34 display(q *front) Q *temp; if(front==null) printf("queue is empty\n"); printf("status of the Queue\n"); for(temp=front;temp!=rear->ptr;temp=temp->ptr) printf("%d\t",temp->data); main() int rpt=1,choice; front=null; rear=null; while(rpt) printf("1.insert\n2.delete\n3.display\n4.exit\n"); printf("enter your choice\n"); scanf("%d",&choice); switch(choice) case 1:insert(); case 2:front=delete(); case 3:display(front); case 4:exit(0); printf("\ndo u wanna continue (type 1 or 0)\n"); scanf("%d",&rpt);

35 /*14. WAP to create a tree and perform inorder, preoder &postorder tree traversal techniques.*/ #include<stdio.h> #include<process.h> #include<conio.h> struct node struct node *left; int item; struct node *right; ; int number,num,ch,x; struct node *tree,*p,*q; void inorder(struct node*); void preorder(struct node*); void postorder(struct node*); void main() void create(struct node*,int); tree=(struct node*)malloc(sizeof(struct node)); printf("input numbers one per line\n"); printf("press ctrl+z for EOF\n"); scanf("%d",&num); tree->item=num; tree->left=null; tree->right=null; while(scanf("%d",&num)!=eof) create(tree,num); do printf("1...inorder traversal\n"); printf("2...preorder traversal\n"); printf("3...postorder traversal\n"); printf("4...exit\n"); printf("enter the ur choice\n"); scanf("%d",&ch); switch(ch) case 1: printf("inorder traversal of a tree\n"); inorder(tree);

36 case 2: printf("preorder traversal of a tree\n"); preorder(tree); case 3: printf("postorder traversal of a tree\n"); postorder(tree); while(ch!=4); void create(struct node *p, int n) if(n >p->item) if(p->right==null) p->right=(struct node *)malloc(sizeof(struct node)); p=p->right; p->item=n; p->left=null; p->right=null; create(p->right,n); if(n<p->item) if(p->left==null) p->left=(struct node*)malloc(sizeof(struct node)); p=p->left; p->item=n; p->left=null; p->right=null; create(p->left,n); printf("number ios duplicate\n");

37 void inorder(struct node *p) if(p!=null) inorder(p->left); printf("%d\t",p->item); inorder(p->right); void preorder(struct node *p) if(p!=null) printf("%d\t",p->item); preorder(p->left); preorder(p->right); void postorder(struct node *p) if(p!=null) postorder(p->left); postorder(p->right); printf("%d\t",p->item);

38 /*15. Write a Program to construct Binary Search Tree and count number of leaves in binary tree*/ #include<stdio.h> #include<process.h> #include<conio.h> struct node struct node *left; int item; struct node *right; ; int number,num,ch,x; struct node *tree,*p,*q; void dis(struct node*); struct node* insert(struct node*,int); struct node* delet(struct node*,int); void main() void create(struct node*,int); tree=(struct node*)malloc(sizeof(struct node)); printf("input numbers one per line\n"); printf("press ctrl+z for EOF\n"); scanf("%d",&num); tree->item=num; tree->left=null; tree->right=null; while(scanf("%d",&num)!=eof) create(tree,num); do printf("1...search an data\n"); printf("2...display traversal\n"); printf("3...insert an data\n"); printf("4...delete an data\n"); printf("5...exit\n"); printf("enter the ur choice\n"); scanf("%d",&ch); switch(ch) case 1: search(); case 2:

39 printf("inorder traversal of a tree\n"); dis(tree); case 3: printf("input node value to insert\n"); scanf("%d",&num); tree=insert(tree,num); case 4: printf("input node value to delete \n"); scanf("%d",&x); tree=delet(tree,x); while(ch!=5); void create(struct node *p, int n) if(n >p->item) if(p->right==null) p->right=(struct node *)malloc(sizeof(struct node)); p=p->right; p->item=n; p->left=null; p->right=null; create(p->right,n); if(n<p->item) if(p->left==null) p->left=(struct node*)malloc(sizeof(struct node)); p=p->left; p->item=n; p->left=null; p->right=null;

40 create(p->left,n); printf("number ios duplicate\n"); search() printf("enter the number to search\n"); scanf("%d",&number); p=q=tree; while(number!=p->item && q!=null) p=q; if(number < p->item) q=p->left; q=p->right; if(number==p->item) printf("%d is Found\n",number); printf("unsuccessful search\n"); void dis(struct node *p) if(p!=null) dis(p->left); printf("%d\t",p->item); dis(p->right); struct node* insert(struct node *p, int n) struct node *temp,*prev,*cur; temp=(struct node*)malloc(sizeof(struct node)); temp->item=n; temp->left=null;

41 temp->right=null; if(p==null) return temp; cur=p; while(cur!=null) prev=cur; cur=(n<cur->item)?cur->left:cur->right; if(n<prev->item) prev->left=temp; prev->right=temp; return p; struct node* delet(struct node *p,int n) struct node *parent, *cur, *pred, *suc, *q; if (p==null) printf("enmty tree"); return(p); cur=p; while(cur!=null && n!=cur->item) parent=cur; cur=(n<cur->item)?cur->left:cur->right; if(cur==null) printf("node to be deleted is not found\n"); return p; if(cur->left==null) q=cur->right; if(cur->right==null) q=cur->left;

42 suc=cur->right; if(suc->left==null) suc->left=cur->left; q=suc; pred=cur->right; suc=pred->left; while(suc->left!=null) pred=suc; suc=pred->left; pred->left=suc->right; suc->left=cur->left; suc->right=cur->left; q=suc; if(parent->left==cur) parent->left=q; parent->right=q; free(cur); return p;

UNIT 4: Linked List Programs demonstrated in class. Tojo Mathew Asst. Professor CSE Dept., NIE Mysuru.

UNIT 4: Linked List Programs demonstrated in class. Tojo Mathew Asst. Professor CSE Dept., NIE Mysuru. UNIT 4: Linked List Programs demonstrated in class. Tojo Mathew Asst. Professor CSE Dept., NIE Mysuru. 1 Table of Contents 1. Array Implementation of Linked List...3 2. Queue using Array Implementation

More information

This document can be downloaded from with most recent updates. 1 Data Structures using C: Module 4 (16MCA11) LINKED LISTS

This document can be downloaded from   with most recent updates. 1 Data Structures using C: Module 4 (16MCA11) LINKED LISTS 1 Data Structures using C: Module 4 (16MCA11) LINKED LISTS 4.1 MEMORY MANAGEMENT 4.1.1 Basics about Memory When a C program is compiled, the compiler translates the source code into machine code. Now the

More information

Government Girls Polytechnic, Bilaspur

Government Girls Polytechnic, Bilaspur Government Girls Polytechnic, Bilaspur Name of the Lab: Programming Lab Practical: Data Structure Lab Class: 4 th Semester (Computer Science & Engineering) Teachers Assessment: 30 End Semester Examination:70

More information

Module III. Linear Data Structures and their Linked Storage Representation

Module III. Linear Data Structures and their Linked Storage Representation Module III Linear Data Structures and their Linked Storage Representation 3.1 Linked List Linked list is the collection of inter connected nodes with a head node representing the first node and a tail

More information

Darshan Institute of Engineering & Technology for Diploma Studies Unit 3

Darshan Institute of Engineering & Technology for Diploma Studies Unit 3 Linear and Non-Linear Data Structures Linear data structure: Linear data structures are those data structure in which data items are arranged in a linear sequence by physically or logically or both the

More information

UNIT 2: STACK & RECURSION Programs demonstrated in class. Tojo Mathew Asst. Professor CSE Dept., NIE Mysuru.

UNIT 2: STACK & RECURSION Programs demonstrated in class. Tojo Mathew Asst. Professor CSE Dept., NIE Mysuru. UNIT 2: STACK & RECURSION Programs demonstrated in class. Tojo Mathew Asst. Professor CSE Dept., NIE Mysuru. Table of Contents 1. C Program to Check for balanced parenthesis by using Stacks...3 2. Program

More information

MODULE V: POINTERS & PREPROCESSORS

MODULE V: POINTERS & PREPROCESSORS MODULE V: POINTERS & PREPROCESSORS INTRODUCTION As you know, every variable is a memory-location and every memory-location has its address defined which can be accessed using ampersand(&) operator, which

More information

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of MCA

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of MCA USN 1 P E PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of MCA INTERNAL ASSESSMENT TEST 2 (Scheme and Solution) Data Structures Using C (16MCA11) 1) A.

More information

STACKS 3.1 INTRODUCTION 3.2 DEFINITION

STACKS 3.1 INTRODUCTION 3.2 DEFINITION STACKS 3 3.1 INTRODUCTION A stack is a linear data structure. It is very useful in many applications of computer science. It is a list in which all insertions and deletions are made at one end, called

More information

AIM:- To write a C program to create a singly linked list implementation.

AIM:- To write a C program to create a singly linked list implementation. SINGLY LINKED LIST AIM:- To write a C program to create a singly linked list implementation. ALGORITHM:- 1. Start the program. 2. Get the choice from the user. 3. If the choice is to add records, get the

More information

Data Structures and Applications (17CS33)

Data Structures and Applications (17CS33) 3.7 Reversing a Singly Linked List #include #include struct node int data; struct node *next; ; void insert_list(int); void display(); void revers(); struct node *head,*newnode,*tail,*temp,*temp1,*temp2;

More information

Sree Vidyanikethan Engineering College Sree Sainath Nagar, A. Rangampet

Sree Vidyanikethan Engineering College Sree Sainath Nagar, A. Rangampet Sree Vidyanikethan Engineering College Sree Sainath Nagar, A. Rangampet 517 102 Department of Computer Science and Engineering I B. Tech C Programming Language Lab Title: Stack SVEC/IT/EXPT-CP-21 PROBLEM

More information

/*Addition of two polynomials*/ #include<stdio.h> #include<malloc.h> #include<conio.h> struct link { int coeff; int pow; struct link *next; }; struct

/*Addition of two polynomials*/ #include<stdio.h> #include<malloc.h> #include<conio.h> struct link { int coeff; int pow; struct link *next; }; struct /*Addition of two polynomials*/ #include #include #include struct link int coeff; int pow; struct link *next; ; struct link *poly1=null,*poly2=null,*poly=null; void create(struct

More information

Frequently asked Data Structures Interview Questions

Frequently asked Data Structures Interview Questions Frequently asked Data Structures Interview Questions Queues Data Structure Interview Questions How is queue different from a stack? The difference between stacks and queues is in removing. In a stack we

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) WINTER 18 EXAMINATION Subject Name: Data Structure using C Model wer Subject Code: 22317 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given

More information

DS Lab Manual -17CS33

DS Lab Manual -17CS33 Chethan Raj C Assistant Professor Dept. of CSE 6. Design, Develop and Implement a menu driven Program in C for the following operations on Circular QUEUE of Characters (Array Implementation of Queue with

More information

Application of Stack (Backtracking)

Application of Stack (Backtracking) Application of Stack (Backtracking) Think of a labyrinth or maze How do you find a way from an entrance to an exit? Once you reach a dead end, you must backtrack. But backtrack to where? to the previous

More information

Linked List in Data Structure. By Prof. B J Gorad, BECSE, M.Tech CST, PHD(CSE)* Assistant Professor, CSE, SITCOE, Ichalkaranji,Kolhapur, Maharashtra

Linked List in Data Structure. By Prof. B J Gorad, BECSE, M.Tech CST, PHD(CSE)* Assistant Professor, CSE, SITCOE, Ichalkaranji,Kolhapur, Maharashtra Linked List in Data Structure By Prof. B J Gorad, BECSE, M.Tech CST, PHD(CSE)* Assistant Professor, CSE, SITCOE, Ichalkaranji,Kolhapur, Maharashtra Linked List Like arrays, Linked List is a linear data

More information

I YEAR, II SEM B.TECH

I YEAR, II SEM B.TECH Data Structures Laboratory Manual I YEAR, II SEM B.TECH Department of Computer Science & Engineering Data Structures Laboratory Manual Department of Computer Science & Engineering Document No: Date of

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) WINTER 16 EXAMINATION Model Answer Subject Code:

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) WINTER 16 EXAMINATION Model Answer Subject Code: Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The model answer and the answer written by candidate

More information

Solution for Data Structure

Solution for Data Structure Solution for Data Structure May 2016 INDEX Q1 a 2-3 b 4 c. 4-6 d 7 Q2- a 8-12 b 12-14 Q3 a 15-18 b 18-22 Q4- a 22-35 B..N.A Q5 a 36-38 b N.A Q6- a 39-42 b 43 1 www.brainheaters.in Q1) Ans: (a) Define ADT

More information

MC9217 / Programming and Data Structures Lab MC9217 PROGRAMMING AND DATA STRUCTURES LAB L T P C

MC9217 / Programming and Data Structures Lab MC9217 PROGRAMMING AND DATA STRUCTURES LAB L T P C MC9217 PROGRAMMING AND DATA STRUCTURES LAB L T P C 0 0 3 2 1.Create a Stack and do the following operations using arrays and linked lists (i)push (ii) Pop (iii) Peep 2.Create a Queue and do the following

More information

DEV BHOOMI INSTITUTE OF TECHNOLOGY

DEV BHOOMI INSTITUTE OF TECHNOLOGY DEV BHOOMI INSTITUTE OF TECHNOLOGY Department of Computer Science and Engineering Year: 2nd Semester: 3rd Data Structures- PCS-303 LAB MANUAL Prepared By: HOD(CSE) DEV BHOOMI

More information

POLYNOMIAL ADDITION. AIM:- To write a C program to represent a polynomial as a linked list and write functions for polynomial addition.

POLYNOMIAL ADDITION. AIM:- To write a C program to represent a polynomial as a linked list and write functions for polynomial addition. POLYNOMIAL ADDITION AIM:- To write a C program to represent a polynomial as a linked list and write functions for polynomial addition. ALGORITHM:- 1. Start the program 2. Get the coefficients and powers

More information

UNIT 3: QUEUE Programs demonstrated in class. Tojo Mathew Asst. Professor CSE Dept., NIE Mysuru.

UNIT 3: QUEUE Programs demonstrated in class. Tojo Mathew Asst. Professor CSE Dept., NIE Mysuru. UNIT 3: QUEUE Programs demonstrated in class. Tojo Mathew Asst. Professor CSE Dept., NIE Mysuru. Table of Contents 1. Simple Queue Implementation with arrays...3 2. Circular queue with global container

More information

Data accessing is faster because we just need to specify the array name and the index of the element to be accssed.. ie arrays are simple to use

Data accessing is faster because we just need to specify the array name and the index of the element to be accssed.. ie arrays are simple to use Module 3 Linear data structures and linked storage representation Advantages of arrays Linear data structures such as stacks and queues can be represented and implemented using sequential allocation ie

More information

Basically queue is nothing but an array or a vector with a maximum capacity of size. Front=1 Front=1 REAR=2. Front=1 REAR=3 Front=1 REAR=4 Q is Full

Basically queue is nothing but an array or a vector with a maximum capacity of size. Front=1 Front=1 REAR=2. Front=1 REAR=3 Front=1 REAR=4 Q is Full Queue A Queue is defined as linear list in which insertion is taking place at one end and deletion is taking place at the other end. The end where insertion is taking place is called as rear end. The end

More information

Model Solution for QP CODE : ( 3 Hours )

Model Solution for QP CODE : ( 3 Hours ) Model Solution for QP CODE : 24788 ( 3 Hours ) All answers are for reference only. Any alternate answer that solves the problem should be considered eqully valid. 1. (a) Define data structure? Give its

More information

DATA STRUCTURES LAB MANUAL USING C (CS,IT,MCA)

DATA STRUCTURES LAB MANUAL USING C (CS,IT,MCA) DATA STRUCTURES LAB MANUAL USING C (CS,IT,MCA) DATA STRUCTURES LAB LIST OF EXPERIMENTS 1) Write a program to perform the following in one dimensional array, Insertion, Deletion, and Searching (Linear and

More information

Prepared By:- Dinesh Sharma Asstt. Professor, CSE & IT Deptt. ITM Gurgaon

Prepared By:- Dinesh Sharma Asstt. Professor, CSE & IT Deptt. ITM Gurgaon Data Structures &Al Algorithms Prepared By:- Dinesh Sharma Asstt. Professor, CSE & IT Deptt. ITM Gurgaon What is Data Structure Data Structure is a logical relationship existing between individual elements

More information

DEPARTMENT OF COMPUTER SCEINCE AND ENGINEERING DATA STRUCTURES LABORATORY. Subject Code: 17CSL38. B.E - III Semester. Academic Year:

DEPARTMENT OF COMPUTER SCEINCE AND ENGINEERING DATA STRUCTURES LABORATORY. Subject Code: 17CSL38. B.E - III Semester. Academic Year: Channabasaveshwara Institute of Technology (Affiliated to VTU, Belgaum & Approved by AICTE, New Delhi) (NAAC Accredited & ISO 9001:2015 Certified Institution) NH 206 (B.H. Road), Gubbi, Tumkur 572 216.

More information

DATA STRUCTURES LAB MANUAL

DATA STRUCTURES LAB MANUAL DATA STRUCTURES LAB MANUAL Year : 2016-2017 Course Code : ACS102 Regulations : R16 Semester : I B.Tech II Semester Branch : CSE / IT Prepared by Ms. N. JAYANTHI ASSOCIATE PROFESSOR INSTITUTE OF AERONAUTICAL

More information

Vivekananda College of Engineering & Technology. Data Structures and Applications

Vivekananda College of Engineering & Technology. Data Structures and Applications Vivekananda College of Engineering & Technology [Sponsored by Vivekananda Vidyavardhaka Sangha, Puttur ] Affiliated to Visvesvaraya Technological University Approved by AICTE New Delhi & Govt of Karnataka

More information

S.Y. Diploma : Sem. III [CO/CM/IF/CD/CW] Data Structure using C

S.Y. Diploma : Sem. III [CO/CM/IF/CD/CW] Data Structure using C S.Y. Diploma : Sem. III [CO/CM/IF/CD/CW] Data Structure using C Time: 3 Hrs.] Prelim Question Paper Solution [Marks : 100 Q.1 (a) Attempt any SIX of the following : [12] Q.1 (a) (i) Define time complexity

More information

Guide for The C Programming Language Chapter 5

Guide for The C Programming Language Chapter 5 1. Differentiate between primitive data type and non-primitive data type. Primitive data types are the basic data types. These data types are used to represent single values. For example: Character, Integer,

More information

DATA STRUCTURE. o DYNAMIC MEMORY. ALLOCATION o SELF-REFERENTIAL STRUCTURE o TYPEDEF LINK LIST STACK QUEUE TREE

DATA STRUCTURE. o DYNAMIC MEMORY. ALLOCATION o SELF-REFERENTIAL STRUCTURE o TYPEDEF LINK LIST STACK QUEUE TREE DATA STRUCTURE TOPICS PAGE o DYNAMIC MEMORY 2-5 ALLOCATION o SELF-REFERENTIAL STRUCTURE o TYPEDEF LINK LIST 5-16 STACK 17-28 o APPLICATION OF STACK 28-38 QUEUE 39-43 TREE o BINARY SEARCH TREE o HEAP GRAPH

More information

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Computer Science and Engineering

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Computer Science and Engineering USN 1 P E PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Computer Science and Engineering SOLUTION FOR INTERNAL ASSESSMENT TEST 2 Date : 6/10/2017 Marks:

More information

PESIT Bangalore South Campus

PESIT Bangalore South Campus TEST - 2 Date : 29-9-2014 Marks : 50 Subject & Code : DS(10CS35) Class : III CSE &ISE Name of faculty : Dr.JSP/Mrs.Vandana/Mrs.Renuka Time : 11.30AM to 1 PM Note: Answer any 5 Questions 1 Write a C program

More information

Fundamentals of Programming & Procedural Programming

Fundamentals of Programming & Procedural Programming Universität Duisburg-Essen PRACTICAL TRAINING TO THE LECTURE Fundamentals of Programming & Procedural Programming Session Eight: Math Functions, Linked Lists, and Binary Trees Name: First Name: Tutor:

More information

/****************************************** Application: Linked List Example Compiled on: Borland Turbo C++ 3.0

/****************************************** Application: Linked List Example Compiled on: Borland Turbo C++ 3.0 /****************************************** Application: Linked List Example Compiled on: Borland Turbo C++ 3.0 ******************************************/ #include #include /* Structure

More information

Procedural Programming

Procedural Programming Exercise 6 (SS 2016) 04.07.2015 What will I learn in the 6. exercise Math functions Dynamic data structures (linked Lists) Exercise(s) 1 Home exercise 4 (3 points) Write a program which is able to handle

More information

Dev Bhoomi Institute Of Technology. Department of Computer Application EXPERIMENT NO. ISSUE NO. : ISSUE DATE: REV. NO. : REV.

Dev Bhoomi Institute Of Technology. Department of Computer Application EXPERIMENT NO. ISSUE NO. : ISSUE DATE: REV. NO. : REV. LIST OF PRACTICALS 1. Matrix Operations-Add and Multiply 2. String Operations strlen(), strcat() etc. 3. Stack operations using Arrays. 4. Implementing Polish Notations using Stacks. 5. Evaluating postfix

More information

Bachelor of Engineering First Year II SEMESTER CS6212 PROGRAMMING AND DATA STRUCTURES LABORATORY I LAB MANUAL DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Page 1 CS6212 PROGRAMMING AND DATA STRUCTURES

More information

Trees. Linear access time of linked lists is prohibitive

Trees. Linear access time of linked lists is prohibitive Trees Linear access time of linked lists is prohibitive Does there exist any simple data structure for which the running time of most operations (search, insert, delete) is O(log N)? Linked list is a linear

More information

This documentation is for reference purpose only and is for those who have attended the classroom sessions at Thinking Machines

This documentation is for reference purpose only and is for those who have attended the classroom sessions at Thinking Machines Thinking Machines Data Structures Get the highest paid jobs as programmers Page 1 This documentation is for reference purpose only and is for those who have attended the classroom sessions at Thinking

More information

Unit-2. Stacks: Introduction-Definition-Representation of Stack-Operations on Stacks- Applications of Stacks.

Unit-2. Stacks: Introduction-Definition-Representation of Stack-Operations on Stacks- Applications of Stacks. Unit-2 Stacks: Introduction-Definition-Representation of Stack-Operations on Stacks- Applications of Stacks. Queues: Introduction, Definition- Representations of Queues- Various Queue Structures- Applications

More information

The Queues. Front. Rear. Front. Rear. Rear = 0 Front = 0. Fig Queue is empty. Fig push(10) Rear = 1 Front = 0. Fig. 4.3.

The Queues. Front. Rear. Front. Rear. Rear = 0 Front = 0. Fig Queue is empty. Fig push(10) Rear = 1 Front = 0. Fig. 4.3. 4 The Queues A queue is logically a first in first out (FIFO or first come first serve) linear data structure. The concept of queue can be understood by our real life problems. For example a customer come

More information

NCS 301 DATA STRUCTURE USING C

NCS 301 DATA STRUCTURE USING C NCS Data Structure Using C -8- NCS DATA STRUCTURE USING C Unit- Part- Stack Hammad Mashkoor Lari Assistant Professor Allenhouse Institute of Technology www.ncsds.wordpress.com Introduction Stack is a non

More information

Programming. Lists, Stacks, Queues

Programming. Lists, Stacks, Queues Programming Lists, Stacks, Queues Summary Linked lists Create and insert elements Iterate over all elements of the list Remove elements Doubly Linked Lists Circular Linked Lists Stacks Operations and implementation

More information

UNIT VI. STACKS AND QUEUES

UNIT VI. STACKS AND QUEUES UNIT VI. STACKS AND QUEUES Syllabus: /*-------------------------------------------------------------------------*/ Stack: Definition: "Stack is an ordered collection of data elements having similar data

More information

Binary Trees. Examples:

Binary Trees. Examples: Binary Trees A tree is a data structure that is made of nodes and pointers, much like a linked list. The difference between them lies in how they are organized: In a linked list each node is connected

More information

Module III. Linear Data Structures and their Linked Storage Representation

Module III. Linear Data Structures and their Linked Storage Representation Module III Linear Data Structures and their Linked Storage Representation 3.1 Linked List Linked list is the collection of inter connected nodes with a head node representing the first node and a tail

More information

INDEX BUBBLE SORT INSERTION SORT SELECTION SORT PATTREN MATCHING LINEAR SEARCH BINARY SEARCH QUICK SORT MERGE SORT STACK OPERATION USING ARRAY

INDEX BUBBLE SORT INSERTION SORT SELECTION SORT PATTREN MATCHING LINEAR SEARCH BINARY SEARCH QUICK SORT MERGE SORT STACK OPERATION USING ARRAY INDEX S.No. Date Title Page No. Teacher s Sign 1. BUBBLE SORT 2. INSERTION SORT 3. SELECTION SORT 4. PATTREN MATCHING 5. LINEAR SEARCH 6. BINARY SEARCH 7. QUICK SORT 8. MERGE SORT 9. STACK OPERATION USING

More information

Single linked list. Program: #include<stdio.h> #include<conio.h> #include<alloc.h> struct node. int info; struct node *next; void main()

Single linked list. Program: #include<stdio.h> #include<conio.h> #include<alloc.h> struct node. int info; struct node *next; void main() Single linked list Program: #include #include #include struct node int info; struct node *next; ; void main() struct node *s,*start,*prev,*new1,*temp,*temp1,*ptemp; int cho,i,j,x,n,p;

More information

DATA STRUCTURE. 1. malloc() 2. calloc()

DATA STRUCTURE. 1. malloc() 2. calloc() Question : Explain the Dynamic Memory Allocation and following function. When we declare an array in out program, the compiler allocates memory to hold the array prior to providing it. Some times it is

More information

UNIT-2 Stack & Queue

UNIT-2 Stack & Queue UNIT-2 Stack & Queue 59 13. Stack A stack is an Abstract Data Type (ADT), commonly used in most programming languages. It is named stack as it behaves like a real-world stack, for example a deck of cards

More information

Implementation of Singly Linked List. To write a program to implement the concept of singly linked list.

Implementation of Singly Linked List. To write a program to implement the concept of singly linked list. Ex. No: Date: Implementation of Singly Linked List. AIM: To write a program to implement the concept of singly linked list. ALGORITHM: 1. Start 2. Creation: Get the number of elements, and create the nodes

More information

Write a C program to add two Complex numbers using functions illustrating-

Write a C program to add two Complex numbers using functions illustrating- Scheme of valuvation Date : 29/8/2017 Marks: 40 Subject & Code : Data Structures and Applications (15CS33) Class : III A&B Name of Faculty : Ms. Saritha Time : 8:30 am to 10 am NOTE: ANSWER All FIVE QUESTIONS

More information

Module 04 Trees Contents

Module 04 Trees Contents Module 04 Trees Contents Chethan Raj C Assistant Professor Dept. of CSE 1. Trees Terminology 2. Binary Trees, Properties of Binary trees 3. Array and linked Representation of Binary Trees 4. Binary Tree

More information

Procedural Programming & Fundamentals of Programming

Procedural Programming & Fundamentals of Programming & Fundamentals of Programming Exercise 4 (SS 2018) 12.06.2018 What will I learn in the 5. exercise Files Math functions Dynamic data structures (linked Lists) Exercise(s) 1 Files A file can be seen as

More information

/*Tree Traversals*/ #include<stdio.h> #include<conio.h> typedef struct bin { int data; struct bin *left,*right; }node;

/*Tree Traversals*/ #include<stdio.h> #include<conio.h> typedef struct bin { int data; struct bin *left,*right; }node; /*Tree Traversals*/ #include #include typedef struct bin int data; struct bin *left,*right; node; void insert(node *,node *); void inorder(node *); void preorder(node *); void postorder(node

More information

/* Polynomial Expressions Using Linked List*/ #include<stdio.h> #include<conio.h> #include <malloc.h> struct node. int num; int coeff;

/* Polynomial Expressions Using Linked List*/ #include<stdio.h> #include<conio.h> #include <malloc.h> struct node. int num; int coeff; /* Polynomial Expressions Using Linked List*/ #include #include #include struct node int num; int coeff; struct node *next; ; struct node *start1 = NULL; struct node *start2

More information

Information Technology Association Department of Information Technology MIT Campus, Anna University Chennai

Information Technology Association Department of Information Technology MIT Campus, Anna University Chennai Algorithm Puzzles - Week1 Solutions 1. Swap two integer variables without using temporary variable. Give at least two different solutions. The first solution is a=a+b; b=a-b; a=a-b; Hope most of you are

More information

CS6202 - PROGRAMMING & DATA STRUCTURES I Unit IV Part - A 1. Define Stack. A stack is an ordered list in which all insertions and deletions are made at one end, called the top. It is an abstract data type

More information

PESIT Bangalore South Campus Hosur road, 1km before ElectronicCity, Bengaluru -100 Department of Basic Science and Humanities

PESIT Bangalore South Campus Hosur road, 1km before ElectronicCity, Bengaluru -100 Department of Basic Science and Humanities INTERNAL ASSESSMENT TEST-3 Date : 12-05-2016 Marks: 40 Subject & Code : Programming in C and data structures (15PCD23) Sec : F,G,H,I,J,K Name of faculty :Dr J Surya Prasad/Mr.Sreenath M V/Ms.Monika/ Time

More information

Stack & Queue on Self-Referencing Structures

Stack & Queue on Self-Referencing Structures C Programming 1 Stack & Queue on Self-Referencing Structures C Programming 2 Representation of Stack struct stack { int data ; struct stack *next ; ; typedef struct stacknode node, *stack ; C Programming

More information

Stacks. CONTENTS 3.1 Introduction 1. Stack as an abstract data type 2. Representation of a Stack as an array 3.2Applications of Stack.

Stacks. CONTENTS 3.1 Introduction 1. Stack as an abstract data type 2. Representation of a Stack as an array 3.2Applications of Stack. Stacks CONTENTS 3.1 Introduction 1. Stack as an abstract data type 2. Representation of a Stack as an array 3.2Applications of Stack Hours: 12 Marks: 18 3.1 Introduction to Stacks 1. Stack as Abstract

More information

SINGLE LINKED LIST. Algorithm for allocating memory for the new node

SINGLE LINKED LIST. Algorithm for allocating memory for the new node SRI CHANDRASEKHARENDRA SARASWATHI VISWA MAHAVIDYALAYA SCSVMV UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Faculty: S.Gokulakrishnan AP/CSE SINGLE LINKED LIST Aim:- Write a C program to implement

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) WINTER 17 EXAMINATION Subject Name: Data Structure Using C Model Answer Subject Code: 17330 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as

More information

//1 linked list. #include <stdio.h> #include <stdlib.h>

//1 linked list. #include <stdio.h> #include <stdlib.h> #include #include //1 linked list struct node//node of linked list int val;//value part struct node *addr;//address of next node ; struct node *start;//holds address of first node,

More information

ESc101: (Linear, Circular, Doubly) Linked Lists, Stacks, Queues, Trees. Introduction to Linked Lists

ESc101: (Linear, Circular, Doubly) Linked Lists, Stacks, Queues, Trees. Introduction to Linked Lists ESc101: (Linear, Circular, Doubly) Linked Lists, Stacks, Queues, Trees Instructor: Krithika Venkataramani Semester 2, 2011-2012 1 Introduction to Linked Lists Each bead connected to the next through a

More information

What is recursion. WAP to find sum of n natural numbers using recursion (5)

What is recursion. WAP to find sum of n natural numbers using recursion (5) DEC 2014 Q1 a What is recursion. WAP to find sum of n natural numbers using recursion (5) Recursion is a phenomenon in which a function calls itself. A function which calls itself is called recursive function.

More information

Stack & Queue on Self-Referencing Structures

Stack & Queue on Self-Referencing Structures PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 1 Stack & Queue on Self-Referencing Structures PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 2 Representation of Stack struct stack { int data ; struct

More information

SRI CHANDRASEKHARENDRA SARASWATHI VISWA MAHAVIDYALAYA (UNIVERSITY ESTABLISHED UNDER SECTION 3 OF UGC ACT 1956) ENATHUR - KANCHIPURAM

SRI CHANDRASEKHARENDRA SARASWATHI VISWA MAHAVIDYALAYA (UNIVERSITY ESTABLISHED UNDER SECTION 3 OF UGC ACT 1956) ENATHUR - KANCHIPURAM SRI CHANDRASEKHARENDRA SARASWATHI VISWA MAHAVIDYALAYA (UNIVERSITY ESTABLISHED UNDER SECTION 3 OF UGC ACT 1956) ENATHUR - KANCHIPURAM 631 561 DATA STRUCTURES LAB LABORATORY RECORD Name : Register. No :

More information

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING LAB MANUAL. Academic Year: ODD SEMESTER

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING LAB MANUAL. Academic Year: ODD SEMESTER DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING LAB MANUAL Academic Year: 2015-16 ODD SEMESTER Programme (UG/PG) : UG Semester : IV Course Code : CS1032 Course Title : Data Structures & Algorithms Lab Prepared

More information

Now consider the following situation after deleting three elements from the queue...

Now consider the following situation after deleting three elements from the queue... Scheme of valuvation -1I Subject & Code : Data Structure and Application (15CS33) NOTE: ANSWER All FIVE QUESTIONS 1 Explain the diadvantage of linear queue and how it i olved in circular queue. Explain

More information

DC104 DATA STRUCTURE JUNE Q.2 a. If you are using C language to implement the heterogeneous linked list, what pointer type will you use?

DC104 DATA STRUCTURE JUNE Q.2 a. If you are using C language to implement the heterogeneous linked list, what pointer type will you use? Q.2 a. If you are using C language to implement the heterogeneous linked list, what pointer type will you use? The heterogeneous linked list contains different data types in its nodes and we need a link

More information

Scheme of valuations-test 3 PART 1

Scheme of valuations-test 3 PART 1 Scheme of valuations-test 3 PART 1 1 a What is string? Explain with example how to pass string to a function. Ans A string constant is a one-dimensional array of characters terminated by a null ( \0 )

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in themodel answer scheme. 2) The model answer and the answer written by candidate may

More information

LAB MANUAL DATA STRUCTURES & ALGORITHMS (CSE-205-F) III SEMESTER ECS

LAB MANUAL DATA STRUCTURES & ALGORITHMS (CSE-205-F) III SEMESTER ECS LAB MANUAL DATA STRUCTURES & ALGORITHMS (CSE-205-F) III SEMESTER ECS Department of Electronics & Communication Engg. Dronacharya College of Engineering Khentawas, Gurgaon 123506 Data Structures and algorithms

More information

Methodology and Program. By Abhishek Navlakhi Semester 3: Data Structures

Methodology and Program. By Abhishek Navlakhi Semester 3: Data Structures Linked List Methodology and Program By Abhishek Navlakhi Semester 3: Data Structures This document is for private circulation for the students of Navlakhi. More educational content can be found on www.navlakhi.com

More information

Trees CONTENTS. Hours: 8. Marks: 12. Anuradha Bhatia 1

Trees CONTENTS. Hours: 8. Marks: 12. Anuradha Bhatia 1 Trees CONTENTS 6.1 Introduction 1. Terminologies: tree,degree of a node, degree of a tree, level of a node, leaf node, Depth / Height of a tree, In-degree & out- Degree, Directed edge, Path, Ancestor &

More information

MAHARASHTRASTATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

MAHARASHTRASTATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) Subject Code: 17330 Model Answer Page 1/ 22 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The model

More information

The program simply pushes all of the characters of the string into the stack. Then it pops and display until the stack is empty.

The program simply pushes all of the characters of the string into the stack. Then it pops and display until the stack is empty. EENG212 Algorithms & Data Structures Fall 0/07 Lecture Notes # Outline Stacks Application of Stacks Reversing a String Palindrome Example Infix, Postfix and Prefix Notations APPLICATION OF STACKS Stacks

More information

BITS PILANI, DUBAI CAMPUS DUBAI INTERNATIONAL ACADEMIC CITY, DUBAI FIRST SEMESTER

BITS PILANI, DUBAI CAMPUS DUBAI INTERNATIONAL ACADEMIC CITY, DUBAI FIRST SEMESTER BITS PILANI, DUBAI CAMPUS DUBAI INTERNATIONAL ACADEMIC CITY, DUBAI FIRST SEMESTER 2017-2018 COURSE : COMPUTER PROGRAMMING (CS F111) COMPONENT : Tutorial# 7 (SOLUTIONS) DATE : 06-DEC-2017 Answer 1 enum

More information

Doubly Linked List Methodology and Program

Doubly Linked List Methodology and Program Doubly Linked List Methodology and Program Semester 3: Data Structures This document is for private circulation for the students of Navlakhi. More educational content can be found on www.navlakhi.com and

More information

Vivekananda College of Engineering & Technology. Laboratory Manual

Vivekananda College of Engineering & Technology. Laboratory Manual Vivekananda College of Engineering & Technology [Sponsored by Vivekananda Vidyavardhaka Sangha, Puttur ] Affiliated to Visvesvaraya Technological University Approved by AICTE New Delhi & Govt of Karnataka

More information

Assignment 6. Q1. Create a database of students using structures, where in each entry of the database will have the following fields:

Assignment 6. Q1. Create a database of students using structures, where in each entry of the database will have the following fields: Assignment 6 Q1. Create a database of students using structures, where in each entry of the database will have the following fields: 1. a name, which is a string with at most 128 characters 2. their marks

More information

Class / Sem: I CSE / II Semester Subject Code: CS 6202 Subject: Programming and Data Structures I Prepared by T. Vithya Unit IV - LINEAR DATA STRUCTURES STACKS AND QUEUES Stack ADT Evaluating arithmetic

More information

Vivekananda College of Engineering & Technology. Laboratory Manual

Vivekananda College of Engineering & Technology. Laboratory Manual Vivekananda College of Engineering & Technology [Sponsored by Vivekananda Vidyavardhaka Sangha, Puttur ] Affiliated to Visvesvaraya Technological University Approved by AICTE New Delhi & Govt of Karnataka

More information

A. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS

A. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS Syllabus: Pointers and Preprocessors: Pointers and address, pointers and functions (call by reference) arguments, pointers and arrays, address arithmetic, character pointer and functions, pointers to pointer,initialization

More information

SRI CHANDRASEKHARENDRA SARASWATHI VISWA MAHAVIDYALAYA (UNIVERSITY ESTABLISHED UNDER SECTION 3 OF UGC ACT 1956) ENATHUR - KANCHIPURAM

SRI CHANDRASEKHARENDRA SARASWATHI VISWA MAHAVIDYALAYA (UNIVERSITY ESTABLISHED UNDER SECTION 3 OF UGC ACT 1956) ENATHUR - KANCHIPURAM SRI CHANDRASEKHARENDRA SARASWATHI VISWA MAHAVIDYALAYA (UNIVERSITY ESTABLISHED UNDER SECTION 3 OF UGC ACT 1956) ENATHUR - KANCHIPURAM 631 561 DATA STRUCTURES LAB LABORATORY RECORD Name : Register. No :

More information

Pointers. Array. Solution to the data movement in sequential representation

Pointers. Array. Solution to the data movement in sequential representation 1 LISTS Pointers Array sequential representation some operation can be very time-consuming (data movement) size of data must be predefined static storage allocation and deallocation Solution to the data

More information

DATA STRUCTURES USING C

DATA STRUCTURES USING C DATA STRUCTURES USING C DATA STRUCTURES USING C LECTURE NOTES Prepared by Dr. Subasish Mohapatra Department of Computer Science and Application College of Engineering and Technology, Bhubaneswar Biju Patnaik

More information

Bangalore South Campus

Bangalore South Campus USN: 1 P E PESIT Bangalore South Campus Hosur road, 1km before ElectronicCity, Bengaluru -100 Department of Basic Science and Humanities INTERNAL ASSESSMENT TEST 3 Date: 22/11/2017 Time:11:30am- 1.00 pm

More information

MTH 307/417/515 Final Exam Solutions

MTH 307/417/515 Final Exam Solutions MTH 307/417/515 Final Exam Solutions 1. Write the output for the following programs. Explain the reasoning behind your answer. (a) #include int main() int n; for(n = 7; n!= 0; n--) printf("n =

More information

19-Nov CSCI 2132 Software Development Lecture 29: Linked Lists. Faculty of Computer Science, Dalhousie University Heap (Free Store)

19-Nov CSCI 2132 Software Development Lecture 29: Linked Lists. Faculty of Computer Science, Dalhousie University Heap (Free Store) Lecture 29 p.1 Faculty of Computer Science, Dalhousie University CSCI 2132 Software Development Lecture 29: Linked Lists 19-Nov-2018 Location: Chemistry 125 Time: 12:35 13:25 Instructor: Vlado Keselj Previous

More information

DC54 DATA STRUCTURES JUNE 2013

DC54 DATA STRUCTURES JUNE 2013 Q 2 (a) Define storage class and its functions. Explain in detail scope, storage allocation and purpose of each storage class. 'Storage' refers to the scope of a variable and memory allocated by compiler

More information

The combination of pointers, structs, and dynamic memory allocation allow for creation of data structures

The combination of pointers, structs, and dynamic memory allocation allow for creation of data structures Data Structures in C C Programming and Software Tools N.C. State Department of Computer Science Data Structures in C The combination of pointers, structs, and dynamic memory allocation allow for creation

More information

Write a program that creates in the main function two linked lists of characters and fills them with the following values:

Write a program that creates in the main function two linked lists of characters and fills them with the following values: Write a program that creates in the main function two linked lists of characters and fills them with the following values: The first list will have 3 nodes with the following characters: A,B, and C. The

More information