-
MY PROJECTS
-
Recent Posts
- SQL.How can you compare two nullable values safely, and how does IS DISTINCT FROM differ from <>?
- SQL.How are NULL values ordered by ORDER BY, how do defaults differ between databases, and how can you control their placement?
- SQL.How does NULL propagate through arithmetic expressions, and how can COALESCE and NULLIF help handle missing values and division by zero?
- SQL.How does NULL affect join conditions, and why can filtering the right-hand table in WHERE remove unmatched rows from a LEFT JOIN?
- SQL.How do GROUP BY and DISTINCT treat NULL values, even though NULL = NULL evaluates to UNKNOWN?
- SQL.How do aggregate functions handle NULL, and what is the difference between COUNT(*), COUNT(column), and COUNT(DISTINCT column)?
- SQL.How does NULL affect IN and NOT IN, and why can NOT EXISTS be a safer choice when a subquery returns nullable values?
- SQL.How do WHERE, HAVING, and CHECK constraints treat conditions that evaluate to UNKNOWN?
- SQL.Why do column = NULL and column <> NULL not work as expected, and when should you use IS NULL and IS NOT NULL?
- SQL.What is SQL’s three-valued logic (TRUE, FALSE, UNKNOWN), and how do AND, OR, and NOT behave with UNKNOWN?
- ChromeDevTools.Watch all failed requests
- SQL.What are domain types (or constraints on data types), and how do they help enforce data correctness?
- SQL.How does SQL handle comparisons between different data types (for example, string vs number), and why is this dangerous?
- SQL.What is the difference between DATE, TIME, TIMESTAMP, and TIMESTAMPTZ, and which one should be used for business events?
- SQL.How do numeric types like INTEGER, BIGINT, DECIMAL, and FLOAT differ in terms of precision and use cases?
- SQL.What problems can arise from implicit type casting in SQL, and how can it affect indexes?
- SQL.How does NULL differ from 0, an empty string, or FALSE in SQL?
- SQL.What is the difference between CHAR, VARCHAR, and TEXT, and when would you choose each?
- SQL.What is MVCC ?
- SQL.What is AutoVacuum Postgres ?
Categories
- Aptana
- Azure
- C#
- DataSnap
- DBExpress
- Delphi
- Delphi и сети
- Delphi. Язык программирования
- ExtJS
- FastReport
- FireDAC
- FireMonkey
- GIT
- ICS
- IDE
- IIS
- Indy
- InnoSetup
- javascript
- jQuery
- JSON
- LiveBindings
- MSHTML
- MySQL
- PHP
- REST
- Ribbons
- SMS
- SQL инструкции
- SVN
- TRichView
- UniGui
- WebBroker
- WinAPI
- Windows
- Алгоритмы
- Без рубрики
- Деревья
- Ищу ответ
- Компонентостроение
- Мои компоненты
- Начальный уровень
- Обработка исключений
- Парсинг
- Потоки(Threads)
- Регулярные выражения
- Тестирование приложений
Category Archives: C#
C#. Assert. Defensive programming
SO First of all Assert() method is available for Trace and Debug classes. Debug.Assert() is executing only in Debug mode. Trace.Assert() is executing in Debug and Release mode. Here is an example:
|
1 2 3 4 5 6 7 8 9 10 11 |
int i = 1 + 3; // Debug.Assert method in Debug mode fails, since i == 4 Debug.Assert(i == 3); Debug.WriteLine(i == 3, "i is equal to 3"); // Trace.Assert method in Release mode is not failing. Trace.Assert(i == 4); Trace.WriteLine(i == 4, "i is equla to 4"); Console.WriteLine("Press a key to continue..."); Console.ReadLine(); |
Posted in C#
Comments Off on C#. Assert. Defensive programming
C#. Symbol Table with Binary Search
Basic here is 2 arrays keys and vals. Following methods are implemented contains size izEmpty get put delete iterator (IEnumerable) and others… Example illustrates some kind of dictionary with Key and Value, 2 examples – one just shows some standart … Continue reading
Posted in C#
Comments Off on C#. Symbol Table with Binary Search
C#.Algo. Symbol Table Structrure on Linked list
Jasewick origin Git Basic here is one linked list. Following methods are implemented first contains size izEmpty get put delete iterator (IEnumerable) Example illustrates some kind of dictionary with Key and Value, 2 examples – one just shows some standart … Continue reading
Posted in C#
Comments Off on C#.Algo. Symbol Table Structrure on Linked list
C#. PriorityQueue
Git
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
class PriorityQueue { private int[] pq; // inside array pyramid binary tree private int N = 0; // pq[0] not used public void Display() { foreach (int val in pq) Console.Write(val+" "); } public PriorityQueue(int maxN) { pq = new int[maxN + 1]; } public bool isEmpty() { return N == 0; } public int size() { return N; } public void Enqueue(int el) { pq[++N] = el; swimUp(N); } public int Dequeue() { int max = pq[1]; Swap(1, N--); //pq[N + 1] = null; swimDown(1); return max; } private void Swap(int i,int j) { int temp = pq[i]; pq[i] = pq[j]; pq[j] = temp; } private void swimUp(int k) { while ((k > 1) && (pq[k / 2] < pq[k])) { Swap(k/2,k); k = k / 2; } } private void swimDown(int k) { while (2 * k <= N) { int j = 2 * k; if ((j < N) && (j < j + 1)) j++; if (!(k < j)) break; //swap Swap(k,j); k = j; } } } |
Posted in C#
Comments Off on C#. PriorityQueue
C#. PyramidSort
Git
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
class PyramidSort2 { Int32 add2pyramid(Int32[] a, Int32 i, Int32 N) { Int32 imax; Int32 temp; if ((2 * i + 2) < N) { if (a[2 * i + 1] < a[2 * i + 2]) imax = 2 * i + 2; else imax = 2 * i + 1; } else imax = 2 * i + 1; if (imax >= N) return i; if (a[i] < a[imax]) { temp = a[i]; a[i] = a[imax]; a[imax] = temp; if (imax < N / 2) i = imax; } return i; } public void Pyramid_Sort(Int32[] arr, Int32 len) { //step 1: building the pyramid for (Int32 i = len / 2 - 1; i >= 0; --i) { long prev_i = i; i = add2pyramid(arr, i, len); if (prev_i != i) ++i; } //step 2: sorting Int32 buf; for (Int32 k = len - 1; k > 0; --k) { buf = arr[0]; arr[0] = arr[k]; arr[k] = buf; Int32 i = 0, prev_i = -1; while (i != prev_i) { prev_i = i; i = add2pyramid(arr, i, k); } } } } |
Example of use
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
PyramidSort2 ps = new PyramidSort2(); Int32[] arr = new Int32[100]; //заполняем массив случайными числами Random rd = new Random(); for (Int32 i = 0; i < arr.Length; ++i) { arr[i] = rd.Next(1, 101); } System.Console.WriteLine("The array before sorting:"); foreach (Int32 x in arr) { System.Console.Write(x + " "); } //сортировка ps.Pyramid_Sort(arr, arr.Length); System.Console.WriteLine("\n\nThe array after sorting:"); foreach (Int32 x in arr) { System.Console.Write(x + " "); } System.Console.WriteLine("\n\nPress the <Enter> key"); System.Console.ReadLine(); //foreach (var val in a) Console.Write(val); Console.ReadLine(); |
Posted in C#
Comments Off on C#. PyramidSort
C#. QuickSort – Hoar, Lomuto and Unknown Author
Быстрая сортировка по Сейджвику
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
class QuickSort { public int Partition(ref int[] a, int lo, int hi) { int i = lo; int j = hi + 1; int v = a[lo]; // central element while (true) { while (a[++i] < v) if (i == hi) break; while (v <= a[--j] ) if (j == lo) break; if (i >= j) break; Exch(ref a, i, j); } Exch(ref a, lo, j); return j; } public void Sort(ref int[] a, int lo, int hi) { if (hi <= lo) return; int j = Partition(ref a, lo, hi); Sort(ref a, lo, j-1); Sort(ref a, j+1, hi); } public void Exch(ref int[] a,int i,int j) { int temp = a[j]; a[j] = a[i]; a[i] = temp; } public void Test() { int[] a = new int[5] { 3, 1, 2, 0, 1 }; Sort(ref a, 0, a.Length - 1); foreach (int i in a) Console.Write(i + " "); } } |
Git Hoar realization (What is Hoar?)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace QuickSortExample { class Program { static void Main(string[] args) { int[] a = { 3, 2, 5, 6 }; QuickSortHoar qsh = new QuickSortHoar(); qsh.Execute(ref a,0,a.Length-1); foreach (var val in a) Console.Write(val+" "); Console.Read(); } } class QuickSortHoar { void Swap(ref int i,ref int j) { int temp = i; i = j; j = temp; } public void Execute(ref int[] a, int lo, int hi) { int p = a[(hi - lo) / 2 + lo]; int i = lo, j = hi; while (i <= j) { while (a[i] < p && i <= hi) ++i; while (a[j] > p && j >= lo) --j; if (i <= j) { Swap(ref a[i],ref a[j]); ++i; --j; } } if (j > lo) Execute(ref a, lo, j); if (i < hi) Execute(ref a, i, hi); } } } |
Lomuto realization
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
class QuickSort2 { void Swap(ref int i,ref int j) { int temp = i; i = j; j = temp; } // разделение массива по ключу key так, что левая часть - x <=key, правая часть - x > key private int Partition(int[] a, int lo, int hi) { int key = a[hi]; int i = lo - 1; for (int j = lo; j < hi; j++) { if (a[j] <= key) Swap(ref a[++i], ref a[j]); } Swap(ref a[++i], ref a[hi]); return i; } // сортировка public void Execute(int[] a, int lo, int hi) { if (lo < hi) { int key = Partition(a, lo, hi); Execute(a, lo, key - 1); Execute(a, key + 1, hi); } } } |
Git SomeNewRealization
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
static void QuickSort(int[] a, int lo, int hi) // Works! https://gist.github.com/lbsong/6833729 { if (lo >= hi) { return; } int num = a[lo]; /* Console.WriteLine("Before"); Console.WriteLine("pivot index = "+lo); Console.WriteLine("pivot value = " + a[lo]); foreach (int val in a) Console.Write(val+" "); Console.WriteLine(" "); */ int i = lo, j = hi; while (i < j) { while (i < j && a[j] >= num) { j--; } a[i] = a[j]; while (i < j && a[i] <= num) { i++; } a[j] = a[i]; } a[i] = num; /* Console.WriteLine("After"); Console.WriteLine("pivot index = " + lo); Console.WriteLine("pivot value = " + a[lo]); Console.WriteLine("i index = " + i); Console.WriteLine("j index = " + j); foreach (int val in a) Console.Write(val + " "); Console.WriteLine(" "); */ QuickSort(a, lo, i - 1); QuickSort(a, i + 1, hi); } |
Posted in C#
Comments Off on C#. QuickSort – Hoar, Lomuto and Unknown Author
C#. Queue on linked list
Git
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace QueueOnOneLinkedList { class Program { static void Main(string[] args) { // fill stack with Count elements int Count = 10; CustomQueueOnLinkedList<string> queue = new CustomQueueOnLinkedList<string>(); Random r = new Random(); Console.WriteLine("lets fill queue with Count elements"); for (int i = 0; i < Count; i++) { int someRandomNumber = r.Next(100); queue.Enque(someRandomNumber.ToString()); } // iterator foreach (var s in queue) { Console.WriteLine(s.ToString()); } Console.WriteLine("What size of queue now?"); Console.WriteLine(queue.size()); Console.WriteLine("lets take last 5 elements from queue"); for (int i = 0; i < 5; i++) { Console.WriteLine(queue.Deque()); } Console.WriteLine("What size of queue now?"); Console.WriteLine(queue.size()); Console.WriteLine("If queue isEmpty?"); if (queue.isEmpty()) Console.WriteLine("Yes"); else Console.WriteLine("No"); Console.ReadLine(); } } class CustomQueueOnLinkedList<T> : IEnumerable<T> { Node<T> first; Node<T> last; private int N; class Node<T> { public T item; public Node<T> next; } public bool isEmpty() { return ((last == null) || (N == 0)); } public int size() { return N; } public void Enque(T item) { Node<T> lastOld = last; last = new Node<T>(); last.item = item; last.next = null; if (isEmpty()) first = last;else lastOld.next = last; N++; } public T Deque() { T item = first.item; first = first.next; if (isEmpty()) last = null; N--; return item; } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); } public IEnumerator<T> GetEnumerator() { var node = first; while (node != null) { yield return node.item; node = node.next; } } } } |
Posted in C#
Comments Off on C#. Queue on linked list
C#.Algo.MergeSort
Git
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MergeSort { class Program { static void Main(string[] args) { int Count = 1000; Random r = new Random(); int[] a = new int[Count]; for (int i = 0; i < a.Length; i++) { a[i] = r.Next(100); } MergeSort ms = new MergeSort(); ms.Execute(ref a); foreach (int i in a) Console.WriteLine(i); Console.ReadLine(); } } public class MergeSort { private int[] aux; public void Execute(ref int[] a) { aux = new int[a.Length]; Sort(a, 0, a.Length-1); } void Sort(int[] a,int lo,int hi) { if (hi <= lo) return; int mid = lo + (hi - lo) / 2; // Console.WriteLine("Sort a " + lo + " " + hi); Sort(a, lo, mid); Sort(a, mid+1, hi); Merge(a,lo,mid,hi); } public void Merge(int[] a, int lo, int mid, int hi) { Console.WriteLine("Merge a " + lo + " "+mid+" " + hi); int i = lo, j = mid + 1; for (int k = lo; k <= hi; k++) aux[k] = a[k]; for (int k = lo; k <= hi; k++) { if (i > mid) a[k] = aux[j++]; // left data is over, get data from right else if(j > hi) a[k] = aux[i++]; //right data is over, get data from left else if (aux[j] < aux[i]) a[k] = aux[j++]; // key from right < key from left - get data from right else a[k] = aux[i++]; // key from right >= key from left - get data from left } } } } |
Posted in C#
Comments Off on C#.Algo.MergeSort
C#. SelectionSort | InsertionSort | BubbleSort.shellSort
Git
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SortExamplesSelectionSort { class Program { static void Main(string[] args) { int Count = 10; Random r = new Random(); int[] a = new int[Count]; for (int i = 0; i < a.Length; i++) { a[i] = r.Next(1000); } //SelectionSort(ref a); //InsertionSort(ref a); //BubbleSort(ref a); shellSort2(ref a); foreach (int i in a) Console.WriteLine(i); Console.ReadLine(); } static void SelectionSort(ref int[] a) // complexity O(n^2) { for (int i = 0; i < a.Length; i++) { int min = i; // find min for (int j = i; j < a.Length; j++) { if (a[j] < a[min]) min = j; } // exchange int temp = a[i]; a[i] = a[min]; a[min] = temp; } } static void InsertionSort(ref int[] a) // complexity O(n^2) { for (int i = 0; i < a.Length; i++) { for (int j = i; j>0; j--) { if (a[j] < a[j - 1]) { // exchange int temp = a[j]; a[j] = a[j-1]; a[j-1] = temp; } } } } static void shellSort2(ref int[] a) { int j; int step = a.Length / 2; while (step > 0) { for (int i = 0; i < (a.Length - step); i++) { j = i; while ((j >= 0) && (a[j] > a[j + step])) { int tmp = a[j]; a[j] = a[j + step]; a[j + step] = tmp; j -= step; } } step = step / 2; } } } } |
Сортировка пузырьком
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
static void BubbleSort(ref int[] a) // complexity O(n^2) { for (int i = 0; i < a.Length; i++) { for (int j = 0; j < a.Length-1; j++) { if (a[j] > a[j+1]) { // exchange int temp = a[j+1]; a[j+1] = a[j]; a[j] = temp; } } } } |
Posted in C#
Comments Off on C#. SelectionSort | InsertionSort | BubbleSort.shellSort
C#. BagOnLinkedList
Git
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BagOnLinkedList { class Program { static void Main(string[] args) { // fill stack with Count elements int Count = 10; Bag<string> bag = new Bag<string>(); //FixedGenericsStack<string> stack = new FixedGenericsStack<string>(Count); Random r = new Random(); Console.WriteLine("lets fill bag with Count elements"); for (int i = 0; i < Count; i++) { int someRandomNumber = r.Next(100); bag.push(someRandomNumber.ToString()); } // iterator foreach (var s in bag) { Console.WriteLine(s.ToString()); } Console.WriteLine("What size of bag now?"); Console.WriteLine(bag.size()); Console.WriteLine("If bag isEmpty?"); if (bag.isEmpty()) Console.WriteLine("Yes"); else Console.WriteLine("No"); Console.ReadLine(); } } public class Bag<T>:IEnumerable<T> { Node<T> first; private int N; class Node<T> { public T item; public Node<T> next; } public bool isEmpty() { return (first == null) || (N == 0); } public int size() { return N; } public void push(T item) { // adding to the begining Node<T> oldfirst = first; first = new Node<T>(); first.item = item; first.next = oldfirst; N++; } /* // no pop in stack method public T pop() { T item = first.item; first = first.next; N--; return item; } */ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); } public IEnumerator<T> GetEnumerator() { var node = first; while (node != null) { yield return node.item; node = node.next; } } } } |
Posted in C#
Comments Off on C#. BagOnLinkedList