Skip to content

Commit 313a5bf

Browse files
saad1504thuva4
authored andcommitted
Leaky bucket alogrithm in C++ (thuva4#268)
* Leaky bucket alogrithm in C++ * Readme updated * Rename Leaky-Bucket/C++/LeakyBucket.cpp to LeakyBucket/C/LeakyBucket.cpp
1 parent 827015a commit 313a5bf

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

Leaky-Bucket/C++/a.out

13.2 KB
Binary file not shown.

LeakyBucket/C/LeakyBucket.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <cstdlib>
2+
#include <iostream>
3+
#include <unistd.h>
4+
using namespace std;
5+
//Program to demonstrate leaky bucket algorithm
6+
int main()
7+
{
8+
int bs,outr,ip,cbs=0,i;
9+
//Assign zero to current bucket size
10+
cout << "Enter Bucket Size and Output rate " << endl;
11+
cin >> bs >> outr;
12+
//input Bucket size and output rate
13+
cout << " Input Packet Current Bucket Output Discarded" << endl;
14+
for(i=0;i<200;i++)
15+
{
16+
ip=rand()%201;
17+
// random functions chooses the number randomly for input packet
18+
cbs+=ip;
19+
if(cbs>(bs+outr))
20+
{
21+
cout << ip<<"\t"<<bs<<"\t"<<outr<<"\t"<<cbs-(bs+outr)<<endl;
22+
cbs=bs;
23+
}
24+
else
25+
{
26+
if(cbs<outr)
27+
cout << ip<<"\t"<<cbs<<"\t"<<"0\t"<<"0"<<endl;
28+
else
29+
{
30+
cbs-=outr;
31+
cout << ip<<"\t"<<cbs<<"\t"<<outr<<"\t"<<"0"<<endl;
32+
}
33+
sleep(1);
34+
}
35+
}
36+
return 0;
37+
}

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Inverse Fast Fourier Transform | | | | | :+1: | | | |
4141
Johnson algorithm | :+1: | :+1: | | | :+1: | | | |
4242
Kadane's algorithm | :+1: | :+1: | | :+1: | :+1: | :+1: | :+1: | |
4343
Knuth Morris Prath Algorithm | :+1: | :+1: | | | :+1: | | | |
44+
Leaky-Bucket | | | | | :+1: | | | |
4445
LinearSearch | :+1: | :+1: | :+1: | :+1:| :+1: | :+1: | :+1: | | | :+1: |
4546
Longest common subsequence | :+1: | :+1: | | :+1: | :+1: | | | | :+1:
4647
Longest increasing subsequence | :+1: | :+1: | | | :+1: | | | |
@@ -470,6 +471,8 @@ Extended Euclidean algorithm | | | | |:+1:| | | |
470471

471472
* Lesk algorithm : word sense disambiguation
472473

474+
* Leaky bucket algorithm : an algorithm that demonstrates traffic control in network transmission
475+
473476
* Levenberg–Marquardt algorithm : An algorithm for solving nonlinear least squares problems.
474477

475478
* Levenshtein edit distance : compute a metric for the amount of difference between two sequences

0 commit comments

Comments
 (0)