How do l create a function to delete the letter 'a' from words that start with letter 'a' from a LinkedList for example deleting letter 'a' from word

  • Thread starter Thread starter Isheunesu Tembo
  • Start date Start date
I

Isheunesu Tembo

Guest
using System;
using System.Collections;
using System.Collections.Generic;

namespace LinkedLists
{
class Program
{
static void Main(string[] args)
{
LinkedList linkedList = new LinkedList();

linkedList.AddStart("apple");
linkedList.AddEnd("apricot");
linkedList.AddEnd("banana");
linkedList.AddStart("grapes");
linkedList.RemoveEnd();
linkedList.Display();


}
}


public class Node
{
public object data;
public Node next;

}

class LinkedList
{
Node head;
Node current;
int counter = 0;

public LinkedList()
{
head = new Node();
current = head;
}

public void AddStart(object data)
{

Node newnode = new Node();
newnode.next = head.next;
newnode.data = data;
counter++;
}
public void AddEnd(object data)
{
Node newnode = new Node();
newnode.data = data;
current.next = newnode;
current = newnode;
counter++;

}
public void RemoveStart()
{
if (head.next.ToString().Contains("a") && head.next.next.ToString().Contains("a"))
{
head.next.ToString().Replace("a", " ");
}
if (counter > 0)
{
head.next = head.next.next;
counter--;
}
else
{
Console.WriteLine("No element exists in the linked list");
Console.ReadLine();
}
}
public void RemoveEnd()
{
if (counter > 0)
{
Node prevNode = new Node();
Node cur = head;
while (cur.next != null)
{
prevNode = cur;
cur = cur.next;
}
prevNode.next = null;

string data = cur.data.ToString();

}
else
{
Console.WriteLine("No element exist in this linked list.");
Console.ReadLine();
}
}
public void RemoveLetter()
{

}
public void Display()
{
Console.Write("Head ->");
Node curr = head;
while (curr.next != null)
{
curr = curr.next;
Console.WriteLine(curr.data.ToString());

}
Console.ReadLine();
}
}

}

Continue reading...
 
Back
Top