1. Trang chủ
  2. » Luận Văn - Báo Cáo

The project final report doubly linked list by c++

52 1 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Doubly Linked List By C++
Tác giả Nguyen Thi Phu
Người hướng dẫn Phd. Le Van Vinh
Trường học Trường Đại Học Sư Phạm Kỹ Thuật Tp. Hồ Chí Minh
Chuyên ngành Công Nghệ Thông Tin
Thể loại Project Final Report
Năm xuất bản 2022
Thành phố Tp. Hồ Chí Minh
Định dạng
Số trang 52
Dung lượng 3,89 MB

Nội dung

Install Doubly Linked List, Queue Structure, Hash Tableand their... PROJECT 1.1 : DOUBLY LINKED LIST BY C++ : − A Linked List is a list which includes one or many NODE, we define a NODE

Trang 1

BỘ GIÁO DỤC VÀ ĐÀO TẠO TRƯỜNG ĐẠI HỌC SƯ PHẠM KĨ THUẬT TP HỒ CHÍ MINH

KHOA CÔNG NGHỆ THÔNG TIN

******************

THE PROJECT FINAL REPORT INSTRUCTOR : PhD LE VAN VINH SUBJECT CODE : DASA230179_22_1_10 STUDENT : NGUYEN THI PHU STUDENT ID : 21110600

TP HỒ CHÍ MINH THÁNG 12 NĂM 2022 -

Trang 2

Name ID Task Completion rate

1 Install Doubly Linked List, Queue Structure, Hash Tableand their fucntions

2 Install Grapical User Interface (Winform)

3 Edit and check the program

100%

* Evaluation :

….………

………

………

………

………

………

Instructor

PhD Le Van Vinh

Trang 3

I PROJECT 1.1 : DOUBLY LINKED LIST BY C++ :

− A Linked List is a list which includes one or many NODE, we define a NODE has at least two elements : <data_type> data and NODE next We use the element data to store the users’ data, and the element next to link

to the others We use NODE head and NODE tail to manage our linked list easily

− A Doubly Linked List contains an extra pointer : NODE previous, typically called the previous pointer, together with the next pointer and data which are there in the Singly Linked List

− Installing by C++ language programming “struct” data type for the COFFEE products :

− Then we will install The Doubly Linked List’s functions :

1 Initializing the Doubly Linked List :

− By assigning NODE Head and NODE Tail equals NULL, we have finished the initialization

void initList(DoublyLinkedList& myList)

{

myList.Head = NULL;

myList.Tail = NULL;

}

Trang 4

2 Creating new NODE :

3 Checking the list whether it is full or empty :

bool isEmpty(DoublyLinkedList myList)

4 Showing the data of the list :

− By traversing the linked list, we have the value of it We traverse from the first NODE (NODE Head) to the last NODE (NODE Tail) and get the data

Trang 5

void showANode(NODE* X)

{

cout << "The coffee name : " << X->data.name << endl;

cout << "The concentration : " << X->data.cafein << " %" << endl;cout << "The amount : " << X->data.count << endl;

cout << "The orginal : " << X->data.sourcecost << " VND" << endl;cout << "The agio : " << X->data.salecost << " VND" << endl;}

5 Insertion in Doubly Linked List :

At the front of the Doubly Linked List :

void addFirst(DoublyLinkedList& myList, COFFEE X)

Trang 6

At the end of the Doubly Linked List :

void addLast(DoublyLinkedList& myList, COFFEE X)

Trang 7

At the position of the Doubly Linked List :

void addPosition(DoublyLinkedList& myList, int k, COFFEE X)

Trang 8

6 Removing an element out of the list :

At the front of the Doubly Linked List :

void removeFisrt(DoublyLinkedList& myList)

Trang 9

At the end of the Doubly Linked List :

void removeLast(DoublyLinkedList& myList)

Trang 10

At the position of the Doubly Linked List :

void removePosition(DoublyLinkedList& myList, int k)

The NODE chosen :

− We make full use of the remove at the front of the list and remove at the end of the list to install this function If the NODE chosen is the first NODE

of the Doubly Linked List we utilise removeFirst function, in case of it is the last NODE of the Doubly Linked List we can use removeLast function When the NODE isn’t drop in 2 cases mentioned we will install as the diagram :

Trang 11

void removeNode(DoublyLinkedList& myList, NODE* p)

7 Working with File handling :

− We have a file “COFFEE.txt”, and then we transfer the data from it to the Doubly Linked List through some procedures :

+ Step 1 : Read file

+ Step 2 : Define the structure of the file An element is defined by 5 atributtes : name, cafein, count, original cost and salecost

+ Step 3 : Use the addLast(DoublyLinkedList& myList) function to insert

an element respectively

Trang 14

8 Searching by name of the Coffee product :

− By traversing the Doubly Linked List from the first NODE to the last NODE, if the program find the name of the Coffee we want to search, it return its data, In case of not being found, it returns the NULL value NODE* searchByName(DoublyLinkedList myList, string s)

9 Seaching the List of low cost :

− We use the addLast() method to add an new item with satisfied requirement

In this case, if the cost's Coffee products less than k, return the List of them DoublyLinkedList searchByLowCost(DoublyLinkedList myList, int k)

10 Sorting for data of the Doubly Linked List :

− In this report, we will install the Selection Sort and Quick Sort Algorithm for this problem Two atributtes we choose to sort are : name’s and salecost’s products

− Step 1 : Create and initialize new list named as newList

Trang 15

− Step 2 : Use while-loop until my list is empty

− Step 2.1 : Assign NODE Head to NODE q

− Step 2.2 : Traverse from the second NODE to the last NODE in the list If the value (name or salecost) of NODE q is less than the element traversed,

we will do the next step 2.3 and 2.4 Else we continue traversing to the last NODE

− Step 2.3 : Use the add last fucntion (addLast(DoublyLinkedList& myList, COFFEE X)) to insert this element

− Step 2.4 : Use the remove node function (

void selectionSort(DoublyLinkedList myList)

− Step 1 : Seperate the Doubly Linked List into two smaller List

− Step 2 : Check whether myList is empty or not If it is empty return the program and do not anything

− Step 3 : Choose the pivot item (It can be a NODE Head) and remove it from List

− Step 4 : Traverse the Doubly Linked List, and add the item into two List initialized Remember to remove it

− Step 5 : Use the Recursion Function for two List initialized

− Step 6 : Concatenate new List 1 - pivot - new List 2

void quickSort(DoublyLinkedList& myList)

{

DoublyLinkedList mynewList1, mynewList2;

initList(mynewList1); initList(mynewList2);

if (myList.Head == myList.Tail) return;

NODE* pivot = createNode(myList.Head->data);

NODE* p = myList.Head->next;

Trang 16

myList.Head = NULL;

while (p != NULL)

{

if(p->data.name.compare(pivot->data.name) <= 0) addLast(mynewList1,p->data);

Trang 17

void mergeList(DoublyLinkedList& X, DoublyLinkedList Y)

Filtering the low count coffee products :

void removeLowCount(DoublyLinkedList& myList)

Trang 18

DoublyLinkedList requestByCost(DoublyLinkedList myList, long k)

− Instead of using "Struct" as C++, in C# - an oriented programming language, we create classes like each of struct

❖ Build Class COFFEE :

public class COFFEE

{

public string name;

public double cafein;

public int count;

public int original_cost;

public int sale_cost;

}

❖ Build Class NODE :

public class NODE

{

public COFFEE data;

public NODE prev;

public NODE next;

}

❖ Build Class Doubly Linked List :

− We just transfer the code in C++ into C# language by fixing grammar error public class DoublyLinkedList

{

public NODE Head;

public NODE Tail;

Trang 19

Create new Node :

public NODE createNode(COFFEE X) {

NODE tmp = new NODE(); tmp.data = X;

tmp.prev = null;

tmp.next = null;

return tmp;

}

Check List is empty or full :

public bool isEmpty()

Add a new item :

public void addFirst(COFFEE X) {

NODE tmp = createNode(X);

if (isEmpty())

this.Head = this.Tail = tmp; else

{

tmp.next = this.Head; this.Head.prev = tmp; this.Head = tmp;

Trang 20

Remove an old item :

public void removeFisrt()

Trang 21

else

{

if (this.Head == this.Tail) this.Head = this.Tail = null; else

{

NODE tmp = this.Tail; this.Tail = this.Tail.prev; this.Tail.next = null; tmp = null;

Trang 23

public void quickSort()

{

DoublyLinkedList mynewList1 = new DoublyLinkedList(); DoublyLinkedList mynewList2 = new DoublyLinkedList(); mynewList1.initList();

mynewList2.initList();

if (this.Head == this.Tail) return;

NODE pivot = createNode(this.Head.data);

Trang 25

Initializing the Doubly Linked List and Getting String Connection :

string strCon = @"Data Source=MSI;Initial Catalog = Coffee;Integrated Security=True";

DoublyLinkedList myList = new DoublyLinkedList();

COFFEE tmp = new COFFEE();

SqlConnection sqlCon = null;

Constructor :

public Form1()

{

InitializeComponent();

Trang 26

SqlDataReader reader = sqlCmd.ExecuteReader();while (reader.Read())

{

COFFEE mycoffee = new COFFEE();

mycoffee.name = reader.GetString(0);

mycoffee.cafein = reader.GetDouble(1);mycoffee.count = reader.GetInt32(2);

mycoffee.original_cost = reader.GetInt32(3);mycoffee.sale_cost = reader.GetInt32(4);myList.addLast(mycoffee);

}

reader.Close();

}

Creating Text Box Number 0 :

private void name_Enter(object sender, KeyEventArgs e) {

if (e.KeyData == Keys.Enter)

textBox2.Focus();

}

Creating Text Box Number1 :

private void cafein_Enter(object sender, KeyEventArgs e) {

if (e.KeyData == Keys.Enter)

textBox3.Focus();

}

Creating Text Box Number 2 :

private void count_Enter(object sender, KeyEventArgs e) {

try

{

if (e.KeyData == Keys.Enter)

Trang 27

}

catch(FormatException ex)

{

string notify = ex.Message;

MessageBox.Show("The error : " + notify, "System

Announcement",MessageBoxButtons.RetryCancel);

}

}

Creating Text Box Number 3 :

private void original_Enter(object sender, KeyEventArgs e)

string notify = ex.Message;

MessageBox.Show("The error : " + notify, "System

Announcement", MessageBoxButtons.RetryCancel);

}

}

Creating Text Box Number 4 :

private void sale_Enter(object sender, KeyEventArgs e)

DialogResult result = MessageBox.Show("Do you want to save

?", "System Announcement", MessageBoxButtons.YesNo); if(result == DialogResult.No)

Trang 28

{ textBox1.Text = "";

Announcement",MessageBoxButtons.OK);

} }

}

catch (FormatException ex)

{

string notify = ex.Message;

MessageBox.Show("The error : " + notify, "System Announcement", MessageBoxButtons.RetryCancel);

}

}

Creating Add First Button :

private void addFirstClick(object sender, EventArgs e)

Creating Add Last Button :

private void addLastClick(object sender, EventArgs e)

Trang 29

Creating Refresh Button :

− When we click it, the concepts in listBox1 will be deleted private void refresh_Click(object sender, MouseEventArgs e) {

foreach (ListViewItem eachItem in listView1.Items){

listView1.Items.RemoveAt(eachItem.Index);}

}

Creating Remove First method in MenuStrip :

private void removeFirst_Click(object sender, EventArgs e){

}

}

Creating Remove Last method in MenuStrip :

private void removeLast_Click(object sender, EventArgs e){

Trang 30

}

Creating Search method :

− Using the KeyDown Event to search the information of coffee If it does not exist, create a MessageBox with the text : "There are no result !"

private void search_KeyDown(object sender, KeyEventArgs e)

Creating Search low cost Coffee products :

private void cheapProducts_Click(object sender, EventArgs e)

{

Trang 31

DoublyLinkedList result = myList.searchByLowCost(35000);

Creating Sort by Name in MenuStrip :

private void sort_Name(object sender, EventArgs e)

listView1.Items.Add(item);

}

}

Trang 32

Creating Sort by Sale Cost in MenuStrip :

private void sortSaleCost_Click(object sender, EventArgs e) {

for (int i = 0; i < listView1.Items.Count; i++)

}

myList = result;

}

Trang 33

Creating Show method in MenuStrip :

private void showToolStripMenuItem_Click(object sender, EventArgs e) {

for (NODE p = myList.Head; p != null; p = p.next)

Creating Close method in MenuStrip :

private void close_Click(object sender, EventArgs e)

{

this.Close();

Trang 34

− In this report we only choose STACK or QUEUE to install and build the

program from its application We will build a game “MINESWEEPER”

by C Sharp Window Form (.NET) to be friendly with users

− A Queue is defined as a linear Data Structure that is open at both ends and the operations are performed in First In First Out (FIFO) order

− We define a QUEUE to be a list in which all additions to the list are made

at one end, and all deletions from the list are made at the other end The element which is first pushed into the order, the operation is first performed

on that

− Installing by C Sharp language : As a Doubly Linked List, we will do 2 main tasks

+ Step 1 : We build a class NODE to store two attributes : <data_type> data

and NODE next

+ Step 2 : We build a class QUEUE includes 2 NODES : NODE front

(NODE Head) and NODE rear (NODE Tail) and write its methods Its main methods have : Enqueue(), Dequeue() and Front()

▪ Enqueue method : It is the same as addLast() function

▪ Dequeue method : It is the same as removeFirst() function and get the value of NODE front

▪ Front : Get the value of NODE front but not removing

❖ Build Class NODE :

public class NODE

{

public int data;

public NODE next;

Trang 35

Checking the QUEUE whether is empty or not :

public bool isEmpty()

Trang 36

− Advanced by NET Winform : MINESWEEPER is a matrix including many

buttons So we will build a class ButtonBoom inherits from class Button We consider a matrix is a two-dimension ButtonBoom Array In this game we choose matrix’s size [23,23] to play, because it fits the Form1 builded

− Class Form1 includes :

+ Matrix of ButtomBoom

static ButtonBoom[,] mybtn = new ButtonBoom[23, 23];

+ Constructor to create Form

public Form1()

{

InitializeComponent();

}

− Class ButtomBoom includes 5 atributtes :

+ bool isBoom = false : to check the buttom whether is boom or not and its default value is false, after that we will build a method to drop some booms randomly

• True : if it is boom

• False : if it is not boom

+ int state : to point the buttom whether is opened or not

• Value 0 : is not opened

• Value 1 : is opened.

+ int boom_arround; to count the surroundings boom

+ int i,j : to point the coordinate in matrix or index of button

❖ Buid Class Form1 :

Trang 37

Close Button method :

− Design Close Button Image : Choose Properties, then set an image

Play Button method :

private void startButton_Click(object sender, EventArgs e)

{

setButtonArr();

}

Set Button Matrix method :

private void setButtonArr()

Trang 38

mybtn[i, j].Text = "";

mybtn[i, j].Size = new Size(40, 40);

mybtn[i, j].BackColor = Color.Gray;

mybtn[i, j].Top = top;

mybtn[i, j].Left = left;

Creating Boom method :

− To drop boom randomly, a number of boom are 80 We choose modulo operation to distribute evenly When it is chosen a boom, assign isBoom atributte to true

private void createBoom()

Trang 39

}

}

}

Count Boom surroundings method :

private void countBoomArround()

for (int y = j - 1; y <= j + 1; y++)

if ((x < 23 && y < 23) &&(x >= 0 && y >= 0)&&

!(x == i && y == j))

if (mybtn[x, y].isBoom)count++;

mybtn[i, j].boom_arround = count;

}

}

❖ Build Class ButtonBoom :

Atributtes of ButtomBoom :

public bool isBoom = false;

public int i,j;

public int boom_arround;

public int state;

public void BFS(ButtonBoom bt)

{

int[] dx = new int[8] { -1, -1, -1, 0, 0, 1, 1, 1 };

int[] dy = new int[8] { -1, 0, 1, -1, 1, -1, 0, 1 };

QUEUE q = new QUEUE();

Ngày đăng: 09/04/2024, 16:11

TỪ KHÓA LIÊN QUAN

w