Program_LinkedList
Program_LinkedList
//Practice 1
#include <stdio.h>
#include <stdlib.h>
//Câu a
int data;
}Node;
Node* head;
}LinkedList;
list->head = NULL;
if (new_node == NULL) {
exit(1);
new_node->data = data;
new_node->next = NULL;
return new_node;
new_node->next = list->head;
list->head = new_node;
node = node->next;
printf("\n");
list->head = list->head->next;
free(node);
//Hàm main
int main(){
LinkedList list;
init(&list);
insertHead(i, &list);
printList(&list);
insertHead(15,&list);
printList(&list);
deleteHead(&list);
printList(&list);
return 0;
}
Practice 2
//Practice 2
#include <stdio.h>
#include <stdlib.h>
int data;
}Node;
Node* head;
}LinkedList;
list->head = NULL;
if (new_node == NULL) {
exit(1);
new_node->data = data;
new_node->next = NULL;
return new_node;
}
new_node->next = list->head;
list->head = new_node;
if (list->head == NULL) {
list->head = new_node;
return;
node = node->next;
node->next = new_node;
node = node->next;
printf("\n");
//Xóa ở đầu
list->head = list->head->next;
free(node);
//Xóa ở cuối
node = node->next;
free(node->next);
node->next = NULL;
//Hàm main
int main(){
LinkedList list;
init(&list);
int i = 0, n = 7;
insertHead(array[i], &list);
printList(&list);
insertHead(19,&list);
printList(&list);
insertTail(-3,&list);
printList(&list);
deleteHead(&list);
printList(&list);
deleteTail(&list);
printList(&list);
return 0;
Homework
//Homework 01
#include <stdio.h>
#include <stdlib.h>
typedef struct NodeType {
int data;
}Node;
Node* head;
}LinkedList;
list->head = NULL;
if (new_node == NULL) {
exit(1);
new_node->data = data;
new_node->next = NULL;
return new_node;
new_node->next = list->head;
list->head = new_node;
if(k == 1){
insertHead(data, list);
return;
int pos = 1;
while(node != NULL)
pos++;
if(pos == k){
new_node->next = node->next;
node->next = new_node;
break;
} else {
node = node->next;
if (node == NULL)
}
}
list->head = list->head->next;
free(node);
if(k == 1){
deleteHead(list);
return;
int pos = 1;
node = node->next;
pos++;
if (node == NULL) {
} else {
free(node->next);
node->next = node->next;
node = node->next;
printf("\n");
int main()
LinkedList list;
init(&list);
int i = 0, n = 5;
insertHead(array[i], &list);
printList(&list);
Insert(1,9,&list);
printList(&list);
Delete(3,&list);
printList(&list);
return 0;