SlideShare a Scribd company logo
Q) Session10 a)Execute program to remove negative values from list of values by using
queues
Program:
#include <stdio.h>
#include <stdlib.h>
#define MAX 10
int queue[MAX],f=-1,r=-1;
void enq();
void deq();
void display();
void deletenegative();
main()
{
int n,i;
printf("enter the number of elements");
scanf("%d",&n);
for(i=1;i<=n;i++)
enq();
display();
printf("nAfter deleting negative valuesn");
deletenegative();
display();
}
void enq()
{
int val;
if(r==MAX-1) {
printf("Queue full");
return;
}
else if(f == -1 && r == -1)
f=r=0;
else
r=r+1;
printf("enter the data to be enteredn");
scanf("%d",&val);
queue[r]=val;
}
void deq()
{
if(f==-1)
{
printf("underflow");
return;
}
if(f ==r)
f=r=-1;
else
f=f+1;
}
void display()
{
int i;
if(f ==-1)
printf("queue emptyn");
else
{
for(i=f; i<=r;i++)
printf("%dt",queue[i]);
}
}
void move(int i)
{
for( ;i<r;i++)
queue[i]=queue[i+1];
}
void deletenegative()
{
int i;
if(f ==-1)
printf("queue emptyn");
else
{
for(i=f; i<=r;)
{
if(queue[i] <0)
{
if(i==f)
{
deq();
i=i+1;
}
else
{
move(i);
r=r-1;
i=i-1;
}
}
else
i=i+1;
}
}
}
To see output... See my blog
http://enthusiaststudent.blogspot.in/2017/01/removing-negative-values-in-queues-c.html
Q) 10 bEnqueue, Dequeue and Display operations in Circular Queue using Arrays
#include <stdio.h>
#include <stdlib.h>
#define MAX 5
int cqueue[MAX], front=-1, rear=-1;
void deq();
void enq();
void display();
main()
{
int n,i;
printf("enter the number of elements");
scanf("%d",&n);
for(i=1;i<=n;i++)
enq();
display();
deq();
display();
}
void enq()
{
int val;
if((front == 0 && rear == MAX-1)||(front == rear+1))
{
printf("Queue full");
return;
}
if(front == -1 && rear == -1)
front = rear = 0;
else if(rear == MAX-1)
rear== 0;
else
rear=rear+1;
printf("enter the data to be enteredn");
scanf("%d",&val);
cqueue[rear]=val;
}
void deq()
{
if(front == -1 && rear == -1)
{
printf("queue is empty");
return;
}
printf("ndeleted element=%dn ",cqueue[front]);
if(front == rear)
front = rear = -1;
else if(front == MAX-1)
front = 0;
else
front = front+1;
}
void display()
{
int i;
if(front <= rear)
{
for(i=front;i<=rear;i++)
printf("%dt",cqueue[i]);
}
else
{
for(i=front;i<MAX;i++)
printf("%dt",cqueue[i]);
for(i=0;i<=rear;i++)
printf("%dt",cqueue[i]);
}
}
Q) Program to implement Ascending Priority queue
#include<stdio.h>
#include <stdlib.h>
struct node
{
int data,pri;
struct node *next;
};
struct node *head=NULL,*c,*p;
void create();
void display();
void deleteMin();
main()
{
int n,i;
printf("enter the number of elements");
scanf("%d",&n);
for(i=1;i<=n;i++)
create();
display();
deleteMin();
printf("n after deleting one element, the contents of apq are :n");
display();
}
void create()
{
int v,priority;
printf("enter value and priorityn");
scanf("%d%d",&v,&priority);
struct node *newnode = (struct node *)malloc(sizeof(struct node));
newnode->data =v;
newnode->pri=priority;
newnode->next = NULL;
if(head == NULL)
head = newnode;
else if( newnode->pri < head->pri)
{
newnode->next=head;
head=newnode;
}
else
{
c=head;
while(newnode->pri >= c->pri && c->next != NULL)
{
p=c;
c=c->next;
}
if(c->next == NULL && newnode->pri >= c->pri)
c->next=newnode;
else
{
p->next = newnode;
newnode->next=c;
}
}
}
void display()
{
if(head == NULL)
printf("list is empty");
else
{
c=head;
while(c != NULL)
{
printf("%d %d->",c->data,c->pri);
c=c->next;
}
}
}
void deleteMin()
{
/* delete the first node as the first node is minimum in ascending priority queue*/
c=head;
head=head->next;
free(c);
}
Session-13 A) What is a recursive solution to summing up a list of numbers? First you
should note that the sum of [2 13 4 25 66 71 82 91]) is equal to 2 + sum of [ 13 4 25 66 71
82 91]
#include <stdio.h>
int sum(int *a,int index,int n)
{
if(index == n)
return 0;
return(a[index]+sum(a,index+1,n));
}
main()
{
int n,i,a[100];
printf("enter size of arrayn");
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("array sum =%d",sum(a,0,n));
}
Session-13b) . Write a recursive function called elfish? that, given a word, tells us if that
word is elfish or not.
#include <stdio.h>
int elfish(char *s,char *b, int i)
{
if(b[i]=='0')
return 1;
int k,flag=0;
for(k=0;s[k]!='0';k++)
{
if(s[k]==b[i])
{
flag=1;
break;
}
}
if(flag == 1)
return elfish(s,b,i+1);
else
return 0;
}
main()
{
char s[100],b[4]="elf";
int result;
printf("enter the stringn");
gets(s);
result=elfish(s,b,0);
if(result ==0)
printf("given string is not elfish");
else
printf("given string is elfish");
}
Session-14a)Write a recursive function to Find the total number of sequences of length
n (using H and T) such that no two Hs are next to each other.
#include <stdio.h>
int a[20];
int total_seq(int n)
{
if(n == 1)
return 2;
if(n ==2)
return 3;
if(a[n]!=-1 )
return a[n];
a[n]=total_seq(n-1)+total_seq(n-2);
return a[n];
}
main()
{
int n,i;
printf("enter n value");
scanf("%d",&n);
for(i=0;i<20;i++)
a[i]=-1;
printf("n Total number of sequences = %d",total_seq(n));
}
Session14 b) Given an array of positive numbers, find the maximum sum of a
subsequence with the constraint that no 2 numbers in the sequence should be adjacent
in the array.
#include<stdio.h>
int excl,incl;
/*Function to return max sum such that no two elements are adjacent */
int FindMaxSum(int *a, int index, int n)
{
int temp;
if(index == n)
return incl;
else
{
temp=incl;
if(incl<(excl+a[index]))
incl=excl+a[index];
excl = temp;
return FindMaxSum(a,index+1,n);
}
}
main()
{
int n, a[100],i;
printf(“enter the number of elementsn”);
scanf(“%d”, &n);
printf(“enter array elementsn”);
for(i=0;i<n;i++)
scanf(“%d”, &a[i]);
incl = a[0];
excl = 0;
printf("nMaximum sum of non- adjacent elements= %d n", FindMaxSum(a,1, n));
}
Session-15a)
Infix to postfix conversion
#include<stdio.h>
#include <process.h>
#define MAX 50
char stack[MAX];
int top=-1;
int getpriority(char);
void push(char);
char pop();
main()
{
char infix[50],temp,ch,postfix[50];
int i,j=0;
printf("enter the infix expressionn");
scanf("%s",&infix);
for(i=0; infix[i] != '0'; i++)
{
ch=infix[i];
if(ch == '(')
push(ch);
else if(ch == ')')
{
while(stack[top]!='(')
postfix[j++]=pop();
temp=pop();// popping the (
}
else if(isalnum(ch))
postfix[j++]=ch;
else
{
while(getpriority(stack[top])>=getpriority(ch))
postfix[j++]=pop();
push(ch);
}
}
while(top != -1)
postfix[j++]=pop();
postfix[j]='0';
puts(postfix);
}
int getpriority(char ch)
{
if( ch == '*'|| ch == '/'|| ch == '%')
return 2;
else if(ch == '+' || ch == '-')
return 1;
else
return 0;
}
void push(char item)
{
if(top == MAX-1)
{
printf("stack is full");
return;
}
top=top+1;
stack[top]=item;
}
char pop()
{
if(top == -1)
{
printf("stack empty");
return;
}
char temp;
temp=stack[top];
top=top-1;
return temp;
}
Evaluating PostFix expression
#include<stdio.h>
#include <process.h>
#include <string.h>
#define MAX 50
char stack[MAX];
int top=-1;
void push(float);
float pop();
void main()
{
char exp[MAX],temp,ch;
int i;
float op1,op2,value;
printf("Enter an expression : ");
gets(exp);
for(i=0;i<strlen(exp);i++)
{
ch=exp[i];
if(isdigit(ch))
push((float)ch-'0');
else
{
op2=pop();
op1=pop();
switch(ch)
{
case '+':
value=op1+op2;
break;
case '-':
value=op1-op2;
break;
case '*':
value=op1*op2;
break;
case '/':
value=op1/op2;
break;
case '%':
value=(int)op1%(int)op2;
break;
}
push(value);
}
}
printf("n Result=%f",pop());
}
void push(float item)
{
if(top == MAX-1)
{
printf("stack is full");
return;
}
top=top+1;
stack[top]=item;
}
float pop()
{
if(top == -1)
{
printf("stack empty");
return;
}
float temp;
temp=stack[top];
top=top-1;
return temp;
}
Ad

More Related Content

What's hot (20)

Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
Rahul Chugh
 
Daa practicals
Daa practicalsDaa practicals
Daa practicals
Rekha Yadav
 
C Prog - Array
C Prog - ArrayC Prog - Array
C Prog - Array
vinay arora
 
Ada file
Ada fileAda file
Ada file
Kumar Gaurav
 
C programming array & shorting
C  programming array & shortingC  programming array & shorting
C programming array & shorting
argusacademy
 
Os lab 1st mid
Os lab 1st midOs lab 1st mid
Os lab 1st mid
Murali Kummitha
 
Lab manual operating system [cs 502 rgpv] (usefulsearch.org) (useful search)
Lab manual operating system [cs 502 rgpv] (usefulsearch.org)  (useful search)Lab manual operating system [cs 502 rgpv] (usefulsearch.org)  (useful search)
Lab manual operating system [cs 502 rgpv] (usefulsearch.org) (useful search)
Make Mannan
 
Programs for Operating System
Programs for Operating SystemPrograms for Operating System
Programs for Operating System
LPU
 
Pnno
PnnoPnno
Pnno
shristichaudhary4
 
Cpds lab
Cpds labCpds lab
Cpds lab
praveennallavelly08
 
Os 2 cycle
Os 2 cycleOs 2 cycle
Os 2 cycle
Chaitanya Kn
 
Computer graphics programs in c++
Computer graphics programs in c++Computer graphics programs in c++
Computer graphics programs in c++
Ankit Kumar
 
Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File
Harjinder Singh
 
C Prog. - Strings (Updated)
C Prog. - Strings (Updated)C Prog. - Strings (Updated)
C Prog. - Strings (Updated)
vinay arora
 
Programs
ProgramsPrograms
Programs
kulwinderbawa007
 
Struct examples
Struct examplesStruct examples
Struct examples
mondalakash2012
 
programs
programsprograms
programs
Vishnu V
 
Cg my own programs
Cg my own programsCg my own programs
Cg my own programs
Amit Kapoor
 
Wap in c to draw a line using DDA algorithm
Wap in c to draw a line using DDA algorithmWap in c to draw a line using DDA algorithm
Wap in c to draw a line using DDA algorithm
Kapil Pandit
 
computer graphics practicals
computer graphics practicalscomputer graphics practicals
computer graphics practicals
Manoj Chauhan
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
Rahul Chugh
 
C programming array & shorting
C  programming array & shortingC  programming array & shorting
C programming array & shorting
argusacademy
 
Lab manual operating system [cs 502 rgpv] (usefulsearch.org) (useful search)
Lab manual operating system [cs 502 rgpv] (usefulsearch.org)  (useful search)Lab manual operating system [cs 502 rgpv] (usefulsearch.org)  (useful search)
Lab manual operating system [cs 502 rgpv] (usefulsearch.org) (useful search)
Make Mannan
 
Programs for Operating System
Programs for Operating SystemPrograms for Operating System
Programs for Operating System
LPU
 
Computer graphics programs in c++
Computer graphics programs in c++Computer graphics programs in c++
Computer graphics programs in c++
Ankit Kumar
 
Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File
Harjinder Singh
 
C Prog. - Strings (Updated)
C Prog. - Strings (Updated)C Prog. - Strings (Updated)
C Prog. - Strings (Updated)
vinay arora
 
Cg my own programs
Cg my own programsCg my own programs
Cg my own programs
Amit Kapoor
 
Wap in c to draw a line using DDA algorithm
Wap in c to draw a line using DDA algorithmWap in c to draw a line using DDA algorithm
Wap in c to draw a line using DDA algorithm
Kapil Pandit
 
computer graphics practicals
computer graphics practicalscomputer graphics practicals
computer graphics practicals
Manoj Chauhan
 

Viewers also liked (12)

Points lines and planes Lesson 1
Points lines and planes Lesson 1Points lines and planes Lesson 1
Points lines and planes Lesson 1
Jacqueline Pfaltz
 
Mandela's Dream Collonium-Reconsiliation - Copy
Mandela's Dream Collonium-Reconsiliation - CopyMandela's Dream Collonium-Reconsiliation - Copy
Mandela's Dream Collonium-Reconsiliation - Copy
Buchule Makinana
 
sistema nervioso autonomo
sistema nervioso autonomosistema nervioso autonomo
sistema nervioso autonomo
Carol Rodriguez
 
2017 cv
2017 cv2017 cv
2017 cv
samsudheen nambiar thodi
 
WALI ULLAH HABIB ULLAH (1) (4)
WALI ULLAH HABIB ULLAH (1) (4)WALI ULLAH HABIB ULLAH (1) (4)
WALI ULLAH HABIB ULLAH (1) (4)
wali ullah
 
Broadcast journalism
Broadcast journalismBroadcast journalism
Broadcast journalism
Ria priya
 
Noticia de google
Noticia de googleNoticia de google
Noticia de google
Nicolas Vega Rodriguez
 
studying english abroad or studying at home
studying english abroad or studying at homestudying english abroad or studying at home
studying english abroad or studying at home
Ngọc Huyền
 
Evaluation Question 3
Evaluation Question 3Evaluation Question 3
Evaluation Question 3
Sam Benzie
 
Teoria de cola_carmelaabreu
Teoria de cola_carmelaabreuTeoria de cola_carmelaabreu
Teoria de cola_carmelaabreu
carmela1025
 
CIUDADANIA LOS DERECHOS HUMANOS
CIUDADANIA LOS DERECHOS HUMANOSCIUDADANIA LOS DERECHOS HUMANOS
CIUDADANIA LOS DERECHOS HUMANOS
291103
 
Analisi di mercato del settore dei ricambi per automobili in Russia - 2017
Analisi di mercato del settore dei ricambi per automobili in Russia - 2017Analisi di mercato del settore dei ricambi per automobili in Russia - 2017
Analisi di mercato del settore dei ricambi per automobili in Russia - 2017
GruppoBPC International
 
Points lines and planes Lesson 1
Points lines and planes Lesson 1Points lines and planes Lesson 1
Points lines and planes Lesson 1
Jacqueline Pfaltz
 
Mandela's Dream Collonium-Reconsiliation - Copy
Mandela's Dream Collonium-Reconsiliation - CopyMandela's Dream Collonium-Reconsiliation - Copy
Mandela's Dream Collonium-Reconsiliation - Copy
Buchule Makinana
 
sistema nervioso autonomo
sistema nervioso autonomosistema nervioso autonomo
sistema nervioso autonomo
Carol Rodriguez
 
WALI ULLAH HABIB ULLAH (1) (4)
WALI ULLAH HABIB ULLAH (1) (4)WALI ULLAH HABIB ULLAH (1) (4)
WALI ULLAH HABIB ULLAH (1) (4)
wali ullah
 
Broadcast journalism
Broadcast journalismBroadcast journalism
Broadcast journalism
Ria priya
 
studying english abroad or studying at home
studying english abroad or studying at homestudying english abroad or studying at home
studying english abroad or studying at home
Ngọc Huyền
 
Evaluation Question 3
Evaluation Question 3Evaluation Question 3
Evaluation Question 3
Sam Benzie
 
Teoria de cola_carmelaabreu
Teoria de cola_carmelaabreuTeoria de cola_carmelaabreu
Teoria de cola_carmelaabreu
carmela1025
 
CIUDADANIA LOS DERECHOS HUMANOS
CIUDADANIA LOS DERECHOS HUMANOSCIUDADANIA LOS DERECHOS HUMANOS
CIUDADANIA LOS DERECHOS HUMANOS
291103
 
Analisi di mercato del settore dei ricambi per automobili in Russia - 2017
Analisi di mercato del settore dei ricambi per automobili in Russia - 2017Analisi di mercato del settore dei ricambi per automobili in Russia - 2017
Analisi di mercato del settore dei ricambi per automobili in Russia - 2017
GruppoBPC International
 
Ad

Similar to Solutionsfor co2 C Programs for data structures (20)

Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
vrgokila
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
manoj11manu
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
Bilal Mirza
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02
Er Ritu Aggarwal
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkar
sandeep kumbhkar
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
Azhar Javed
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
Nithin Kumar,VVCE, Mysuru
 
C basics
C basicsC basics
C basics
MSc CST
 
Data structure output 1
Data structure output 1Data structure output 1
Data structure output 1
Balaji Thala
 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C Code
Syed Ahmed Zaki
 
Data Structure in C Programming Language
Data Structure in C Programming LanguageData Structure in C Programming Language
Data Structure in C Programming Language
Arkadeep Dey
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptx
happycocoman
 
Ds
DsDs
Ds
kooldeep12345
 
Double linked list
Double linked listDouble linked list
Double linked list
Sayantan Sur
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
sreekanth3dce
 
C programs
C programsC programs
C programs
Koshy Geoji
 
C programms
C programmsC programms
C programms
Mukund Gandrakota
 
DSC program.pdf
DSC program.pdfDSC program.pdf
DSC program.pdf
Prof. Dr. K. Adisesha
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdf
anujmkt
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
PRATHAMESH DESHPANDE
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
vrgokila
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
Bilal Mirza
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02
Er Ritu Aggarwal
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkar
sandeep kumbhkar
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
Azhar Javed
 
C basics
C basicsC basics
C basics
MSc CST
 
Data structure output 1
Data structure output 1Data structure output 1
Data structure output 1
Balaji Thala
 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C Code
Syed Ahmed Zaki
 
Data Structure in C Programming Language
Data Structure in C Programming LanguageData Structure in C Programming Language
Data Structure in C Programming Language
Arkadeep Dey
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptx
happycocoman
 
Double linked list
Double linked listDouble linked list
Double linked list
Sayantan Sur
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
sreekanth3dce
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdf
anujmkt
 
Ad

More from Lakshmi Sarvani Videla (20)

Data Science Using Python
Data Science Using PythonData Science Using Python
Data Science Using Python
Lakshmi Sarvani Videla
 
Programs on multithreading
Programs on multithreadingPrograms on multithreading
Programs on multithreading
Lakshmi Sarvani Videla
 
Menu Driven programs in Java
Menu Driven programs in JavaMenu Driven programs in Java
Menu Driven programs in Java
Lakshmi Sarvani Videla
 
Recursion in C
Recursion in CRecursion in C
Recursion in C
Lakshmi Sarvani Videla
 
Simple questions on structures concept
Simple questions on structures conceptSimple questions on structures concept
Simple questions on structures concept
Lakshmi Sarvani Videla
 
Errors incompetitiveprogramming
Errors incompetitiveprogrammingErrors incompetitiveprogramming
Errors incompetitiveprogramming
Lakshmi Sarvani Videla
 
Relational Operators in C
Relational Operators in CRelational Operators in C
Relational Operators in C
Lakshmi Sarvani Videla
 
Recursive functions in C
Recursive functions in CRecursive functions in C
Recursive functions in C
Lakshmi Sarvani Videla
 
Function Pointer in C
Function Pointer in CFunction Pointer in C
Function Pointer in C
Lakshmi Sarvani Videla
 
Functions
FunctionsFunctions
Functions
Lakshmi Sarvani Videla
 
Java sessionnotes
Java sessionnotesJava sessionnotes
Java sessionnotes
Lakshmi Sarvani Videla
 
Singlelinked list
Singlelinked listSinglelinked list
Singlelinked list
Lakshmi Sarvani Videla
 
Graphs
GraphsGraphs
Graphs
Lakshmi Sarvani Videla
 
B trees
B treesB trees
B trees
Lakshmi Sarvani Videla
 
Functions in python3
Functions in python3Functions in python3
Functions in python3
Lakshmi Sarvani Videla
 
Dictionary
DictionaryDictionary
Dictionary
Lakshmi Sarvani Videla
 
Sets
SetsSets
Sets
Lakshmi Sarvani Videla
 
Lists
ListsLists
Lists
Lakshmi Sarvani Videla
 
Data Mining: Data Preprocessing
Data Mining: Data PreprocessingData Mining: Data Preprocessing
Data Mining: Data Preprocessing
Lakshmi Sarvani Videla
 
Dbms
DbmsDbms
Dbms
Lakshmi Sarvani Videla
 

Recently uploaded (20)

Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz
 
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Wonjun Hwang
 
May Patch Tuesday
May Patch TuesdayMay Patch Tuesday
May Patch Tuesday
Ivanti
 
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier VroomAI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
UXPA Boston
 
fennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solutionfennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solution
shallal2
 
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptxReimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
John Moore
 
Viam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdfViam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdf
camilalamoratta
 
IT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information TechnologyIT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information Technology
SHEHABALYAMANI
 
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Mike Mingos
 
An Overview of Salesforce Health Cloud & How is it Transforming Patient Care
An Overview of Salesforce Health Cloud & How is it Transforming Patient CareAn Overview of Salesforce Health Cloud & How is it Transforming Patient Care
An Overview of Salesforce Health Cloud & How is it Transforming Patient Care
Cyntexa
 
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
SOFTTECHHUB
 
Smart Investments Leveraging Agentic AI for Real Estate Success.pptx
Smart Investments Leveraging Agentic AI for Real Estate Success.pptxSmart Investments Leveraging Agentic AI for Real Estate Success.pptx
Smart Investments Leveraging Agentic AI for Real Estate Success.pptx
Seasia Infotech
 
AsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API DesignAsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API Design
leonid54
 
Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)
Kaya Weers
 
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Cyntexa
 
Dark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanizationDark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanization
Jakub Šimek
 
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Markus Eisele
 
Developing System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptxDeveloping System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptx
wondimagegndesta
 
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptxTop 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
mkubeusa
 
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
Lorenzo Miniero
 
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz
 
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Wonjun Hwang
 
May Patch Tuesday
May Patch TuesdayMay Patch Tuesday
May Patch Tuesday
Ivanti
 
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier VroomAI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
UXPA Boston
 
fennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solutionfennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solution
shallal2
 
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptxReimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
John Moore
 
Viam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdfViam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdf
camilalamoratta
 
IT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information TechnologyIT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information Technology
SHEHABALYAMANI
 
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Mike Mingos
 
An Overview of Salesforce Health Cloud & How is it Transforming Patient Care
An Overview of Salesforce Health Cloud & How is it Transforming Patient CareAn Overview of Salesforce Health Cloud & How is it Transforming Patient Care
An Overview of Salesforce Health Cloud & How is it Transforming Patient Care
Cyntexa
 
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
SOFTTECHHUB
 
Smart Investments Leveraging Agentic AI for Real Estate Success.pptx
Smart Investments Leveraging Agentic AI for Real Estate Success.pptxSmart Investments Leveraging Agentic AI for Real Estate Success.pptx
Smart Investments Leveraging Agentic AI for Real Estate Success.pptx
Seasia Infotech
 
AsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API DesignAsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API Design
leonid54
 
Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)
Kaya Weers
 
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Cyntexa
 
Dark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanizationDark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanization
Jakub Šimek
 
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Markus Eisele
 
Developing System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptxDeveloping System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptx
wondimagegndesta
 
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptxTop 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
mkubeusa
 
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
Lorenzo Miniero
 

Solutionsfor co2 C Programs for data structures

  • 1. Q) Session10 a)Execute program to remove negative values from list of values by using queues Program: #include <stdio.h> #include <stdlib.h> #define MAX 10 int queue[MAX],f=-1,r=-1; void enq(); void deq(); void display(); void deletenegative(); main() { int n,i; printf("enter the number of elements"); scanf("%d",&n); for(i=1;i<=n;i++) enq(); display(); printf("nAfter deleting negative valuesn"); deletenegative(); display(); } void enq() { int val; if(r==MAX-1) { printf("Queue full"); return; } else if(f == -1 && r == -1) f=r=0; else r=r+1; printf("enter the data to be enteredn"); scanf("%d",&val); queue[r]=val; } void deq() { if(f==-1) {
  • 2. printf("underflow"); return; } if(f ==r) f=r=-1; else f=f+1; } void display() { int i; if(f ==-1) printf("queue emptyn"); else { for(i=f; i<=r;i++) printf("%dt",queue[i]); } } void move(int i) { for( ;i<r;i++) queue[i]=queue[i+1]; } void deletenegative() { int i; if(f ==-1) printf("queue emptyn"); else { for(i=f; i<=r;) { if(queue[i] <0) { if(i==f) { deq(); i=i+1; } else {
  • 3. move(i); r=r-1; i=i-1; } } else i=i+1; } } } To see output... See my blog http://enthusiaststudent.blogspot.in/2017/01/removing-negative-values-in-queues-c.html Q) 10 bEnqueue, Dequeue and Display operations in Circular Queue using Arrays #include <stdio.h> #include <stdlib.h> #define MAX 5 int cqueue[MAX], front=-1, rear=-1; void deq(); void enq(); void display(); main() { int n,i; printf("enter the number of elements"); scanf("%d",&n); for(i=1;i<=n;i++) enq(); display();
  • 4. deq(); display(); } void enq() { int val; if((front == 0 && rear == MAX-1)||(front == rear+1)) { printf("Queue full"); return; } if(front == -1 && rear == -1) front = rear = 0; else if(rear == MAX-1) rear== 0; else rear=rear+1; printf("enter the data to be enteredn"); scanf("%d",&val); cqueue[rear]=val; } void deq() { if(front == -1 && rear == -1) { printf("queue is empty"); return;
  • 5. } printf("ndeleted element=%dn ",cqueue[front]); if(front == rear) front = rear = -1; else if(front == MAX-1) front = 0; else front = front+1; } void display() { int i; if(front <= rear) { for(i=front;i<=rear;i++) printf("%dt",cqueue[i]); } else { for(i=front;i<MAX;i++) printf("%dt",cqueue[i]); for(i=0;i<=rear;i++) printf("%dt",cqueue[i]); } } Q) Program to implement Ascending Priority queue
  • 6. #include<stdio.h> #include <stdlib.h> struct node { int data,pri; struct node *next; }; struct node *head=NULL,*c,*p; void create(); void display(); void deleteMin(); main() { int n,i; printf("enter the number of elements"); scanf("%d",&n); for(i=1;i<=n;i++) create(); display(); deleteMin(); printf("n after deleting one element, the contents of apq are :n"); display(); } void create() { int v,priority; printf("enter value and priorityn"); scanf("%d%d",&v,&priority); struct node *newnode = (struct node *)malloc(sizeof(struct node)); newnode->data =v; newnode->pri=priority; newnode->next = NULL; if(head == NULL) head = newnode; else if( newnode->pri < head->pri) { newnode->next=head; head=newnode; } else { c=head; while(newnode->pri >= c->pri && c->next != NULL) { p=c; c=c->next; } if(c->next == NULL && newnode->pri >= c->pri) c->next=newnode; else
  • 7. { p->next = newnode; newnode->next=c; } } } void display() { if(head == NULL) printf("list is empty"); else { c=head; while(c != NULL) { printf("%d %d->",c->data,c->pri); c=c->next; } } } void deleteMin() { /* delete the first node as the first node is minimum in ascending priority queue*/ c=head; head=head->next; free(c); } Session-13 A) What is a recursive solution to summing up a list of numbers? First you should note that the sum of [2 13 4 25 66 71 82 91]) is equal to 2 + sum of [ 13 4 25 66 71 82 91] #include <stdio.h> int sum(int *a,int index,int n) { if(index == n) return 0; return(a[index]+sum(a,index+1,n)); } main() { int n,i,a[100]; printf("enter size of arrayn"); scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&a[i]);
  • 8. printf("array sum =%d",sum(a,0,n)); } Session-13b) . Write a recursive function called elfish? that, given a word, tells us if that word is elfish or not. #include <stdio.h> int elfish(char *s,char *b, int i) { if(b[i]=='0') return 1; int k,flag=0; for(k=0;s[k]!='0';k++) { if(s[k]==b[i]) { flag=1; break; } } if(flag == 1) return elfish(s,b,i+1); else return 0; } main() { char s[100],b[4]="elf"; int result; printf("enter the stringn"); gets(s); result=elfish(s,b,0); if(result ==0) printf("given string is not elfish"); else printf("given string is elfish"); } Session-14a)Write a recursive function to Find the total number of sequences of length n (using H and T) such that no two Hs are next to each other. #include <stdio.h> int a[20]; int total_seq(int n) { if(n == 1) return 2; if(n ==2) return 3; if(a[n]!=-1 )
  • 9. return a[n]; a[n]=total_seq(n-1)+total_seq(n-2); return a[n]; } main() { int n,i; printf("enter n value"); scanf("%d",&n); for(i=0;i<20;i++) a[i]=-1; printf("n Total number of sequences = %d",total_seq(n)); } Session14 b) Given an array of positive numbers, find the maximum sum of a subsequence with the constraint that no 2 numbers in the sequence should be adjacent in the array. #include<stdio.h> int excl,incl; /*Function to return max sum such that no two elements are adjacent */ int FindMaxSum(int *a, int index, int n) { int temp; if(index == n) return incl; else { temp=incl; if(incl<(excl+a[index])) incl=excl+a[index]; excl = temp; return FindMaxSum(a,index+1,n); } } main() { int n, a[100],i; printf(“enter the number of elementsn”); scanf(“%d”, &n); printf(“enter array elementsn”); for(i=0;i<n;i++) scanf(“%d”, &a[i]); incl = a[0]; excl = 0; printf("nMaximum sum of non- adjacent elements= %d n", FindMaxSum(a,1, n)); }
  • 10. Session-15a) Infix to postfix conversion #include<stdio.h> #include <process.h> #define MAX 50 char stack[MAX]; int top=-1; int getpriority(char); void push(char); char pop(); main() { char infix[50],temp,ch,postfix[50]; int i,j=0; printf("enter the infix expressionn"); scanf("%s",&infix); for(i=0; infix[i] != '0'; i++) { ch=infix[i]; if(ch == '(') push(ch); else if(ch == ')') { while(stack[top]!='(') postfix[j++]=pop(); temp=pop();// popping the ( } else if(isalnum(ch)) postfix[j++]=ch; else { while(getpriority(stack[top])>=getpriority(ch)) postfix[j++]=pop(); push(ch); } } while(top != -1) postfix[j++]=pop(); postfix[j]='0'; puts(postfix); } int getpriority(char ch) { if( ch == '*'|| ch == '/'|| ch == '%') return 2; else if(ch == '+' || ch == '-') return 1; else return 0; }
  • 11. void push(char item) { if(top == MAX-1) { printf("stack is full"); return; } top=top+1; stack[top]=item; } char pop() { if(top == -1) { printf("stack empty"); return; } char temp; temp=stack[top]; top=top-1; return temp; } Evaluating PostFix expression #include<stdio.h> #include <process.h> #include <string.h> #define MAX 50 char stack[MAX]; int top=-1; void push(float); float pop(); void main() { char exp[MAX],temp,ch; int i; float op1,op2,value; printf("Enter an expression : "); gets(exp); for(i=0;i<strlen(exp);i++) { ch=exp[i]; if(isdigit(ch)) push((float)ch-'0'); else {
  • 12. op2=pop(); op1=pop(); switch(ch) { case '+': value=op1+op2; break; case '-': value=op1-op2; break; case '*': value=op1*op2; break; case '/': value=op1/op2; break; case '%': value=(int)op1%(int)op2; break; } push(value); } } printf("n Result=%f",pop()); } void push(float item) { if(top == MAX-1) { printf("stack is full"); return; } top=top+1; stack[top]=item; } float pop() { if(top == -1) { printf("stack empty"); return; }
  翻译: