This C++ program defines a linked list data structure to store student name and grade pairs. It includes functions to initialize an empty list, add nodes by input, print the list, locate a node by position, and delete a node by position. The main function prompts the user to input a list, prints it, prompts for a position to delete, locates and deletes the node at that position, and prints the updated list.
This C++ program defines a linked list data structure to store student name and grade pairs. It includes functions to initialize an empty list, add nodes by input, print the list, locate a node by position, and delete a node by position. The main function prompts the user to input a list, prints it, prompts for a position to delete, locates and deletes the node at that position, and prints the updated list.
This C++ program defines a linked list data structure to store student name and grade pairs. It includes functions to initialize an empty list, add nodes by input, print the list, locate a node by position, and delete a node by position. The main function prompts the user to input a list, prints it, prompts for a position to delete, locates and deletes the node at that position, and prints the updated list.
Node* Locate(int k, LinkList L) { Node* P; int i=1; P = L->Next; while ((P!= NULL) && (i != k)) {i++; P = P->Next; } return P; } //xoa phan tu sau vi tri k void Xoa_PT(LinkList &L,int k) { Node *P,*T; P=Locate(k,L); if (P->Next!=NULL){ T=P->Next; P->Next=T->Next; free(T); } } int main() { Nhap(); Xuat_DS(); Node *t; int k; cout<<"Nhap vi tri can xoa:"; cin>>k; t=Locate(k,L); Xoa_PT(L,k); cout<<"\n DS sau khi xoa:\n"; Xuat_DS(); }