Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Node* createAnEmptyList() {
- Node* head = (Node*)malloc(sizeof(Node));
- //the head->val is never used
- head->next = NULL;
- //head->next will store the pointer to the first elem of the list
- return head;
- }
- Node* createLinkedList(int n) {
- Node* head = createAnEmptyList();
- Node* tail = head;
- for (int i = 0; i < n; i++) {
- head->next = (Node*)malloc(sizeof(Node));
- head = head->next;
- scanf("%d", &(head->value));
- head->next = NULL;
- }
- return tail;
- }
- void pushBack(Node* head, int val) {
- while (head->next != NULL)
- head = head->next;
- head->next = (Node*)malloc(sizeof(Node));
- head->next->value = val;
- head->next->next = NULL;
- }
- void popFront(Node* head) {
- Node* tmp = head->next;
- head->next = head->next->next;
- free(tmp);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement