https://www.rivier.edu/faculty/vriabov/Tutotial-com_small_int.pdf
October 29, 2014
Small Office network simulation
https://www.rivier.edu/faculty/vriabov/Tutotial-com_small_int.pdf
April 22, 2014
Sorted Linked List implementation in C
include "stdlib.h"
include "conio.h"
void del(int data);
void insert(int value);
void display();
struct node
{
int data;
struct node *link;
};
struct node *top=NULL,*temp, *temp1, *temp2, *temp3;
int main()
{
int choice,data;
while(1) //infinite loop is used to insert/delete infinite number of elements in linked list
{
printf("\n1.Insert\n2.Delete\n3.Display\n4.Exit\n");
printf("\nEnter ur choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Enter a new element :");
scanf("%d",&data);
insert(data);
break;
case 2:
printf("Enter the value to be deleted from sorted linked list :");
scanf("%d",&data);
del(data);
break;
case 3:
display();
break;
case 4:
exit(0);
}
}
getch();
return 0;
}
void insert(int data)
{
temp=(struct node *)malloc(sizeof(struct node));
temp->data=data;
if(top == NULL)
{
temp->link=NULL;
top=temp;
}
else // top not null
{
temp1 = top ;
while(temp1 != NULL)
{
if(temp1->data >= data) // list element is smaller ...
{
if(temp1 == top) // list element is head ...
{
temp->link = temp1;
top = temp;
break;
}
else // list element is not head ..
{
temp->link = temp1;
temp2->link = temp;
break;
}
}
else
{
if(temp1->link == NULL)
{
temp->link = NULL;
temp1->link = temp;
break;
}
else
{
temp2 = temp1;
temp1 = temp1->link;
}
}
}
}
// creating a space for the new element.
}
void del(int data)
{
struct node *temp,*var;
temp=top;
int i=0;
while(temp!=NULL)
{
if(temp->data == data)
{ i = 1; // Flag ..
if(temp==top)
{
top=temp->link;
free(temp);
break;
}
else
{
var->link=temp->link;
free(temp);
break;
}
}
else
{
var=temp;
temp=temp->link;
}
}
if(i == 1)
{
printf("data deleted from list is %d",data);
}
else
{
printf("\n The required data, %d is not found in the list. go look somewhere else",data);
}
}
void display()
{
temp=top;
if(temp==NULL)
{
printf("\nStack is empty\n");
}
while(temp!=NULL)
{
printf(" %d ->",temp->data);
temp=temp->link;
}
}
March 12, 2014
Priority Queue Implementation in C using Arrays
#include <stdio.h>
#include <conio.h>
#define size 5
int queue[5][2] = {0};
int top = -1;
int bottom;
void push(int value, int pr)
{
int i,j,k;
if(top < size-1)
{
if(queue[top][1] > pr)
{
for(i=0;i<top;i++)
{
if(queue[i][1] > pr)
{
break;
}
}
for(j=top;j>=i;j--)
{
queue[j+1][0] = queue[j][0];
queue[j+1][1] = queue[j][1];
}
top++;
queue[i][0] = value;
queue[i][1] = pr;
}
else
{
top++;
queue[top][0] = value;
queue[top][1] = pr;
}
}
else
{
printf("queue overflow \n");
}
}
void pop()
{
int i;
if(queue[0][0] == 0)
{
printf("\n The queue is empty \n");
}
else
{
printf("After , dequeue the following value is erased \n %d \n", queue[0][0]);
for(i=0;i<top;i++)
{
queue[i][0] = queue[i+1][0];
queue[i][1] = queue[i+1][1];
}
queue[top][0] = 0;
queue[top][1] = 0;
top--;
}
}
void display()
{ int i,j;
printf("Element\tPriority \n");
for(i=size - 1;i>=0;i--)
{
for(j=0;j<2;j++)
{
printf(" %d\t",queue[i][j]);
}
printf("\n");
}
}
int main()
{
int i,j, ch=0 ,value = 0,pr=0;
while(1)
{
printf("\n Please Enter the choice. \n");
printf("1 for Enqueue \n 2 for Dequeue \n 3 for display\n 5 for exit: \t \n");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\n Please Enter the number to be inserted: \t ");
scanf("%d", &value);
printf("\n Please Enter the priority: \t ");
scanf("%d", &pr);
push(value,pr);
break;
case 2:
pop();
break;
case 3:
display();
break;
case 5:
exit(0);
default:
printf("You entered wrong choice\n");
}
}
}
C program to Read From a File
#include <stdio.h> #include <stdlib.h> void main() { FILE *fptr; char filename[15]; char ch; ...
-
A terminal emulation program for TCP/IP networks such as the Internet. The Telnet program runs on your computer and connects your PC to a ...
-
Voice over IP (VoIP, or voice over Internet Protocol) commonly refers to the communication protocols, technologies, methodologies, and tra...
-
Star Formations http://cs-study.blogspot.com/2013/10/c-program-to-print-different-star.html Hollow...