Question Using 4D linked List make a Full functional Noted Pad on Winform

just-umair

New member
Joined
Jan 3, 2021
Messages
4
Programming Experience
Beginner
I am creating a data structure project. My task is to use a 4D linked list and display Linked List in Windows form.
How can I display my linked list data in Winform and How can I use Cut Copy paste functions?
 
What is a 4D Linked List?

Why would you need to display it?

How is such a data structure often visualized? Why can't you visualize it the same way?

How is Notepad related to this?

What does clipboard operations like cut, copy, and paste have to do with this data structure?
 
OMG! Our OP has a terrible teacher that has given an assignment like described in this C/C++ assignment:
Create a notepad that allows the user to write text on the console. For this purpose, the user should be
able to control and track the movement of the cursor. The user can access, add and delete any part of
the text. To add or delete a text, the user can take the cursor to that location (using the arrow keys) and
perform the required operation. The working of the program (i.e. the movement of the cursor, add and
delete operation) must be consistent with the working of the real notepad. However, you do not have
to handle word wrapping.

In addition, the user should be able to save and load the data in a text file using S and L respectively.
The program will automatically save the data in file save.txt, and load the data from the same file.
There is no need to ask the user for the file name. Use Q to quit the notepad. Don’t forget to
implement the destructor.

Internally, the notepad is composed of two-dimensional doubly linkedlist. Its implementation is just
like a doubly linked list with an additional property that it can grow in two dimensions. Since text can
be written on multi lines, each row of the 2D-linkedlist represents one line. Each node contains four
links which it uses to connect to node before, after, below and above it. In addition each node can store
a character.

This is a terrible approach to doing a text editor. Consider that a basic node looks like this:
C#:
class Node
{
    public char Char { get; set; }
    public Node Before { get; set; }
    public Node After { get; set; }
    public Node Above { get; set; }
    public Node Below { get; set; }
}

On a 64 bit machine, each of those 4 references to Nodes will take up 8 bytes each. That character that is held there will take up 2 bytes (because in .NET Framework Char's are 16-bit). And I suspect that the compiler will also put in some padding between the character and the first reference to get it at the appropriate alignment, so effectively the entire Node will use up either 2 + 2 + 4 * 8 == 36 bytes, or 2 + 6 + 4 * 8 == 40 bytes. That's per character. So a text file that is composed of 1MB of ASCII text will use up 36MB to 40MB of RAM. That's a terrible text editor. Even Visual Studio, the memory hog that it is, does not have that kind of ratio of content to memory overhead.

Yes, yes, I know that the link I have above describes a 2D doubly linked list, but this other link with less details also has essentially the same assignment, and the OP on that thread calls his data structure a 4D linked list.
 
I know this is a terrible approach to create a notepad. But that's the project I have to do. I am stuck in this shit. SO I have to do this code. Anyway, I successfully creat a 4 D note pad using Cpp. If you want to have a look check the attached file. I am facing an issue in getting data from the user Cause I can't use the console.read() so is there any way to creat a code
 

Attachments

  • notepad.txt
    12.3 KB · Views: 89
I see in your C++ code that you are using _getch(). The .NET Framework's Console.Read() is pretty much equivalent to _getch().

Also, I see in your C++ code that you are familiar with using the Windows Console APIs. If you are having trouble with Console.Read() you could just use P/Invoke calls to call the Windows Console APIs directly. Basically the Console class is just a nice wrapper around the Console APIs. Nobody says that you have to use that wrapper if you know a better way.
 
I see in your C++ code that you are using _getch(). The .NET Framework's Console.Read() is pretty much equivalent to _getch().

Also, I see in your C++ code that you are familiar with using the Windows Console APIs. If you are having trouble with Console.Read() you could just use P/Invoke calls to call the Windows Console APIs directly. Basically the Console class is just a nice wrapper around the Console APIs. Nobody says that you have to use that wrapper if you know a better way.
I am fresh to C# and inform. I have experience in Cpp. Can you explain to me a Lil bit more about how should I use to get user inputs using P/invoke call.
Hmmm. In c++ I use std::cin to get data from users now how I can get data from users? Thanks a lot for help :)
 
You mean to tell me you didn't understand any of your Console API calls for highlighting, moving the cursor, etc.? Did you just copy and pasted that code without understanding?

Umm. _getch() does not use std::cin.

Anyway, I'm sorry. I misspoke about the equivalence of _getch() and Console.Read(). The equivalent is Console.ReadKey().

To learn more about P/Invoke, see here:

The Console APIs are listed here:
The function names are pretty self-explanatory.
 
This is a terrible approach to doing a text editor.
Of course it is, but that's not the point. The point of assignments like this is not to create a useful application but to demonstrate that you understand how to use the building blocks. This assignment is about linked lists and a text editor is just a means to an end. Assignments like this are always contrived because it's almost impossible to isolate specific things you want to test otherwise.
 
But here's a better approach that uses two doubly linked lists that is more efficient:
C#:
class Line
{
    public Line Above { get; set; }
    public Line Below { get; set; }
    public TextRun FirstRun { get; set; }
}

class TextRun
{
    public TextRun Next { get; set; }
    public TextRun Previous { get; set; }
    pubic string Text { get; set; }
    public Formatting Formatting { get; set; }
}
 
Back
Top Bottom