close all;
clear all;
d=[1,0,1,1,0];
for i=1:length(d)
if d(i)==1
a(i)=-2;
b(i)=2;
else
a(i)=2;
b(i)=-2;
end
hold on;
for j=i:0.01:i+0.5
plot(j,a(i),'.-r');
end
for j=i+0.5:0.01:i+1
plot(j,b(i),'.-r');
end
grid on;
end
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<iostream.h>
struct node
{
int info;
struct node* link;
};
struct node *last=0;
void main()
{
struct node*first=0;
int n;
clrscr();
struct node* add_first(struct node*);
struct node* add_last(struct node*);
struct node* del_first(struct node*);
struct node* del_last(struct node*);
void traverse(struct node*);
cout<<" \n 1.add at first ";
cout<<" \n 2.add at last ";
cout<<" \n 3.delete at first ";
cout<<" \n 4.delete at last ";
cout<<" \n 5.traverse ";
do
{
cout<<"\n enter your choice ";
cin>>n;
switch(n)
{
case 1:first=add_first(first);
break;
case 2:first=add_last(first);
break;
case 3:first=del_first(first);
break;
case 4:first=del_last(first);
break;
case 5:traverse(first);
break;
default: cout<<"\n\n invalid entry ";
exit(0);
}
} while(n!=0);
getch();
}
struct node *add_first(struct node *f)
{
struct node* nw;
nw=(struct node*)malloc(sizeof(struct node));
cout<<"\n enter the value of node ";
cin>>nw->info;
if(f==0)
{
last=nw;
nw->link=nw;
return(nw);
}
else
{
nw->link=f;
f=nw;
last->link=nw;
return(f);
}
}
struct node* add_last(struct node *f)
{
struct node* nw;
nw=(struct node*)malloc(sizeof(struct node));
cout<<"\n enter the value of node ";
cin>>nw->info;
if(f==0)
{
nw->link=nw;
last=nw;
return(nw);
}
else
{
last->link=nw;
nw->link=f;
last=nw;
return(f);
}
}
struct node* del_first(struct node *f)
{
if(f==0)
{
cout<<"\n list is empty";
return(f);
}
else
{
f=f->link;
last->link=f;
cout<<"\n node is deleted ";
return(f);
}
}
struct node* del_last(struct node* f)
{
if(f==0)
{
cout<<" \n link list is empty ";
return(f);
}
else
{
struct node* save=f;
while(save->link!=last)
{
save=save->link;
save->link=f;
last=save;
cout<<"\n node is deleted ";
return(f);
}
}
}
void traverse(struct node* f)
{
if(f==0)
{
cout<<"link list is empty ";
}
else
{
struct node* save;
cout<<"\n\n";
while(save->link!=f)
{
cout<<save->info<<" ";
save=save->link;
}
cout<<save->info<<"\n\n";
}
}
/*
DFS TRAVERSAL
ROLL NO:- 09BCE006
*/
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
void create();
void dfs();
struct node
{
int data,status;
struct node *next;
struct link *adj;
}*start,*p,*q;
struct link
{
struct node *next;
struct link *adj;
}*l,*k;
void main()
{
clrscr();
create();
dfs();
}
void create()
{
int dat,flag=0;
start=NULL;
cout<<"Enter the nodes in the graph (0 to end):\n\n";
while(1)
{
cin>>dat;
if(dat==0)
break;
p=new node;
p->data=dat;
p->status=0;
p->next=NULL;
p->adj=NULL;
if(flag==0)
{
start=p;
q=p;
flag++;
}
else
{
q->next=p;
q=p;
}
}
p=start;
while(p!=NULL)
{
cout<<"\nEnter the links of "<<p->data<<"(0 to end)\n";
flag=0;
while(1)
{
cin>>dat;
if(dat==0)
break;
k=new link;
k->adj=NULL;
if(flag==0)
{
p->adj=k;
l=k;
flag++;
}
else
{
l->adj=k;
l=k;
}
q=start;
while(q!=NULL)
{
if(q->data==dat)
k->next=q;
q=q->next;
}
}
p=p->next;
}
return;
}
void dfs()
{
int stack[25],top=1;
cout<<"\nDFS result is\n";
p=start;
while(p!=NULL)
{
p->status=0;
p=p->next;
}
p=start;
stack[0]=0;
stack[top]=p->data;
p->status=1;
while(1)
{
if(stack[top]==0)
{
break;
}
p=start;
while(p!=NULL)
{
if(p->data==stack[top])
{
break;
}
p=p->next;
}
cout<<stack[top]<<" ";
top--;
k=p->adj;
while(k!=NULL)
{
q=k->next;
if(q->status==0)
{
top++;
stack[top]=q->data;
q->status=1;
}
k=k->adj;
}
}
getch();
return;
}
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<process.h>
int binary_search(int ,int ,int,int);
int a[100],loc;
void main()
{
clrscr();
int n,x,low,high;
cout<<"\nEnter number of element:";
cin>>n;
cout<<"Enter elements in ascending order:\n";
for(int i=0;i<n;i++)
{
cin>>a[i];
cout<<endl;
}
cout<<"Enter element which u want to found:\n";
cin>>x;
low=1;
high=n;
loc=binary_search(n,x,low,high);
if(loc==0)
cout<<"ELEMENT NOT FOUND\n";
else
{
cout<<"The position of search element is:\n";
cout<<loc;
}
getch();
}
int binary_search(int n,int x,int l,int h)
{
int m;
if(l>h)
{
loc=0;
}
else
{
m=(l+h)/2;
if(x<a[m-1])
{
loc=binary_search(n,x,l,m-1);
}
else if(x>a[m-1])
{
loc=binary_search(n,x,m+1,h);
}
else
{
loc=m;
}
}
return(loc);
}
/* ROLL NO:- 09BCE006
PRIORITY QUEUE
*/
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include<stdlib.h>
void insert(void);
void del(void);
void disply(void);
struct node
{
int priority;
int value;
struct node *link;
}*first=NULL;
void main()
{
int n;
clrscr();
while(1)
{
cout<<"\n 1.insert \n 2.delete \n 3.display \n 4.Exit \n";
cin>>n;
switch(n)
{
case 1:insert();
break;
case 2:del();
break;
case 3:disply();
break;
case 4:exit(1);
default:cout<<"\n insert valid choice";
break;
}
}
}
void insert()
{
struct node *nw,*p;
int val,prior;
nw=(struct node *)malloc(sizeof(struct node));
cout<<"\n enter the value of node:";
cin>>val;
cout<<"\n enter the priority of node: ";
cin>>prior;
nw->value=val;
nw->priority=prior;
if(first== NULL || prior<first->priority)
{
nw->link=first;
first=nw;
}
else
{
p=first;
while(p->link != NULL && p->link->priority <=prior)
p=p->link;
nw->link=p->link;
p->link=nw;
}
}
void del()
{
struct node *nw;
if(first == NULL)
cout<<"Queue Underflow\n";
else
{
nw = first;
cout<<"Deleted item is: "<<nw->value;
first = first->link;
free(nw);
}
}
void disply()
{
struct node *ptr;
ptr = first;
if(first == NULL)
cout<<"Queue is empty\n";
else
{
cout<<"Queue is :\n\n";
cout<<"Priority\tItem\n";
while(ptr!=NULL)
{
cout<<ptr->priority<<"\t\t"<<ptr->value<<"\n";
ptr = ptr->link;
}
}
}
/* Binary Search Tree
Roll no:- 09BCE006
*/
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<process.h>
struct tree
{
int info;
struct tree *lptr,*rptr;
}*root,*head,*hroot;
void insert(struct tree*,int);
void del(struct tree*,int);
void inorder(struct tree*);
void preorder(struct tree*);
void postorder(struct tree*);
void main()
{
clrscr();
int ch,x;
char cho;
while(1)
{
cout<<"\n\n1.INSERTION\n2.INORDER TRAVERSAL\n3.PREORDER TRAVERSAL\n";
cout<<"4.POSTORDER TRAVERSAL\n5.DELETION\n6.EXIT\n";
cout<<"Enter ur choice\n";
cin>>ch;
clrscr();
switch(ch)
{
case 1:cout<<"Enter ur value whiich is to be inserted\n";
cin>>x;
insert(hroot,x);
break;
case 2:inorder(hroot);
break;
case 3:preorder(hroot);
break;
case 4:postorder(hroot);
break;
case 5:cout<<"enter the value";
cin>>x;
del(hroot,x);
break;
case 6:exit(1);
}
}
getch();
}
void insert(tree *root,int x)
{
tree *temp;
temp=new tree;
temp->info=x;
temp->lptr=NULL;
temp->rptr=NULL;
if(root==NULL)
{ hroot=root=temp;
}
else
{if(root->info<temp->info)
{
if(root->rptr==NULL)
{
root->rptr=temp;
}
else
{
root=root->rptr;
insert(root,x);
}
}
else
{
if(root->lptr==NULL)
{
root->lptr=temp;
}
else
{
root=root->lptr;
insert(root,x);
}
}
}
}
void inorder(tree *root)
{
if(root==NULL)
{
cout<<"\n TREE IS EMPTY\n";
exit(0);
}
if(root->lptr!=NULL)
{
inorder(root->lptr);
}
cout<<endl<<root->info;
if(root->rptr!=NULL)
{
inorder(root->rptr);
}
return;
}
void preorder(tree *root)
{
if(root==NULL)
{
cout<<"\n TREE IS EMPTY\n";
exit(0);
}
else
{
cout<<endl<<root->info;
}
if(root->lptr!=NULL)
{
preorder(root->lptr);
}
if(root->rptr!=NULL)
{
preorder(root->rptr);
}
return;
}
void postorder(tree *root)
{
if(root==NULL)
{
cout<<"\n TREE IS EMPTY\n";
exit(0);
}
if(root->lptr!=NULL)
{
postorder(root->lptr);
}
if(root->rptr!=NULL)
{
postorder(root->rptr);
}
cout<<endl<<root->info;
return;
}
void del(tree *root,int n)
{
tree *par,*p,*temp;
if(root==NULL)
{
cout<<"tree is empty ";
exit(0);
}
else
{
par=NULL;
p=root;
}
while(p!=NULL)
{
if(n==p->info)
{
break;
}
else if(n<p->info)
{
par=p;
p=p->lptr;
}
else
{
par=p;
p=p->rptr;
}
}
/* if(p->lptr!=NULL && p->rptr!=NULL)
{
par=p;
}*/
if(p->lptr==NULL && p->rptr==NULL)
{
temp=NULL;
}
else if(p->lptr!=NULL && p->rptr==NULL)
{
temp=p->lptr;
}
else if(p->lptr==NULL && p->rptr!=NULL)
{
temp=p->rptr;
}
if(par!=NULL)
{
if(p==par->lptr)
{
par->lptr=temp;
}
else
{
par->rptr=temp;
}
}
else
{
p=temp;
}
}
#include<stdio.h>
#include<conio.h>
int a[10];
void q_s(int lb,int ub);
void main()
{
int ub,lb,i,j;
clrscr();
printf("enter elements:");
for(i=0;i<10;i++)
{
scanf("%d",&a[i]);
}
q_s(0,9);
printf("elements in the sorted order are:");
for(i=0;i<10;i++)
{
printf("%d\n",a[i]);
}
getch();
}
void q_s(int lb,int ub)
{
int i,j,t;
int flag=1,key;
if(lb<ub)
{
i=lb;
j=ub+1;
key=a[lb];
while(flag)
{
i=i+1;
while(a[i]<key)
{
i=i+1;
}
j=j-1;
while(a[j]>key)
{
j=j-1;
}
if(i<j)
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
else
{
flag=0;
}
}
t=a[lb];
a[lb]=a[j];
a[j]=t;
q_s(lb,j-1);
q_s(j+1,ub);
}
}
/*
HEAP SORT
ROLL NO:- 09BCE006
*/
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include<stdlib.h>
void create_heap(int n);
void heap_sort(int n);
int k[100];
void main()
{
int n;
clrscr();
cout<<"Enter the no of elements which you want to sort :: ";
cin>>n;
cout<<"Enter the elements "<<endl;
for(int i=1;i<=n;i++)
{
cin>>k[i];
}
heap_sort(n);
cout<<"The sorted list is as follows "<<endl;
for(int j=1;j<=n;j++)
{
cout<<endl<<k[j]<<endl;
}
getch();
}
void heap_sort(int n)
{
int temp,i,j,key;
create_heap(n);
// cout<<"\tTraversal\t\t"<<endl<<endl;
for(int q=n;q>=2;q--)
{
temp=k[1];
k[1]=k[q];
k[q]=temp;
i=1;
key=k[1];
j=2;
if((j+1)<q)
{
if(k[j+1]>k[j])
j++;
}
while(j<=q-1&&k[j]>key)
{
k[i]=k[j];
i=j;
j=2*i;
if((j+1)<q)
{
if(k[j+1]>k[j])
j++;
else if(j>n)
j=n;
}
k[i]=key;
}
/* for(i=1;i<=n;i++)
{
cout<<k[i]<<" ";
}
cout<<endl;*/
}
return;
}
void create_heap(int n)
{
int i,j,key,temp;
for(int q=2;q<=n;q++)
{
i=q;
key=k[q];
j=i/2;
while(i>1&&key>k[j])
{
temp=k[i];
k[i]=k[j];
k[j]=temp;
i=j;
j=i/2;
if(j<i)
j=1;
}
k[i]=key;
}
return;
}
/* OUTPUT ::
Enter the no of elements which you want to sort :: 7
Enter the elements
12
23
35
62
48
49
9
Traversal
49 48 23 12 35 9 62
48 12 23 9 35 49 62
35 12 23 9 48 49 62
23 12 9 35 48 49 62
12 9 23 35 48 49 62
9 12 23 35 48 49 62
The sorted list is as follows
9
12
23
35
48
49
62
*/
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include<stdlib.h>
#include<process.h>
struct node
{
int dat;
struct node *p;
};
struct node *first;
void main()
{
int a;
clrscr();
struct node * insf(struct node *);
struct node * insend(struct node *);
struct node * del(struct node*);
struct node * reverse(struct node*);
void trv(struct node *);
again:
cout<<" \n 1. insert a node at first ";
cout<<" \n 2. insert a node at end ";
cout<<" \n 3. traverse ";
cout<<" \n 4. deletion ";
cout<<" \n 5. reverse ";
cout<<" Enter Your Choice ";
cin>>a;
switch(a)
{
case 1: first=insf(first);
break;
case 2: first=insend(first);
break;
case 3: trv(first);
break;
case 4: first=del(first);
break;
case 5: first=reverse(first);
break;
default: exit(0);
}
int n;
cout<<"\n do you want to continue ? y=1 & n=0 ";
cin>>n;
if(n==1)
{
goto again;
}
getch();
}
struct node * insf(struct node *f)
{
struct node * nw;
nw=(struct node *)malloc(sizeof(struct node));
cout<<"\n\n enter the value of new node ";
cin>>nw->dat;
nw->p=f;
return(nw);
}
struct node * insend(struct node *f)
{
struct node *nw,*s;
nw=(struct node *)malloc(sizeof(struct node));
cout<<"\n\n enter the value of new node ";
cin>>nw->dat;
if(f==0)
{
nw->p=0;
return(nw);
}
s=f;
while(s->p!=0)
{
s=s->p;
}
nw->p=0;
s->p=nw;
return(f);
}
void trv(struct node *f)
{
if(f==0)
{
cout<<"list is empty ";
}
else
{
struct node *s;
s=f;
cout<<"\n\n list is :";
cout<<s->dat<<" ";
while(s->p!=0)
{
s=s->p;
cout<<s->dat<<" ";
}
}
}
struct node* del(struct node *f)
{
struct node *temp=f;
if(f==NULL)
{
cout<<"\nlist is empty ";
return(f);
}
else
{
int val;
cout<<" enter the value of node : ";
cin>>val;
if(temp->dat==val)
{
cout<<"\n node is deleted ";
f=f->p;
return(f);
}
if(temp->p==0)
{
cout<<"\n node not found ";
return(f);
}
while((((temp->p)->dat)!=val)&&((temp->p)!=0))
temp=temp->p;
if((temp->p)==0)
{
cout<<" \n node not found";
return(f);
}
else
{
temp->p=(temp->p)->p;
cout<<"\n Node is deleted ";
return(f);
}
}
}
struct node* reverse(struct node *f)
{
struct node *t1,*t2,*t3;
if(f==0)
{
cout<<"link list is empty ";
return(f);
}
else
{
if(f->p==0)
{
return(f);
}
t1=f;
t2=f->p;
t3=t2->p;
t1->p=0;
t2->p=t1;
while(t3!=0)
{
t1=t2;
t2=t3;
t3=t3->p;
t2->p=t1;
}
cout<<"\n now link list is reversed ";
return(t2);
}
}
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
int top=-1;
int *stk;
void PUSH(int n)
{ if(top>n)
cout<<"\nSTACK OVERFLOW";
else
{ top++;
cout<<"\nEnter the element to be inserted:";
cin>>stk[top];
}
}
void POP()
{ if(top<0)
cout<<"\nSTACK UNDERFLOW";
else
{ int item=stk[top];
top--;
cout<<"\nThe deleted element is:"<<item;
}
}
void PEEP()
{ int pos;
cout<<"\nEnter the element position u want to search:";
cin>>pos;
if(top-pos+1<=0)
cout<<"\nSTACK UNDERFLOW";
else
{ cout<<"\nRequired element:"<<stk[top-pos+1];
}
}
void TRAVERSE()
{ int pos,value;
/* cout<<"\nEnter the position u want to change value:";
cin>>pos;
cout<<"\nEnter the value to be change:";
cin>>value;
if(top-pos+1<=0)
cout<<"\nSTACK UNDERFLOW";
else
{ stk[top-pos+1]=value;
}*/
}
void main()
{ clrscr();
int n,i;
cout<<"\nEnter the size of stack:\n";
cin>>n;
again:
cout<<"Enter your choice:";
cout<<"1.PUSH\n";
cout<<"2.POP\n";
cout<<"3.PEEP\n";
cout<<"4.CHANGE\n";
cin>>i;
switch(i)
{
case 1:PUSH(n);
break;
case 2:POP();
break;
case 3:PEEP();
break;
case 4:CHANGE();
break;
default:exit(0);
}
cout<<" Do u want to continue(Y=1/N=0):";
int x;
cin>>x;
if(x==1)
{
goto again;
}
else
{
exit(0); }
getch();
}
/* output:-
Enter the size of stack:
3
Enter your choice:1.PUSH
2.POP
3.PEEP
4.CHANGE
1
Enter the element to be inserted:4
Do u want to continue(Y=1/N=0):1
Enter your choice:1.PUSH
2.POP
3.PEEP
4.CHANGE
1
Enter the element to be inserted:5
Do u want to continue(Y=1/N=0):1
Enter your choice:1.PUSH
2.POP
3.PEEP
4.CHANGE
1
Enter the element to be inserted:6
Do u want to continue(Y=1/N=0):1
Enter your choice:1.PUSH
2.POP
3.PEEP
4.CHANGE
4
Enter the position u want to change value:2
Enter the value to be change:55
Do u want to continue(Y=1/N=0):1
Enter your choice:1.PUSH
2.POP
3.PEEP
4.CHANGE
3
Enter the element position u want to search:2
Required element:55 Do u want to continue(Y=1/N=0):
0
*/
//----------------------------RmiServer.java--------------------------------//
import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;
import java.net.*;
public class RmiServer extends java.rmi.server.UnicastRemoteObject
implements ReceiveMessageInterface
{
int thisPort;
String thisAddress;
Registry registry; // rmi registry for lookup the remote objects.
// This method is called from the remote client by the RMI.
// This is the implementation of the “ReceiveMessageInterface”.
public void receiveMessage(String x) throws RemoteException
{
System.out.println(x);
}
public RmiServer() throws RemoteException
{
try{
// get the address of this host.
thisAddress= (InetAddress.getLocalHost()).toString();
}
catch(Exception e){
throw new RemoteException("can't get inet address.");
}
thisPort=3232; // this port(registry’s port)
System.out.println("this address="+thisAddress+",port="+thisPort);
try{
// create the registry and bind the name and object.
registry = LocateRegistry.createRegistry( thisPort );
registry.rebind("rmiServer", this);
}
catch(RemoteException e){
throw e;
}
}
static public void main(String args[])
{
try{
RmiServer s=new RmiServer();
}
catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
}
//----------------------------RmiClient.java--------------------------------//
import java.rmi.*;
import java.rmi.registry.*;
import java.net.*;
public class RmiClient
{
static public void main(String args[])
{
ReceiveMessageInterface rmiServer;
Registry registry;
String serverAddress=args[0];
String serverPort=args[1];
String text=args[2];
System.out.println("sending "+text+" to "+serverAddress+":"+serverPort);
try{
// get the “registry”
registry=LocateRegistry.getRegistry(
serverAddress,
(new Integer(serverPort)).intValue()
);
// look up the remote object
rmiServer=
(ReceiveMessageInterface)(registry.lookup("rmiServer"));
// call the remote method
rmiServer.receiveMessage(text);
}
catch(RemoteException e){
e.printStackTrace();
}
catch(NotBoundException e){
e.printStackTrace();
}
}
}
//----------------------------ReceiveMessageInterface.java--------------------------------//
import java.rmi.*;
public interface ReceiveMessageInterface extends Remote
{
void receiveMessage(String x) throws RemoteException;
}
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<dos.h>
#include<sys/stat.h>
#include<alloc.h>
#include<stdlib.h>
typedef struct used
{
int inode;
struct stat temp;
struct used *next;
struct time create;
struct time modi;
int lock;
int ref;
};
used *getnode()
{ used *t=(used *)malloc(sizeof(used));
t->next=NULL;
t->ref=1;
struct time temptime;
gettime(&temptime);
t->create=temptime;
return t;
}
used *fre,*start;
void init(int number)
{
used *t1,*t2,*t3;
// capacity of the inode list is 10
int i,j,k,l;
fre=getnode();
start=NULL;
t2=fre;
for(i=0;i<number;i++)
{ t1=getnode();
t2->next=t1;
t2=t1;
}
}
// max inode number will be 1000
used *cache;
void usenode();
void copy_in(used *);
void input(used *);
void display();
char loop();
void close();
int search(used *);
void incref(used *);
void main()
{
clrscr();
init(19);
char c;
int j=0;
while(1)
{ c=loop();
j=0;
if(c==13)
{ input(cache);
if(search(cache))
incref(cache);
else
usenode();
}
if(c==27)
close();
}
display();
getch();
}
char loop()
{
while(!kbhit())
{ display();
delay(1000);
clrscr();
}
char c=getch();
return c;
}
void usenode()
{
used *t,*temp;
t=fre;
if(t->next==NULL)
{
printf("No fre node avail.\n");
return ;
}
while(t->next!=NULL)
{ temp=t;
t=t->next;
}
temp->next=NULL;
// one node is deleted
t=start;
if(start==NULL)
{
start=getnode();
copy_in(start);
return ;
}
while(t->next!=NULL)
{
t=t->next;
}
temp=getnode();
copy_in(temp);
t->next=temp;
return ;
}
void copy_in(used *temp)
{
temp->inode=cache->inode;
}
void display()
{
used *t;
t=start;
int i=0;
// displaying used incore inodes
while(t!=NULL)
{ gotoxy(10,4+i);
cout<<t->inode<<":"<<t->ref;
printf(" Created on : %2d:%02d:%02d",t->create.ti_hour,t->create.ti_min,t->create.ti_sec);
t=t->next;
i++;
}
cout<<"\nUsed incore copies : "<<i<<"\n\n\n";
i=0;
// displaying fre inode list
t=fre;
while(t!=NULL)
{ t=t->next;
i++;
}
cout<<"Free incore copies : "<<i<<"\n\n\n";
}
void input(used *ch)
{ // clrscr();
int i,j,k;
cout<<"inode number : ";
cin>>ch->inode;
cout<<"\nEnter permission : ";
cin>>i;
ch->lock=i;
}
void close()
{
cout<<"Enter inode for closing file : ";
int i;
cin>>i;
used *t,*pred,*succ;
t=start;
pred=t;
int flag=0;
if(t->inode==i)
{
flag=1;
}
while(t!=NULL && t->inode!=i)
{ pred=t;
t=t->next;
if(t->inode==i)
{ flag=1;
break;
}
}
if(flag==0)
{ printf("No such found..\n");
return ;
}
if(t->ref>=1)
{ t->ref--;
}
if(t->ref!=0)
return ;
if(pred==t)
{ if(start->next!=NULL)
start=start->next;
else
start=NULL;
}
else
{
pred->next=t->next;
t->next=NULL;
}
// increments free inode list
t=fre;
while(t->next!=NULL)
{ t=t->next;
}
succ=getnode();
t->next=succ;
}
int search(used *ch)
{
used *t;
t=start;
if(t==NULL)
return 0;
int flag=0;
while(t!=NULL)
{ if(t->inode == ch->inode)
{ flag=1;
return flag;
}
t=t->next;
}
return flag;
}
void incref(used *ch)
{
used *t;
t=start;
int flag=0;
while(t!=NULL)
{ if(t->inode == ch->inode)
{ t->ref++;
break;
}
t=t->next;
}
}
#include<protos.h>
void main()
{
long int offset;
clrscr();
printf("Enter byteoffset : ";
cin>>offset;
int b_offset;
int single=-1,doubles=-1,triples=-1;
long int block=offset/1024;
if(block < 266)
{ single=block;
b_offset=offset%1024;
goto SKP;
}
else if(block > 266 && block < 65802)
{ single=block/256;
doubles=block%256-10;
b_offset=offset%1024;
goto SKP;
}
else if(block > 65802 && block<10000000)
{ single=block/(256*256);
long int temp=block%(256*256);
doubles=temp/256;
triples=temp%256;
b_offset=offset%1024;
}
SKP:
printf("\n%d %d %d %d single,doubles,triples,b_offset);
getch();
}
#include<unistd.h>
#include<stdio.h>
#include<fcntl.h>
char string[]="patel";
int main(char argv[10][100],int argc)
{
int fd;
char buf[200];
mknod("fifo",010777,0);
if(argc == 2)
fd=open("fifo",O_WRONLY);
else
fd=open("fifo",O_RDONLY);
while(1)
{
if(argc==2)
{ printf("writing");
write(fd,string,6);
}
else
{
printf("Reading");
read(fd,buf,6);
printf("read string : %s ",buf);
}
}
}
%program of tower of hanoi
predicates
hanoi(integer).
hanoi1(integer,symbol,symbol,symbol).
clauses
hanoi(P):-
hanoi1(P,"A","B","C").
hanoi1(0,R,S,T).
hanoi1(P,R,S,T):-
U=P-1,
hanoi1(U,R,T,S),
write("move disk no ",P," from ",R," to ",T),nl,
readchar(A),
hanoi1(U,S,R,T).
%output
%move disk no 1 from A to C
%move disk no 2 from A to B
%move disk no 1 from C to B
%move disk no 3 from A to C
%move disk no 1 from B to A
%move disk no 2 from B to C
%move disk no 1 from A to C