Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <assert.h>
- #include "push.h"
- void
- linked_list_node_insert(node_t *sptr,
- char c)
- {
- sptr = malloc(sizeof(node_t));
- node_t *newNode ;
- newNode = (node_t*)malloc(sizeof(node_t));
- newNode->word = c;
- newNode->next = NULL;
- if (sptr->next == NULL)
- {
- sptr->next = newNode;
- }
- node_t *cur = sptr;
- /*while (cur->next == NULL)
- {
- last = cur;
- cur = cur->next;
- }*/
- printf("original last character is: %c", last->word);
- printf("\n");
- last->next = newNode;
- return;
- }
- void
- linked_list_printlist(node_t *sptr)
- {
- node_t *cur ;
- printf("%c\n", cur->word);
- printf("linked_list_printlist: ");
- if(cur != NULL)
- {
- printf("%c", cur->word);
- printf((cur->next != NULL) ? "\n" : " ");
- cur = cur->next;
- }
- if(cur == NULL)
- {
- printf("is no data\n");
- return;
- }
- }
- char linked_list_node_all_delete(node_t *sptr)
- {
- node_t *current, *head;
- head = sptr;
- while( head != NULL)
- {
- current = head;
- head = current->next;
- free(current);
- }
- if(head == NULL)
- {
- printf("node is empty \n");
- }
- return 0;
- }
- int main()
- {
- node_t s ;
- linked_list_node_insert(&s, 'a');
- linked_list_node_insert(&s, 'b');
- linked_list_node_insert(&s, 'c');
- linked_list_printlist(&s);
- ///linked_list_node_all_delete(s);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement