LinkedList Representation
Linked List Representation
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Memory_understanding
{
public class Node_
{
public Node_ next;
public object data;
}
public class LinkedList
{
private Node_ head;
public void printAllNodes()
{
Node_ current=head;
while(current !=null)
{
Console.WriteLine(current.data);
current=current.next;
}
}
public void AddFirst(Object data)
{
Node_ toadd= new Node_();
toadd.next=head;
toadd.data=data;
head=toadd;
}
public void AddLast(Object data)
{
if(head == null)
{
head = new Node_();
head.data=data;
head.next=null;
}
else
{
Node_ add=new Node_();
add.data=data;
Node_ current= head;
while(current.next !=null)
{
current=current.next;
}
current.next=add;
}
}
public void sortedList(LinkedList lst)
{
LinkedList list1 = this;
}
}
class Prog
{
public static void Main_()
{
LinkedList lst=new LinkedList();
lst.AddFirst("amit");
lst.AddLast("arun");
lst.AddLast("adit");
lst.printAllNodes();
Console.ReadLine();
LinkedList list2 = new LinkedList();
list2.AddFirst("Ajit");
list2.AddLast("Avik");
list2.AddLast("Asha");
//list2.sortedlist(lst);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Memory_understanding
{
public class Node_
{
public Node_ next;
public object data;
}
public class LinkedList
{
private Node_ head;
public void printAllNodes()
{
Node_ current=head;
while(current !=null)
{
Console.WriteLine(current.data);
current=current.next;
}
}
public void AddFirst(Object data)
{
Node_ toadd= new Node_();
toadd.next=head;
toadd.data=data;
head=toadd;
}
public void AddLast(Object data)
{
if(head == null)
{
head = new Node_();
head.data=data;
head.next=null;
}
else
{
Node_ add=new Node_();
add.data=data;
Node_ current= head;
while(current.next !=null)
{
current=current.next;
}
current.next=add;
}
}
public void sortedList(LinkedList lst)
{
LinkedList list1 = this;
}
}
class Prog
{
public static void Main_()
{
LinkedList lst=new LinkedList();
lst.AddFirst("amit");
lst.AddLast("arun");
lst.AddLast("adit");
lst.printAllNodes();
Console.ReadLine();
LinkedList list2 = new LinkedList();
list2.AddFirst("Ajit");
list2.AddLast("Avik");
list2.AddLast("Asha");
//list2.sortedlist(lst);
}
}
Comments
Post a Comment