Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct Node {
- int data;
- struct Node *next;
- } node_t;
- typedef struct List {
- node_t *b_node;
- node_t *c_node;
- } list_t;
- void print_list(list_t *list);
- void add_start(list_t *list, int new_data);
- void add_end(list_t *list, int new_data);
- int main(int argc, char *argv[])
- {
- list_t *List = (list_t *)malloc(sizeof(list_t));
- node_t *head = (node_t *)malloc(sizeof(node_t));
- node_t *second = (node_t *)malloc(sizeof(node_t));
- node_t *third = (node_t *)malloc(sizeof(node_t));
- node_t *fourth = (node_t *)malloc(sizeof(node_t));
- node_t *fifth = (node_t *)malloc(sizeof(node_t));
- head->data = 1;
- head->next = NULL;
- List->b_node = head;
- List->c_node = NULL;
- /*
- second->data = 2;
- second->next = third;
- third->data = 3;
- third->next = fourth;
- fourth->data = 4;
- fourth->next = fifth;
- fifth->data = 5;
- fifth->next = NULL;
- */
- return 0;
- }
- void add_start(list_t *list, int new_data)
- {
- if(NULL == list) {
- fprintf(stderr, "You fucked up!\n");
- fflush(stderr);
- return;
- }
- node_t *new = (node_t *)malloc(sizeof(node_t));
- new->data = new_data;
- new->next = list->b_node;
- list->b_node = new;
- }
- void print_list(list_t *list)
- {
- node_t *current = list->b_node;
- while(current != NULL) {
- printf("%d\n", current->data);
- current = current->next;
- }
- }
- void add_end(list_t *list, int new_data)
- {
- if(NULL == list) {
- fprintf(stderr, "You fucked up!\n");
- fflush(stderr);
- return;
- }
- node_t *new = (node_t *)malloc(sizeof(node_t));
- new->data = new_data;
- if(list->c_node->next == NULL) {
- list->c_node->next = new;
- new->next = NULL;
- return;
- }
- }
Add Comment
Please, Sign In to add comment