LinkedList
Written by: maffelu , 2009-09-28 22:54:05
class Program {
static void Main() {
LinkedList<String> myLinkedList = new LinkedList<string>();
myLinkedList.AddLast("World");
myLinkedList.AddLast("!");
myLinkedList.AddFirst("Hello ");
myLinkedList.AddFirst("Common phrase: ");
foreach (String s in myLinkedList)
Console.Write(s);
//OUTPUT:
//Common phrase: Hello World!
Console.Read();
}
}
class Program {
static void Main() {
LinkedList<string> myLinkedList = new LinkedList<string>();
LinkedListNode<string> nodeA = new LinkedListNode<string>("A");
LinkedListNode<string> nodeB = new LinkedListNode<string>("B");
LinkedListNode<string> nodeC = new LinkedListNode<string>("C");
myLinkedList.AddLast(nodeB);
myLinkedList.AddBefore(nodeB, nodeA);
myLinkedList.AddAfter(nodeB, nodeC);
foreach (string s in myLinkedList)
Console.Write("{0} ", s);
//OUTPUT:
//A B C
Console.Read();
}
}
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace MorkaForm {
public partial class Form1 : Form {
LinkedList<String> linkedList;
LinkedListNode<String> node;
public Form1() {
InitializeComponent();
this.Text = "MorkaLork LinkedList demo";
linkedList = new LinkedList<string>();
linkedList.AddLast(@"C:UsersmaffeluPicturesMorkaPicsSquareMorkaButton.png");
linkedList.AddLast(@"C:UsersmaffeluPicturesMorkaPicsRoundMorkaButton.png");
linkedList.AddLast(@"C:UsersmaffeluPicturesMorkaPicsCrazyMorkaButton.png");
//Get a node
node = linkedList.First;
//Set startup picture
pbMain.Image = Image.FromFile(node.Value);
}
private void btnPrevious_Click(object sender, EventArgs e) {
if (node.Previous != null) {
pbMain.Image = Image.FromFile(node.Previous.Value);
node = node.Previous;
}
}
private void btnNext_Click(object sender, EventArgs e) {
if (node.Next != null) {
pbMain.Image = Image.FromFile(node.Next.Value);
node = node.Next;
}
}
}
}
There are no comments on this article.
If you have any question or just want to leave a message, just fill out the form below!
Your e-mail will not be visible in your post, it is for validation reasons only
Maffelu
Creator and admin of MorkaLork.com.
Started programming in HTML back when frames and tables was the way to design a page, moved on to Pascal/Delphi, PHP, javascript/jQuery, VB.NET/C#, Java and C++.
Currently studies .NET (in general) focusing on ASP.NET.