// queue.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
struct queue
{
int front;
int rear;
int a[5];
int capacity;
};
void enqueue(struct queue *q, int data)
{
if((q->front == ((q->rear+1)%q->capacity)))
{
printf("Queue full");
return ;
}
if(q->front == -1)
q->front=0;
q->rear = (++q->rear)%q->capacity;
q->a[q->rear]=data;
printf("front %d rear %d\n",q->front,q->rear);
}
void dequeue(struct queue *q)
{
if((q->front == -1) && (q->rear == -1))
{
printf("\n queue empty");
return;
}
if(q->front == q->rear)
{
q->front = -1;
q->rear = -1;
return;
}
q->front = (++q->front)%q->capacity;
}
void display(struct queue q)
{
if((q.front == -1) && (q.rear == -1))
{
printf("\n queue empty");
return;
}
for(int i=q.front;;i++)
{
i = i%(q.capacity);
printf("-%d-",q.a[i]);
if(i==q.rear)
break;
}
}
int main(int argc, char* argv[])
{
int ch=0, data = 0;
struct queue q;
q.capacity = 5;
q.front = -1;
q.rear = -1;
printf("1.enqueue\n2.dequeue\n3.display\n4.exit");
while(1)
{
printf("\nEnter the option!\n");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("Enter data:");
scanf("%d",&data);
enqueue(&q,data);
break;
case 2: dequeue(&q);
break;
case 3: display(q);
break;
case 4: exit(0);
}
}
return 0;
}
Tuesday, July 28, 2015
queue implementation in c using array
Wednesday, October 17, 2012
Different ways of compilations in android
Different compilations are used for android code
1. Compilation of complete code
$make
2. Compiling android kernel
$make bootimage
3. compiling system img
$make systemimage
4. compilation of an apk
open Android.mk of an apk
LOCAL_MODULE := xyz_module_name
$make xyz_module_name
5. mm is command to compile the indiviual modules . TO work this command first all the code should compile atleast once
1. Compilation of complete code
$make
2. Compiling android kernel
$make bootimage
3. compiling system img
$make systemimage
4. compilation of an apk
open Android.mk of an apk
LOCAL_MODULE := xyz_module_name
$make xyz_module_name
5. mm is command to compile the indiviual modules . TO work this command first all the code should compile atleast once
Monday, September 3, 2012
how to compile SystemUI
Go to base SystemUI folder and type
$mm
SystemUI.apk is generated in out folder
//install to phone
adb root
adb remount
adb push SystemUI.apk /system/app/
adb reboot
$mm
SystemUI.apk is generated in out folder
//install to phone
adb root
adb remount
adb push SystemUI.apk /system/app/
adb reboot
Wednesday, August 22, 2012
Reverse single linked list.
#include<stdio.h>
#include<stdlib.h>
typedef struct node {
int data;
struct node *next;
};
struct node *head=NULL;
void push(int d)
{
struct node *tmp = (struct node *)malloc(sizeof(struct node*));
struct node *ptr = head;
if( head == NULL)
{
tmp->data = d;
tmp->next = NULL;
head = tmp;
} else {
tmp->data = d;
tmp->next = NULL;
while(ptr->next != NULL)
{
ptr = ptr->next;
}
ptr->next = tmp;
}
}
void display()
{
struct node *ptr = head;
while(ptr)
{
printf("%d",ptr->data);
ptr = ptr->next;
}
}
void delete(int n)
{
struct node *ptr=head;
struct node *pre;
int i=1;
if(head != NULL && n==1)
{
head = head->next;
free(ptr);
return;
}
while(ptr != NULL)
{
if(i == n)
{
pre->next = ptr->next;
free(ptr);
ptr=pre->next;
break;
}
pre= ptr;
ptr= ptr->next;
i++;
}
}
void reverse()
{
struct node *ptr=head;
struct node *tmp=NULL;
struct node *next=NULL;
while(ptr)
{
next = ptr->next;
ptr->next = tmp;
tmp=ptr;
ptr=next;
}
head = tmp;
}
main()
{
int d=0,i=0;
while(i<5)
{
i++;
scanf("%d",&d);
push(d);
}
display();
scanf("%d",&d);
delete(d);
display();
printf("reverse ");
reverse();
display();
}
Tuesday, August 21, 2012
delete nth element linked list
void delete(int n)
{
struct node *ptr=head;
struct node *pre;
int i=1;
if((ptr != NULL) && n == 1)
{
head = head->next;
free(ptr);
return;
}
while(ptr != NULL)
{
if(i == n)
{
pre->next = ptr->next;
free(ptr);
ptr=pre->next;
break;
}
pre= ptr;
ptr= ptr->next;
i++;
}
}
{
struct node *ptr=head;
struct node *pre;
int i=1;
if((ptr != NULL) && n == 1)
{
head = head->next;
free(ptr);
return;
}
while(ptr != NULL)
{
if(i == n)
{
pre->next = ptr->next;
free(ptr);
ptr=pre->next;
break;
}
pre= ptr;
ptr= ptr->next;
i++;
}
}
Thursday, July 5, 2012
How to declare new system property in Android
Go to init.rc
//define property
setprop sys.xyz 0
//use in your code
int ret;
char prop_value[MAX];
ret = property_get("sys.xyz",prop_value,NULL)
//define property
setprop sys.xyz 0
//use in your code
int ret;
char prop_value[MAX];
ret = property_get("sys.xyz",prop_value,NULL)
Friday, June 29, 2012
Subscribe to:
Posts (Atom)