Generate all initial n numbers formed from 0 1 and 2

Here given code implementation process.

// Java Program 
// Generate all initial n numbers formed from 0 1 and 2
class QNode
{
	public String data;
	public QNode next;
	public QNode(String data)
	{
		this.data = data;
		this.next = null;
	}
}
// Define custom queue class
class MyQueue
{
	public QNode front;
	public QNode rear;
	public int size;
	public MyQueue()
	{
		this.front = null;
		this.rear = null;
		this.size = 0;
	}
	// Add a new node at last of queue
	public void enqueue(String data)
	{
		QNode node = new QNode(data);
		if (this.front == null)
		{
			// When first node of queue
			this.front = node;
		}
		else
		{
			// Add node at last level
			this.rear.next = node;
		}
		this.size++;
		this.rear = node;
	}
	// Delete front node of queue
	public void dequeue()
	{
		if (this.front != null)
		{
			if (this.rear == this.front)
			{
				this.rear = null;
				this.front = null;
			}
			else
			{
				this.front = this.front.next;
			}
			this.size--;
		}
	}
	public int isSize()
	{
		return this.size;
	}
	public boolean isEmpty()
	{
		if (this.isSize() == 0)
		{
			return true;
		}
		return false;
	}
	public QNode peek()
	{
		if (this.isSize() == 0)
		{
			return null;
		}
		else
		{
			return this.front;
		}
	}
}
public class NumberCombination
{
	public void combination012(int n)
	{
		if (n <= 0)
		{
			return;
		}
		if (n == 1)
		{
			System.out.println("0");
			return;
		}
		MyQueue record = new MyQueue();
		QNode temp = null;
		// Second number
		record.enqueue("1");
		// Third number
		record.enqueue("2");
		int count = 3;
		// First number
		System.out.println("0");
		while (record.isEmpty() == false)
		{
			// Get front node
			temp = record.peek();
			if (count < n)
			{
				record.enqueue(temp.data + "0");
				count++;
			}
			if (count < n)
			{
				record.enqueue(temp.data + "1");
				count++;
			}
			if (count < n)
			{
				record.enqueue(temp.data + "2");
				count++;
			}
			System.out.println(temp.data);
			// Remove front node
			record.dequeue();
		}
	}
	public static void main(String args[])
	{
		NumberCombination task = new NumberCombination();
		// Test n = 20
		task.combination012(20);
	}
}

Output

0
1
2
10
11
12
20
21
22
100
101
102
110
111
112
120
121
122
200
201
// Include header file
#include <iostream>
using namespace std;
// C++ Program 
// Generate all initial n numbers formed from 0 1 and 2
class QNode
{
	public: string data;
	QNode *next;
	QNode(string data)
	{
		this->data = data;
		this->next = NULL;
	}
};
// Define custom queue class
class MyQueue
{
	public: QNode *front;
	QNode *rear;
	int size;
	MyQueue()
	{
		this->front = NULL;
		this->rear = NULL;
		this->size = 0;
	}
	// Add a new node at last of queue
	void enqueue(string data)
	{
		QNode *node = new QNode(data);
		if (this->front == NULL)
		{
			// When first node of queue
			this->front = node;
		}
		else
		{
			// Add node at last level
			this->rear->next = node;
		}
		this->size++;
		this->rear = node;
	}
	// Delete front node of queue
	void dequeue()
	{
		if (this->front != NULL)
		{
			if (this->rear == this->front)
			{
				this->rear = NULL;
				this->front = NULL;
			}
			else
			{
				this->front = this->front->next;
			}
			this->size--;
		}
	}
	int isSize()
	{
		return this->size;
	}
	bool isEmpty()
	{
		if (this->isSize() == 0)
		{
			return true;
		}
		return false;
	}
	QNode *peek()
	{
		if (this->isSize() == 0)
		{
			return NULL;
		}
		else
		{
			return this->front;
		}
	}
};
class NumberCombination
{
	public: void combination012(int n)
	{
		if (n <= 0)
		{
			return;
		}
		if (n == 1)
		{
			cout << "0" << endl;
			return;
		}
		MyQueue *record = new MyQueue();
		QNode *temp = NULL;
		// Second number
		record->enqueue("1");
		// Third number
		record->enqueue("2");
		int count = 3;
		// First number
		cout << "0" << endl;
		while (record->isEmpty() == false)
		{
			// Get front node
			temp = record->peek();
			if (count < n)
			{
				record->enqueue(temp->data  +  "0");
				count++;
			}
			if (count < n)
			{
				record->enqueue(temp->data  +  "1");
				count++;
			}
			if (count < n)
			{
				record->enqueue(temp->data  +  "2");
				count++;
			}
			cout << temp->data << endl;
			// Remove front node
			record->dequeue();
		}
	}
};
int main()
{
	NumberCombination *task = new NumberCombination();
	// Test n = 20
	task->combination012(20);
	return 0;
}

Output

0
1
2
10
11
12
20
21
22
100
101
102
110
111
112
120
121
122
200
201
// Include namespace system
using System;
// Csharp Program 
// Generate all initial n numbers formed from 0 1 and 2
public class QNode
{
	public String data;
	public QNode next;
	public QNode(String data)
	{
		this.data = data;
		this.next = null;
	}
}
// Define custom queue class
public class MyQueue
{
	public QNode front;
	public QNode rear;
	public int size;
	public MyQueue()
	{
		this.front = null;
		this.rear = null;
		this.size = 0;
	}
	// Add a new node at last of queue
	public void enqueue(String data)
	{
		QNode node = new QNode(data);
		if (this.front == null)
		{
			// When first node of queue
			this.front = node;
		}
		else
		{
			// Add node at last level
			this.rear.next = node;
		}
		this.size++;
		this.rear = node;
	}
	// Delete front node of queue
	public void dequeue()
	{
		if (this.front != null)
		{
			if (this.rear == this.front)
			{
				this.rear = null;
				this.front = null;
			}
			else
			{
				this.front = this.front.next;
			}
			this.size--;
		}
	}
	public int isSize()
	{
		return this.size;
	}
	public Boolean isEmpty()
	{
		if (this.isSize() == 0)
		{
			return true;
		}
		return false;
	}
	public QNode peek()
	{
		if (this.isSize() == 0)
		{
			return null;
		}
		else
		{
			return this.front;
		}
	}
}
public class NumberCombination
{
	public void combination012(int n)
	{
		if (n <= 0)
		{
			return;
		}
		if (n == 1)
		{
			Console.WriteLine("0");
			return;
		}
		MyQueue record = new MyQueue();
		QNode temp = null;
		// Second number
		record.enqueue("1");
		// Third number
		record.enqueue("2");
		int count = 3;
		// First number
		Console.WriteLine("0");
		while (record.isEmpty() == false)
		{
			// Get front node
			temp = record.peek();
			if (count < n)
			{
				record.enqueue(temp.data + "0");
				count++;
			}
			if (count < n)
			{
				record.enqueue(temp.data + "1");
				count++;
			}
			if (count < n)
			{
				record.enqueue(temp.data + "2");
				count++;
			}
			Console.WriteLine(temp.data);
			// Remove front node
			record.dequeue();
		}
	}
	public static void Main(String[] args)
	{
		NumberCombination task = new NumberCombination();
		// Test n = 20
		task.combination012(20);
	}
}

Output

0
1
2
10
11
12
20
21
22
100
101
102
110
111
112
120
121
122
200
201
package main
import "fmt"
// Go Program 
// Generate all initial n numbers formed from 0 1 and 2
type QNode struct {
	data string
	next * QNode
}
func getQNode(data string) * QNode {
	var me *QNode = &QNode {}
	me.data = data
	me.next = nil
	return me
}
// Define custom queue class
type MyQueue struct {
	front * QNode
	rear * QNode
	size int
}
func getMyQueue() * MyQueue {
	var me *MyQueue = &MyQueue {}
	me.front = nil
	me.rear = nil
	me.size = 0
	return me
}
// Add a new node at last of queue
func(this *MyQueue) enqueue(data string) {
	var node * QNode = getQNode(data)
	if this.front == nil {
		// When first node of queue
		this.front = node
	} else {
		// Add node at last level
		this.rear.next = node
	}
	this.size++
	this.rear = node
}
// Delete front node of queue
func(this *MyQueue) dequeue() {
	if this.front != nil {
		if this.rear == this.front {
			this.rear = nil
			this.front = nil
		} else {
			this.front = this.front.next
		}
		this.size--
	}
}
func(this MyQueue) isSize() int {
	return this.size
}
func(this MyQueue) isEmpty() bool {
	if this.isSize() == 0 {
		return true
	}
	return false
}
func(this MyQueue) peek() * QNode {
	if this.isSize() == 0 {
		return nil
	} else {
		return this.front
	}
}
type NumberCombination struct {}
func getNumberCombination() * NumberCombination {
	var me *NumberCombination = &NumberCombination {}
	return me
}
func(this NumberCombination) combination012(n int) {
	if n <= 0 {
		return
	}
	if n == 1 {
		fmt.Println("0")
		return
	}
	var record * MyQueue = getMyQueue()
	var temp * QNode = nil
	// Second number
	record.enqueue("1")
	// Third number
	record.enqueue("2")
	var count int = 3
	// First number
	fmt.Println("0")
	for (record.isEmpty() == false) {
		// Get front node
		temp = record.peek()
		if count < n {
			record.enqueue(temp.data + "0")
			count++
		}
		if count < n {
			record.enqueue(temp.data + "1")
			count++
		}
		if count < n {
			record.enqueue(temp.data + "2")
			count++
		}
		fmt.Println(temp.data)
		// Remove front node
		record.dequeue()
	}
}
func main() {
	var task * NumberCombination = getNumberCombination()
	// Test n = 20
	task.combination012(20)
}

Output

0
1
2
10
11
12
20
21
22
100
101
102
110
111
112
120
121
122
200
201
<?php
// Php Program 
// Generate all initial n numbers formed from 0 1 and 2
class QNode
{
	public $data;
	public $next;
	public function __construct($data)
	{
		$this->data = $data;
		$this->next = NULL;
	}
}
// Define custom queue class
class MyQueue
{
	public $front;
	public $rear;
	public $size;
	public function __construct()
	{
		$this->front = NULL;
		$this->rear = NULL;
		$this->size = 0;
	}
	// Add a new node at last of queue
	public function enqueue($data)
	{
		$node = new QNode($data);
		if ($this->front == NULL)
		{
			// When first node of queue
			$this->front = $node;
		}
		else
		{
			// Add node at last level
			$this->rear->next = $node;
		}
		$this->size++;
		$this->rear = $node;
	}
	// Delete front node of queue
	public function dequeue()
	{
		if ($this->front != NULL)
		{
			if ($this->rear == $this->front)
			{
				$this->rear = NULL;
				$this->front = NULL;
			}
			else
			{
				$this->front = $this->front->next;
			}
			$this->size--;
		}
	}
	public function isSize()
	{
		return $this->size;
	}
	public function isEmpty()
	{
		if ($this->isSize() == 0)
		{
			return true;
		}
		return false;
	}
	public function peek()
	{
		if ($this->isSize() == 0)
		{
			return NULL;
		}
		else
		{
			return $this->front;
		}
	}
}
class NumberCombination
{
	public function combination012($n)
	{
		if ($n <= 0)
		{
			return;
		}
		if ($n == 1)
		{
			echo("0\n");
			return;
		}
		$record = new MyQueue();
		$temp = NULL;
		// Second number
		$record->enqueue("1");
		// Third number
		$record->enqueue("2");
		$count = 3;
		// First number
		echo("0\n");
		while ($record->isEmpty() == false)
		{
			// Get front node
			$temp = $record->peek();
			if ($count < $n)
			{
				$record->enqueue($temp->data."0");
				$count++;
			}
			if ($count < $n)
			{
				$record->enqueue($temp->data."1");
				$count++;
			}
			if ($count < $n)
			{
				$record->enqueue($temp->data."2");
				$count++;
			}
			echo($temp->data."\n");
			// Remove front node
			$record->dequeue();
		}
	}
}

function main()
{
	$task = new NumberCombination();
	// Test n = 20
	$task->combination012(20);
}
main();

Output

0
1
2
10
11
12
20
21
22
100
101
102
110
111
112
120
121
122
200
201
// Node JS Program 
// Generate all initial n numbers formed from 0 1 and 2
class QNode
{
	constructor(data)
	{
		this.data = data;
		this.next = null;
	}
}
// Define custom queue class
class MyQueue
{
	constructor()
	{
		this.front = null;
		this.rear = null;
		this.size = 0;
	}
	// Add a new node at last of queue
	enqueue(data)
	{
		var node = new QNode(data);
		if (this.front == null)
		{
			// When first node of queue
			this.front = node;
		}
		else
		{
			// Add node at last level
			this.rear.next = node;
		}
		this.size++;
		this.rear = node;
	}
	// Delete front node of queue
	dequeue()
	{
		if (this.front != null)
		{
			if (this.rear == this.front)
			{
				this.rear = null;
				this.front = null;
			}
			else
			{
				this.front = this.front.next;
			}
			this.size--;
		}
	}
	isSize()
	{
		return this.size;
	}
	isEmpty()
	{
		if (this.isSize() == 0)
		{
			return true;
		}
		return false;
	}
	peek()
	{
		if (this.isSize() == 0)
		{
			return null;
		}
		else
		{
			return this.front;
		}
	}
}
class NumberCombination
{
	combination012(n)
	{
		if (n <= 0)
		{
			return;
		}
		if (n == 1)
		{
			console.log("0");
			return;
		}
		var record = new MyQueue();
		var temp = null;
		// Second number
		record.enqueue("1");
		// Third number
		record.enqueue("2");
		var count = 3;
		// First number
		console.log("0");
		while (record.isEmpty() == false)
		{
			// Get front node
			temp = record.peek();
			if (count < n)
			{
				record.enqueue(temp.data + "0");
				count++;
			}
			if (count < n)
			{
				record.enqueue(temp.data + "1");
				count++;
			}
			if (count < n)
			{
				record.enqueue(temp.data + "2");
				count++;
			}
			console.log(temp.data);
			// Remove front node
			record.dequeue();
		}
	}
}

function main()
{
	var task = new NumberCombination();
	// Test n = 20
	task.combination012(20);
}
main();

Output

0
1
2
10
11
12
20
21
22
100
101
102
110
111
112
120
121
122
200
201
#  Python 3 Program 
#  Generate all initial n numbers formed from 0 1 and 2
class QNode :
	def __init__(self, data) :
		self.data = data
		self.next = None
	

#  Define custom queue class
class MyQueue :
	def __init__(self) :
		self.front = None
		self.rear = None
		self.size = 0
	
	#  Add a new node at last of queue
	def enqueue(self, data) :
		node = QNode(data)
		if (self.front == None) :
			#  When first node of queue
			self.front = node
		else :
			#  Add node at last level
			self.rear.next = node
		
		self.size += 1
		self.rear = node
	
	#  Delete front node of queue
	def dequeue(self) :
		if (self.front != None) :
			if (self.rear == self.front) :
				self.rear = None
				self.front = None
			else :
				self.front = self.front.next
			
			self.size -= 1
		
	
	def isSize(self) :
		return self.size
	
	def isEmpty(self) :
		if (self.isSize() == 0) :
			return True
		
		return False
	
	def peek(self) :
		if (self.isSize() == 0) :
			return None
		else :
			return self.front
		
	

class NumberCombination :
	def combination012(self, n) :
		if (n <= 0) :
			return
		
		if (n == 1) :
			print("0")
			return
		
		record = MyQueue()
		temp = None
		#  Second number
		record.enqueue("1")
		#  Third number
		record.enqueue("2")
		count = 3
		#  First number
		print("0")
		while (record.isEmpty() == False) :
			#  Get front node
			temp = record.peek()
			if (count < n) :
				record.enqueue(temp.data + "0")
				count += 1
			
			if (count < n) :
				record.enqueue(temp.data + "1")
				count += 1
			
			if (count < n) :
				record.enqueue(temp.data + "2")
				count += 1
			
			print(temp.data)
			#  Remove front node
			record.dequeue()
		
	

def main() :
	task = NumberCombination()
	#  Test n = 20
	task.combination012(20)

if __name__ == "__main__": main()

Output

0
1
2
10
11
12
20
21
22
100
101
102
110
111
112
120
121
122
200
201
#  Ruby Program 
#  Generate all initial n numbers formed from 0 1 and 2
class QNode 
	# Define the accessor and reader of class QNode
	attr_reader :data, :next
	attr_accessor :data, :next
	def initialize(data) 
		self.data = data
		self.next = nil
	end

end

#  Define custom queue class
class MyQueue 
	# Define the accessor and reader of class MyQueue
	attr_reader :front, :rear, :size
	attr_accessor :front, :rear, :size
	def initialize() 
		self.front = nil
		self.rear = nil
		self.size = 0
	end

	#  Add a new node at last of queue
	def enqueue(data) 
		node = QNode.new(data)
		if (self.front == nil) 
			#  When first node of queue
			self.front = node
		else
 
			#  Add node at last level
			self.rear.next = node
		end

		self.size += 1
		self.rear = node
	end

	#  Delete front node of queue
	def dequeue() 
		if (self.front != nil) 
			if (self.rear == self.front) 
				self.rear = nil
				self.front = nil
			else
 
				self.front = self.front.next
			end

			self.size -= 1
		end

	end

	def isSize() 
		return self.size
	end

	def isEmpty() 
		if (self.isSize() == 0) 
			return true
		end

		return false
	end

	def peek() 
		if (self.isSize() == 0) 
			return nil
		else
 
			return self.front
		end

	end

end

class NumberCombination 
	def combination012(n) 
		if (n <= 0) 
			return
		end

		if (n == 1) 
			print("0", "\n")
			return
		end

		record = MyQueue.new()
		temp = nil
		#  Second number
		record.enqueue("1")
		#  Third number
		record.enqueue("2")
		count = 3
		#  First number
		print("0", "\n")
		while (record.isEmpty() == false) 
			#  Get front node
			temp = record.peek()
			if (count < n) 
				record.enqueue(temp.data + "0")
				count += 1
			end

			if (count < n) 
				record.enqueue(temp.data + "1")
				count += 1
			end

			if (count < n) 
				record.enqueue(temp.data + "2")
				count += 1
			end

			print(temp.data, "\n")
			#  Remove front node
			record.dequeue()
		end

	end

end

def main() 
	task = NumberCombination.new()
	#  Test n = 20
	task.combination012(20)
end

main()

Output

0
1
2
10
11
12
20
21
22
100
101
102
110
111
112
120
121
122
200
201
// Scala Program 
// Generate all initial n numbers formed from 0 1 and 2
class QNode(var data: String,
	var next: QNode)
{
	def this(data: String)
	{
		this(data, null)
	}
}
// Define custom queue class
class MyQueue(var front: QNode,
	var rear: QNode,
		var size: Int)
{
	def this()
	{
		this(null, null, 0)
	}
	// Add a new node at last of queue
	def enqueue(data: String): Unit = {
		var node: QNode = new QNode(data);
		if (this.front == null)
		{
			// When first node of queue
			this.front = node;
		}
		else
		{
			// Add node at last level
			this.rear.next = node;
		}
		this.size += 1;
		this.rear = node;
	}
	// Delete front node of queue
	def dequeue(): Unit = {
		if (this.front != null)
		{
			if (this.rear == this.front)
			{
				this.rear = null;
				this.front = null;
			}
			else
			{
				this.front = this.front.next;
			}
			this.size -= 1;
		}
	}
	def isSize(): Int = {
		return this.size;
	}
	def isEmpty(): Boolean = {
		if (this.isSize() == 0)
		{
			return true;
		}
		return false;
	}
	def peek(): QNode = {
		if (this.isSize() == 0)
		{
			return null;
		}
		else
		{
			return this.front;
		}
	}
}
class NumberCombination()
{
	def combination012(n: Int): Unit = {
		if (n <= 0)
		{
			return;
		}
		if (n == 1)
		{
			println("0");
			return;
		}
		var record: MyQueue = new MyQueue();
		var temp: QNode = null;
		// Second number
		record.enqueue("1");
		// Third number
		record.enqueue("2");
		var count: Int = 3;
		// First number
		println("0");
		while (record.isEmpty() == false)
		{
			// Get front node
			temp = record.peek();
			if (count < n)
			{
				record.enqueue(temp.data + "0");
				count += 1;
			}
			if (count < n)
			{
				record.enqueue(temp.data + "1");
				count += 1;
			}
			if (count < n)
			{
				record.enqueue(temp.data + "2");
				count += 1;
			}
			println(temp.data);
			// Remove front node
			record.dequeue();
		}
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: NumberCombination = new NumberCombination();
		// Test n = 20
		task.combination012(20);
	}
}

Output

0
1
2
10
11
12
20
21
22
100
101
102
110
111
112
120
121
122
200
201
// Swift 4 Program 
// Generate all initial n numbers formed from 0 1 and 2
class QNode
{
	var data: String;
	var next: QNode? ;
	init(_ data: String)
	{
		self.data = data;
		self.next = nil;
	}
}
// Define custom queue class
class MyQueue
{
	var front: QNode? ;
	var rear: QNode? ;
	var size: Int;
	init()
	{
		self.front = nil;
		self.rear = nil;
		self.size = 0;
	}
	// Add a new node at last of queue
	func enqueue(_ data: String)
	{
		let node: QNode = QNode(data);
		if (self.front == nil)
		{
			// When first node of queue
			self.front = node;
		}
		else
		{
			// Add node at last level
			self.rear!.next = node;
		}
		self.size += 1;
		self.rear = node;
	}
	// Delete front node of queue
	func dequeue()
	{
		if (self.front  != nil)
		{
			if (self.rear === self.front)
			{
				self.rear = nil;
				self.front = nil;
			}
			else
			{
				self.front = self.front!.next;
			}
			self.size -= 1;
		}
	}
	func isSize() -> Int
	{
		return self.size;
	}
	func isEmpty() -> Bool
	{
		if (self.isSize() == 0)
		{
			return true;
		}
		return false;
	}
	func peek() -> QNode?
	{
		if (self.isSize() == 0)
		{
			return nil;
		}
		else
		{
			return self.front;
		}
	}
}
class NumberCombination
{
	func combination012(_ n: Int)
	{
		if (n <= 0)
		{
			return;
		}
		if (n == 1)
		{
			print("0");
			return;
		}
		let record: MyQueue = MyQueue();
		var temp: QNode? = nil;
		// Second number
		record.enqueue("1");
		// Third number
		record.enqueue("2");
		var count: Int = 3;
		// First number
		print("0");
		while (record.isEmpty() == false)
		{
			// Get front node
			temp = record.peek();
			if (count < n)
			{
				record.enqueue(temp!.data + "0");
				count += 1;
			}
			if (count < n)
			{
				record.enqueue(temp!.data + "1");
				count += 1;
			}
			if (count < n)
			{
				record.enqueue(temp!.data + "2");
				count += 1;
			}
			print(temp!.data);
			// Remove front node
			record.dequeue();
		}
	}
}
func main()
{
	let task: NumberCombination = NumberCombination();
	// Test n = 20
	task.combination012(20);
}
main();

Output

0
1
2
10
11
12
20
21
22
100
101
102
110
111
112
120
121
122
200
201
// Kotlin Program 
// Generate all initial n numbers formed from 0 1 and 2
class QNode
{
	var data: String;
	var next: QNode ? ;
	constructor(data: String)
	{
		this.data = data;
		this.next = null;
	}
}
// Define custom queue class
class MyQueue
{
	var front: QNode ? ;
	var rear: QNode ? ;
	var size: Int;
	constructor()
	{
		this.front = null;
		this.rear = null;
		this.size = 0;
	}
	// Add a new node at last of queue
	fun enqueue(data: String): Unit
	{
		val node: QNode = QNode(data);
		if (this.front == null)
		{
			// When first node of queue
			this.front = node;
		}
		else
		{
			// Add node at last level
			this.rear?.next = node;
		}
		this.size += 1;
		this.rear = node;
	}
	// Delete front node of queue
	fun dequeue(): Unit
	{
		if (this.front != null)
		{
			if (this.rear == this.front)
			{
				this.rear = null;
				this.front = null;
			}
			else
			{
				this.front = this.front?.next;
			}
			this.size -= 1;
		}
	}
	fun isSize(): Int
	{
		return this.size;
	}
	fun isEmpty(): Boolean
	{
		if (this.isSize() == 0)
		{
			return true;
		}
		return false;
	}
	fun peek(): QNode ?
	{
		if (this.isSize() == 0)
		{
			return null;
		}
		else
		{
			return this.front;
		}
	}
}
class NumberCombination
{
	fun combination012(n: Int): Unit
	{
		if (n <= 0)
		{
			return;
		}
		if (n == 1)
		{
			println("0");
			return;
		}
		val record: MyQueue = MyQueue();
		var temp: QNode ? ;
		// Second number
		record.enqueue("1");
		// Third number
		record.enqueue("2");
		var count: Int = 3;
		// First number
		println("0");
		while (record.isEmpty() == false)
		{
			// Get front node
			temp = record.peek();
			if (count < n)
			{
				record.enqueue(temp?.data + "0");
				count += 1;
			}
			if (count < n)
			{
				record.enqueue(temp?.data + "1");
				count += 1;
			}
			if (count < n)
			{
				record.enqueue(temp?.data + "2");
				count += 1;
			}
			println(temp?.data);
			// Remove front node
			record.dequeue();
		}
	}
}
fun main(args: Array < String > ): Unit
{
	val task: NumberCombination = NumberCombination();
	// Test n = 20
	task.combination012(20);
}

Output

0
1
2
10
11
12
20
21
22
100
101
102
110
111
112
120
121
122
200
201


Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment







© 2021, kalkicode.com, All rights reserved