| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 11627 | HW2-Linked Lists |
|
Description
The target of this homework is to implement a linked list of integers and each integer would be a node.
You are asked to implement 7 functions below:
You are asked to implement 7 functions below:
1.InsertBack (int data) :Insert a data to the end of the linked list
e.g. A->B → InsertBack (C) → A->B->C
2.DeleteBack() :Delete the end node of the linked the linked list
2.DeleteBack() :Delete the end node of the linked the linked list
e.g. A->B->C → DeleteBack () → A->B
3.InsertFront (int data) :Insert a data to the front of the linked list
e.g. A->B → InsertFront (C) → C->A->B
4.DeleteBack() :Delete the front node of the linked the linked list
e.g. A->B->C → DeleteFront () → B->C
5.InsertAfter (int data1, int data2) :Insert data2 after data1
If data1 doesn’t exist in the linked list, do nothing
e.g. A->C → InsertAfter (A, B) → A->B->C
e.g. A->C → InsertAfter (D, B) → A->C
e.g. A->C → InsertAfter (D, B) → A->C
6.Delete (int data) :Remove the data from the linked list
If data doesn’t exist in the linked list, do nothing
e.g. A->B->C → Delete (B) → A->C
e.g. A->B->C → Delete (Y) → A->B->C
7.Reverse () :Reverse the linked list
e.g. A->B->C → Reverse () → C->B->A
Input
Input will contain function name and integer (depend on the type of the function)
eg:
InsertFront 1
InsertAfter 1 2
Reverse
END
•Note:
1.Integers range from 0 to 99
2.Each node is unique, two duplicate integers won’t exist at the same time
e.g.
25->3->42->77->10
25->3->42->3->10 won’t happened
(the program will deal with I/O, you don't have to take it into consideration)
Output
Output the result of the linked list of integers:
eg:1->2->4->5
(the program will deal with I/O, you don't have to take it into consideration)