diff --git a/L3/LD_24/App_Data/Rezultatai.txt b/L3/LD_24/App_Data/Rezultatai.txt
index 288d333..c501991 100644
--- a/L3/LD_24/App_Data/Rezultatai.txt
+++ b/L3/LD_24/App_Data/Rezultatai.txt
@@ -1,45 +1,45 @@
----------------------------
| Įtaisai |
----------------------------
-| ID | Vardas | Kaina |
+| ID | Vardas | Kaina |
----------------------------
-| 0 | Atsuktuvas | 0.99 |
-| 1 | Varztas | 0.05 |
-| 2 | Laidas | 2.00 |
-| 3 | Plaktukas | 2.99 |
+| 0 | Atsuktuvas | 0.99 |
+| 1 | Varztas | 0.05 |
+| 2 | Laidas | 2.00 |
+| 3 | Plaktukas | 2.99 |
----------------------------
--------------------------------------------------
| Pirkėjai |
--------------------------------------------------
-| Pavardė | Vardas | Įtaisas | Įtaiso kiekis |
+| Pavardė | Vardas | Įtaisas | Įtaiso kiekis |
--------------------------------------------------
-| Petraitis | Petras | 0 | 10 |
-| Petraitis | Petras | 1 | 10 |
-| Jonaitis | Jonas | 1 | 20 |
-| Jonaitis | Jonas | 1 | 20 |
-| Jonaitis | Jonas | 1 | 20 |
-| Onaite | Ona | 2 | 200 |
-| Jonaitis | Brolis | 1 | 100 |
-| Jonaitis | Brolis | 0 | 100 |
-| Jonaitis | Jonas | 1 | 20 |
-| Jonaitis | Jonas | 1 | 20 |
-| Jonaitis | Jonas | 2 | 20 |
-| Onaite | Ona | 0 | 20 |
+| Petraitis | Petras | 0 | 10 |
+| Petraitis | Petras | 1 | 10 |
+| Jonaitis | Jonas | 1 | 20 |
+| Jonaitis | Jonas | 1 | 20 |
+| Jonaitis | Jonas | 1 | 20 |
+| Onaite | Ona | 2 | 200 |
+| Jonaitis | Brolis | 1 | 100 |
+| Jonaitis | Brolis | 0 | 100 |
+| Jonaitis | Jonas | 1 | 20 |
+| Jonaitis | Jonas | 1 | 20 |
+| Jonaitis | Jonas | 2 | 20 |
+| Onaite | Ona | 0 | 20 |
--------------------------------------------------
------------------------------------------------------------
| Populiariausi įtaisai |
------------------------------------------------------------
-| ID | Vardas | Įtaisų kiekis, vnt. | Įtaisų kaina, eur. |
+| ID | Vardas | Įtaisų kiekis, vnt. | Įtaisų kaina, eur. |
------------------------------------------------------------
-| 2 | Laidas | 220 | 440.00 |
+| 2 | Laidas | 220 | 440.00 |
------------------------------------------------------------
----------------------------------------------------------
| Vienos rūšies pirkėjai |
----------------------------------------------------------
-| Pavardė | Vardas | Įtaiso kiekis, vnt. | Kaina, eur. |
+| Pavardė | Vardas | Įtaiso kiekis, vnt. | Kaina, eur. |
----------------------------------------------------------
| Nėra |
----------------------------------------------------------
@@ -47,9 +47,9 @@
----------------------------------
| Atrinkti įtaisai (n=1, k=1.00) |
----------------------------------
-| ID | Vardas | Kaina |
+| ID | Vardas | Kaina |
----------------------------------
-| 0 | Atsuktuvas | 0.99 |
-| 1 | Varztas | 0.05 |
+| 0 | Atsuktuvas | 0.99 |
+| 1 | Varztas | 0.05 |
----------------------------------
diff --git a/L3/LD_24/Code/InOutUtils.cs b/L3/LD_24/Code/InOutUtils.cs
index df1d0b3..f8bda0a 100644
--- a/L3/LD_24/Code/InOutUtils.cs
+++ b/L3/LD_24/Code/InOutUtils.cs
@@ -14,31 +14,28 @@ namespace LD_24.Code
public static class InOutUtils
{
///
- /// Read lines from a file
+ /// Read lines from a stream
///
/// Target filename
/// IEnumerable of all the lines
- private static IEnumerable ReadLines(string filename)
+ private static IEnumerable ReadLines(StreamReader stream)
{
- using (StreamReader reader = File.OpenText(filename))
+ string line;
+ while ((line = stream.ReadLine()) != null)
{
- string line;
- while ((line = reader.ReadLine()) != null)
- {
- yield return line;
- }
+ yield return line;
}
}
///
- /// Read products from a file
+ /// Read products from a stream reader
///
- /// Target file
+ /// Target stream reader
/// A list of products
- public static LinkedList ReadProducts(string filename)
+ public static LinkedList ReadProducts(StreamReader reader)
{
LinkedList products = new LinkedList();
- foreach (string line in ReadLines(filename))
+ foreach (string line in ReadLines(reader))
{
string[] parts = line.Split(',');
string id = parts[0].Trim();
@@ -49,15 +46,67 @@ namespace LD_24.Code
return products;
}
+ ///
+ /// Read products from a stream
+ ///
+ /// Target stream
+ /// A list of products
+ public static LinkedList ReadProducts(Stream stream)
+ {
+ using (StreamReader reader = new StreamReader(stream))
+ {
+ return ReadProducts(reader);
+ }
+ }
+
+ ///
+ /// Read products from a file
+ ///
+ /// Target file
+ /// A list of products
+ public static LinkedList ReadProducts(string filename)
+ {
+ using (StreamReader reader = File.OpenText(filename))
+ {
+ return ReadProducts(reader);
+ }
+ }
+
///
/// Read orders from a file
///
/// Target file
/// A list of orders
public static LinkedList ReadOrders(string filename)
+ {
+ using (StreamReader reader = File.OpenText(filename))
+ {
+ return ReadOrders(reader);
+ }
+ }
+
+ ///
+ /// Read orders from a stream
+ ///
+ /// Target stream
+ /// A list of orders
+ public static LinkedList ReadOrders(Stream stream)
+ {
+ using (StreamReader reader = new StreamReader(stream))
+ {
+ return ReadOrders(reader);
+ }
+ }
+
+ ///
+ /// Read orders from a stream reader
+ ///
+ /// Target stream reader
+ /// A list of orders
+ public static LinkedList ReadOrders(StreamReader reader)
{
LinkedList orders = new LinkedList();
- foreach (string line in ReadLines(filename))
+ foreach (string line in ReadLines(reader))
{
string[] parts = line.Split(',');
string customerSurname = parts[0].Trim();
@@ -79,10 +128,10 @@ namespace LD_24.Code
{
for (int i = 0; i < widths.Count; i++)
{
- if (widths[i] < 0)
- writer.Write("| {0} ", cells[i].PadRight(-widths[i]));
+ if (widths[i] > 0)
+ writer.Write("| {0} ", cells[i].PadRight(widths[i]));
else
- writer.Write("| {0} ", cells[i].PadLeft(widths[i]));
+ writer.Write("| {0} ", cells[i].PadLeft(-widths[i]));
}
writer.WriteLine("|");
}
diff --git a/L3/LD_24/Code/LinkedList.cs b/L3/LD_24/Code/LinkedList.cs
index 4a389d5..bbe51b4 100644
--- a/L3/LD_24/Code/LinkedList.cs
+++ b/L3/LD_24/Code/LinkedList.cs
@@ -42,10 +42,8 @@ namespace LD_24.Code
public int Count()
{
int count = 0;
- Node current = head;
- while (current != null)
+ for (Node d = head; d != null; d = d.Next)
{
- current = current.Next;
count++;
}
return count;
diff --git a/L3/LD_24/Forma1.aspx b/L3/LD_24/Forma1.aspx
index 6aefcdf..3c6686c 100644
--- a/L3/LD_24/Forma1.aspx
+++ b/L3/LD_24/Forma1.aspx
@@ -10,15 +10,27 @@