AJ
BAN USERWe can have two main classes Product and Inventory.
A product can be any type of product like furniture, cosmetics, phone etc..
It can contain all features like isChildSafe, isFragile and so on.
Inventory will be actual physical items kept in the shop. Every inventory will linked to a product. It can have features like availability,area of storage and so on. Product to Inventory will be one to many relationship
I have just followed the approach of finding a window of size n with minimum difference between last and first elements.(Assuming the array is sorted). Kindly correct if I am wrong.
void distribute(int a[],int size,int n)
{
int min = -1;
int end = 0;
int j =0;
int start = 0;
int i = 0;
for(i = 0;i< size-n;i++)
{
j = i + n -1;
if(a[end]-a[i]<min)
{
min = a[j]-a[i];
start = i;
end = j;
}
}
for(i = start;i<=end;i++)
cout<<a[i];
}
{struct node
{
int value;
struct node* child[5];
};
int n = 5;//maximum number of child nodes
void zigzag(struct node * root)
{
if(root== NULL)
return;
Stack s1;
Stack s2;
int i =0;
s1.push(root)
while(!s1.empty() || !s2.empty())
{
while(!s1.empty())
{
root = s1.pop();
cout<<root->value;
for(i =0;i< n;i++)
if(root->child[i])
s2.push(root->child[i]);
}
if(s1.empty())
cout<<endl; // empty line after every level
while(!s2.empty())
{
root = s2.pop();
cout<<root->value;
for(i =n-1;i> 0;i--)
if(root->child[i])
s1.push(root->child[i])
}
if(s2.empty())
cout<<endl;//// empty line after every level
}
}
}
#include "SnakesnLadders.h"
#include<math.h>
#define MAX_PLAYERS 4
#define MAX_BLOCK 100
class Player
{
int id;
std::basic_string<char> name;
int position;
public:
Player(int id,std::basic_string<char> name)
{
this->id = id;
this->name = name;
}
int throw_dice()
{
return random()%6;
}
Player(const Player &p)
{
this->id = p.id;
this->name = p.name;
}
int get_position()
{return position;}
void set_position(int n)
{
position = n;
}
};
class Board
{
int n;//no of blocks 100 common case
int move[];
public:
Board()
{
n = MAX_BLOCK;
for(int i =0;i<n;i++)
{
move[i] = -1;
}
}
Board(int n , int move[])
{
this->n = n;
for(int i =0;i<n;i++)
{
this->move[i] = move[i];
}
}
int get_steps()
{
return n;
}
int* get_moves()
{
return move;
}
};
class Game
{
Player players[MAX_PLAYERS];
Board board;
int n;
public: Game(Player p[],Board b,int n);
int play();
};
Game :: Game(Player p[],Board b,int n)
{
this-> n = n;
for(int i = 0;i<n;i++)
this->players[i](&p[i])
this->board = board;
}
int Game::play()
{
int chance = 0;
int dice_value = 0;
while(1)
{
dice_value = players[chance].throw_dice();
int move = 0;
int new_position = players[chance].get_position() + dice_value;
if(move = board.get_moves()[new_position] != -1)
{
new_position += move;
}
if(new_position <= 100)
{
players[chance].set_position(new_position);
}
if(new_position == 100)
return chance;
if(dice_value != 6)
chance = chance == 5 ? 0 : chance+1;
}
return -1;
}
//
// BookCatelog.cpp
// BookCatelog
//
// .
//
#include<string>
#include<stdio.h>
#include<map>
#include<list>
enum category {A , B, C};
class Book
{
std::basic_string<char> name; // assuming to be unique
std::basic_string<char> author;
std::basic_string<char> publisher;
std::basic_string<char>publishing_date;
double price;
category category;
int count;
public: Book(std::basic_string<char> name,std::basic_string<char> author,std::basic_string<char> publisher,std::basic_string<char> publishing_date,double price,enum category category,int count)
{
this->name = name;
this->author = author;
this->publisher =publisher;
this->publishing_date = publishing_date;
this->price = price;
this->category = category;
this->count= count;
}
Book(Book &b)
{
this->name = b.name;
this->author = b.author;
this->publisher =b.publisher;
this->publishing_date = b.publishing_date;
this->price = b.price;
this->category = b.category;
this->count= b.count;
}
std::string get_name ()
{
return name;
}
int get_count()
{
return count;
}
std::string get_author_name()
{
return author;
}
Book()
{
name = " ";
author = " ";
publisher = " ";
publishing_date = " ";
price = 0.0;
category = A;
count = 0;
}
};
class TrieNode
{
public:
int value;
TrieNode* child[26];
TrieNode()
{
value = 0;
for(int i =0;i<26;i++)
child[i] = 0;
}
};
class Trie
{
TrieNode root;
int count;
public:
std::list<std::basic_string<char>> search(std::basic_string<char> book_name);
void insert(std::basic_string<char> key);
std::list<std::basic_string<char>> words(TrieNode t, std::basic_string<char> prefix);
Trie()
{
root = new TrieNode();
count = 0;
}
};
void Trie::insert(std::basic_string<char> key)
{
TrieNode t = root;
int i;
int length = key.length();
int index;
for(int i =0; i< length; i++)
{
index = key[i] - '0';
if(t.child[index])
{
t.child[index] = new TrieNode();
}
t = t.child[index]
}
t.value = count;
}
std::list<std::basic_string<char>> Trie :: words(TrieNode t, std::basic_string<char> prefix)
{
TrieNode curr = t;
std::list<std::basic_string<char>> list;
static int count = 0;
for(int i = 0;i< 26;i++)
{
if(t.child[i])
list.push_back(words(t.child[i],prefix[i]));
}
return list;
}
std::list<std::basic_string<char>> Trie :: search(std::basic_string<char> key)
{
TrieNode t = root;
int i;
int length = key.length();
int index;
std::basic_string<char> prefix = "";
std::list<std::basic_string<char>> l;
int count = 0;
for(int i =0;i<length;i++)
{;
index = key[i] - '0';
prefix += key[i];
if(!t.child[index] == 0)
{
break;
}
t = t.child[index];
}
//..
if(t.value > 0)
{
l.push_back(prefix);
return l;
}
else
{
l= words(t,prefix);
}
}
class BookCatelog
{
Book books[1000];
static int book_count;
std::map<std::string, int> book_name_map;
std::map<std:string,list<std::string>> author_books_map;
Trie book_name_tree;
Trie author_name_tree;
public:BookCatelog()
{
book_count = 0;
for(int i = 0; i< 1000;i++)
books[i] = new Book();
}
void addbook(Book b)
{
if(book_name_map[b.get_name()] > -1 )
{
(books[book_name_map[b.get_name()]].get_count())++;
}
else
{
books[book_count++](&b);
book_name_tree.insert(b.get_name());
author_name_tree.insert(b.get_author_name());
author_books_map[b.get_author_name()].push_back(b.get_name());
book_name_map[b.get_name()] = 1
}
}
};
The job scheduler can facilitate the client to create a queue of its own with configurable values like timeouts, retry counts, consumption logic, priority and user permissions.
- AJ September 08, 2017For every queue, the client should be able to create, delete and cancel the execution of the job.The jobs can also belong to a definite group.All the jobs in a particular group will be executed in sequence.
We will have a logic around the failed jobs depending on the status code of the response.If the job has failed with 5XX, it will be sent to a retry queue.If the job has failed with 4XX, it can be sidelined and sent to the sidelined queue.The client can see the sidelined queue and can take corrective action.
We will be able to set a number of consumers of the job queue depending on the load.