Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 14th, 2005, 2:45 AM   #1
technocraze
Newbie
 
Join Date: Jul 2005
Posts: 1
Rep Power: 0 technocraze is on a distinguished road
C# - LinkedList Issues

--------------------------------------------------------------------------------

I encountered a few problems when trying to execute a few operations for LinkedList implementaions using C#-Sharp programming codes.

Hereby, i am posting the codes that i have written and hopefully some programmers could provide me with some pointers as to how the problems can be resolve or highlights to me what went wrong or provide with some sample solutions.

When i tried to rxecute the operations for btnAddRear and btnAddPosition, there are no effect at all. Hence, i am suspecting the codes have went wrong somewhere in the entire list.

It would be very much appreciated that any programmers gurus could highlight to me what actually went wrong.
Thanx in advance. Looking forward to the solutions to unravel the mystery puzzles.

Below are the main highlights that have yet to be resolve.

1. Delete a node at the end
2. Insert and delete a node at a particular position (if the user enters 5 the node should be inserted at the fifth position in the LinkedList.
3. Insert and delete nodes containing even numbers only.
4. Insert and delete nodes of numbers specified by users. (including min and max numbers).

This is the class node for the variables:
using System;

namespace LinkedList
{
public class Node
{

private object data;
private Node link;
private Node cursor;
private int pos;
private Node next;
private Node prev;

public Node (object d, Node l, Node c)
{
data = d;
link = l;
cursor = c;
}

public object Data
{
get
{
return data;
}
set
{
data = value;
}
}
public Node Link
{
get
{
return link;
}
set
{
link = value;
}
}
public Node Cursor
{
get
{
return cursor;
}
set
{
cursor = value;
}
}
}
}

Formed LinkedList.cs
rivate void btnAddFront_Click(object sender, System.EventArgs e)
{
Node n = new Node(this.tbxData.Text, null, cursor);
n.Link = head;

if (head == null) // linked list is initially empty
{
tail = n;
}
head = n;
size++; // size = size + 1
this.lblSize.Text = size.ToString();
this.Visualize(head);

}

private void btnDeleteFront_Click(object sender, System.EventArgs e)
{
if(head == null) // the linked list is empty
{
MessageBox.Show("Linked List is empty!");
return;
}
head = head.Link;
size--;
this.lblSize.Text = size.ToString();
this.Visualize(head);

}

private void btnAddRear_Click(object sender, System.EventArgs e)
{
Node n = new Node(this.tbxData.Text, null, null);
if(head == null)// the LinkedList is empty
{
head = n;
tail = n;
}
else
{
// connect the last node to the new node
tail.Link = n;
// make tail points to the last node
tail = n;

}
size++; // size = size + 1
this.lblSize.Text = size.ToString();
this.Visualize(head);

}

private void btnDeleteRear_Click(object sender, System.EventArgs e)
{
if(head == null || index <= 0 || index > size)
{
return;

Node prev = null;
Node current = head;

for(int i = 0 ; i < index ; i++)
{
prev = current;
current = current.Link;
}
object temp = current.Data;
if(prev != null)
{
prev.Link = current.Link;
}
else
{
head = current.Link;
}

if(prev.Link == null)
{
tail = prev;
}
size--;
this.lblSize.Text = size.ToString();
this.Visualize(head);

}

/**object temp = null;
if(tail != null) // the linked list is empty
{
temp = tail.Data;
tail = tail.Link;
size--;
this.lblSize.Text = size.ToString();
this.Visualize(head);
}**/

}

private void btnAddPosition_Click(object sender, System.EventArgs e)
{
cursor = head;
for (int i = 1; (i<pos) && (cursor!= null); i++)
{
cursor = cursor.Link;
this.lblPosNum.Text = pos.ToString();
this.Visualize(cursor);

}

}
technocraze is offline   Reply With Quote
Old Jul 14th, 2005, 2:46 AM   #2
uman
Expert Programmer
 
Join Date: Dec 2004
Posts: 794
Rep Power: 4 uman is on a distinguished road
post that inside "code" tags
__________________
Few people deserve to be compared to (Rush) Limbaugh, most of them were convicted at the Nuremburg trials.
--WilliamSChips on Slashdot
uman is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:31 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC