Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Scheduling algorithm is the method by which threads, processes or data flows are
given access to system resources (e.g. processor time, communications bandwidth).
This is usually done to load balance a system effectively or achieve a target quality of
service. The need for a scheduling algorithm arises from the requirement for most
modern systems to perform multitasking(execute more than one process at a time)
and multiplexing (transmit multiple flows simultaneously).
FIFO
In computer science this term refers to the way data stored in a queue is processed as
first in first out(FIFO). Each item in the queue is stored in a queue (simpliciter) data
structure. The first data to be added to the queue will be the first data to be removed,
then processing proceeds sequentially in the same order. This is typical behavior for a
queue.
Disk controllers can use the FIFO as a disk scheduling algorithm to determine the order
to service disk I/O requests.
Read and write addresses are initially both at the first memory location and the FIFO
queue is Empty.
FIFO EmptyWhen read address register reaches to write address register, the FIFO
triggers the Empty signal.FIFO FULLWhen write address register reaches to read
address register, the FIFO triggers the FULL signal.
FIFO is used in queues. And a queue is a particular kind of collection in which the
entities in the collection are kept in order and the principal (or only) operations on the
collection are the addition of entities to the rear terminal position and removal of entities
from the front terminal position. This makes the queue a First-In-First-Out (FIFO) data
structure. In a FIFO data structure, the first element added to the queue will be the first
one to be removed. This is equivalent to the requirement that whenever an element is
added, all elements that were added before have to be removed before the new element can
be invoked. A queue is an example of a linear data structure.
Queues provide services in computer science, transport and operations research where various
entities such as data, objects, persons, or events are stored and held to be processed later. In
these contexts, the queue performs the function of a buffer.
Queues are common in computer programs, where they are implemented as data structures
coupled with access routines, as an abstract data structure or in object-oriented languages as
classes. Common implementations are circular buffers and linked lists.
Rear: A variable stores the index number in the array at which the new data will be
added (in the queue).
Front: It is a variable storing the index number in the array where the data will be
retrieved.
Algorithum for queues
3.Set QUEUE[REAR]:=ITEM
4.Return
This algo deletes an element from queue and assigns it to the variable ITEM.
2.Set ITEM:=QUEUE[FRONT]
4. Return
SOURCE CODE FOR NSERTION AND DELETION IN QUEUES
#include<stdio.h>
#include<conio.h>
#incldue<alloc.h>
Typedef struct node
Int data;
Node;
Void main()
Clrscr();
Int n;
Scanf(“%d”&n);
Head=(node*)malloc(sizeof(node));
Head->next=NULL;
Scanf(“%d”,&(head->data));
P=head;
For(int i=1;i<n;i++)
p->next=(node*)malloc(sizeof(node));
p=p->next;
p->next=NULL;
scanf(“%d”,&p->data);
Int ch=0;
While(ch!=4)
Scanf(“%d”,&ch);
Switch(ch)
Case1: p->next=(node*)malloc(sizeof(node));
P=p->next=NULL;
Scanf(“%d”,&(p->data));
Break;
Case2:
Head=head->next;
Break;
Case3:
P=head;
Printf(“\n”)
While(n!=Null)
{
Printf(“%d”,p->data);
P=p->next;
Break;
Case4:
Printf(“\n quit”);
Break;
Getch();
LIFO
In computer science, a stack is a last in, first out (LIFO) abstract data type and data
structure. A stack can have any abstract data type as an element, but is characterized
by only two fundamental operations: push and pop. The push operation adds to the top
of the list, hiding any items already on the stack, or initializing the stack if it is empty.
The pop operation removes an item from the top of the list, and returns this value to the
caller. A pop either reveals previously concealed items, or results in an empty list.
A stack is a restricted data structure, because only a small number of operations are
performed on it. The nature of the pop and push operations also means that stack
elements have a natural order. Elements are removed from the stack in the reverse
order to the order of their addition: therefore, the lower elements are typically those that
have been in the list the longest. Operations used in stack that is push and pop are:
a push operation, in which a data item is placed at the location pointed to by the
stack pointer, and the address in the stack pointer is adjusted by the size of the data
item;
a pop or pull operation: a data item at the current location pointed to by the stack
pointer is removed, and the stack pointer is adjusted by the size of the data item.
Algorithum for traversing a stack is as follows:
Algo(traversing linear array)here LA is a linear array with lower bound LB and upper
bound UB.this algo traverses LA applying an operation. PROCESS to each element of
LA
1.[initialize counter] set k=LB
5.Exit
#include<iostream.h>
#include<conio.h>
Void main()
{
Int n ,t[10];
Cout<<”Enter the number of elements want to enter: ”;
Cin>>n;
Cout<<”Enter the elements :”;
For(int i=0;i<n;i++)
{
Cin>>t[i];
}
2.Set TOP:=TOP+1
3.Set STACK[TOP]:=ITEM
4.EXIT.
2. Set ITEM:=STACK[TOP]
3. TOP:=TOP-1
4. EXIT.
#include<stdio.h>
#include<malloc.h>
#include<conio.h>
typedef struct node
int data;
node;
void main()
node *head,*p;
clrscr();
int n;
scanf("%d",&n);
head=(node*)malloc(sizeof(node));
head->next=NULL;
scanf("%d",&(head->data));
p=head;
for(int i=1;i<n;i++)
p->next=(node*)malloc(sizeof(node));
p=p->next;
p->next=NULL;
scanf("%d",&(p->data));
}
int ch;
scanf("%d",&ch);
if(ch==1)
node *newn;
newn=(node*)malloc(sizeof(node));
newn->next=NULL;
scanf("%d",&(newn->data));
newn->next=head;
head=newn;
else if(ch==2)
int item;
item=head->data;
head=head->next;
else if(ch==3)
p=head;
printf("displaying");
while(p!=NULL)
printf("%d",p->data);
p=p->next;
else if(ch==4)
printf("quit");
getch();
else
printf("wrong choice");
goto n;
}
REFERENCES
http://learning-computer-programming.blogspot.com/2007/06/data-structures-
introduction-to-stacks.html
http://www.cs.princeton.edu/introcs/43stack/