Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a C# program using WINDOWS FORM App in Visual Studio. THE ANSWER MUST BE IN C#, IN WINDOW FORM APP, IN VISUAL STUDIOS. This

Create a C# program using WINDOWS FORM App in Visual Studio. THE ANSWER MUST BE IN C#, IN WINDOW FORM APP, IN VISUAL STUDIOS.

This is the code that I have so far. I need help answering the problem below. I need the answer to be added to this Form App Below. Thanks!

image text in transcribed

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

namespace Linked_List_Problem

{

public partial class Form1 : Form

{

SingleLinkedList list;

public Form1()

{

InitializeComponent();

list = new SingleLinkedList();

InsertLast(list, 1);

InsertLast(list, 2);

InsertLast(list, 3);

InsertLast(list, 4);

InsertLast(list, 5);

InsertLast(list, 6);

InsertLast(list, 7);

InsertLast(list, 8);

InsertLast(list, 9);

InsertLast(list, 10);

TranverseLinkedList(list);

}

private void Form1_Load(object sender, EventArgs e)

{

}

internal void InsertFront(SingleLinkedList singlyList, int new_data)

{

Node new_node = new Node(new_data);

new_node.next = singlyList.head;

singlyList.head = new_node;

}

internal void InsertLast(SingleLinkedList singlyList, int new_data)

{

Node new_node = new Node(new_data);

if (singlyList.head == null)

{

singlyList.head = new_node;

return;

}

Node lastNode = GetLastNode(singlyList);

lastNode.next = new_node;

}

internal void DeleteNodebyKey(SingleLinkedList singlyList, int key)

{

Node temp = singlyList.head;

Node prev = null;

if (temp != null && temp.data == key)

{

singlyList.head = temp.next;

return;

}

while (temp != null && temp.data != key)

{

prev = temp;

temp = temp.next;

}

if (temp == null)

{

return;

}

prev.next = temp.next;

}

internal void DeleteNodebyIndex(SingleLinkedList singlyList, int index)

{

int nodeIndex = 1;

Node temp = singlyList.head;

Node prev = null;

if (temp != null && nodeIndex == index)

{

singlyList.head = temp.next;

return;

}

while (temp != null && nodeIndex != index)

{

prev = temp;

temp = temp.next;

nodeIndex++;

}

if (temp == null)

{

return;

}

prev.next = temp.next;

}

internal void skipMdeleteN(SingleLinkedList lst, int M, int N)

{

Node curr = lst.head, t;

int count;

while (curr != null)

{

// Skip M nodes

for (count = 1; count

curr = curr.next;

// If we reached end of list, then return

if (curr == null)

return;

// Start from next node and delete N nodes

t = curr.next;

for (count = 1; count

{

Node temp = t;

t = t.next;

//

}

curr.next = t; // Link the previous list with remaining nodes

// Set current pointer for next iteration

curr = t;

}

}

internal Node GetLastNode(SingleLinkedList singlyList)

{

Node temp = singlyList.head;

while (temp.next != null)

{

temp = temp.next;

}

return temp;

}

internal void TranverseLinkedList(SingleLinkedList singlyList)

{

Node temp = singlyList.head;

lblList.Text = "";

while (temp.next != null)

{

lblList.Text += temp.data + "->";

temp = temp.next;

}

lblList.Text += temp.data;

}

private void btnDelete_Click(object sender, EventArgs e)

{

skipMdeleteN(list, Convert.ToInt32(txtM.Text), Convert.ToInt32(txtN.Text));

TranverseLinkedList(list);

}

internal class Node

{

internal int data;

internal Node next;

public Node(int d)

{

data = d;

next = null;

}

}

internal class SingleLinkedList

{

internal Node head;

}

}

}

Remove duplicate element from sorted Linked List Given a linked list of N nodes. The task is to remove duplicates from the given list (if exists). For example if the linked list is 11->11->11->21->43->43->60, then linked list should be converted to 11->21-43->60. Find the middle of a given linked list Given a singly linked list, find middle of the linked list. For example, if given linked list is 1->2->3->4->5 then output should be 3 If there are even nodes, then there would be two middle nodes, we need to print second middle element. For example, if given linked list is 1->2->3>4->5->6 then output should be 4. Recommended approach: (Assuming you don't have access to count) Method 1: Traverse the whole linked list and count the no. of nodes. Now traverse the list again till count/2 and return the node at count/2. Method 2: Traverse linked list using two pointers. Move one pointer by one and other pointer by two. When the fast pointer reaches end slow pointer will reach middle of the linked list

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 11 The Ultimate Database For Cloud Analytics And Mobile

Authors: John Campbell, Chris Crone, Gareth Jones, Surekha Parekh, Jay Yothers

1st Edition

1583474013, 978-1583474013

More Books

Students also viewed these Databases questions