Created
January 23, 2019 17:32
-
-
Save dertst/c4c7d2431513be457b2c58061192b8a4 to your computer and use it in GitHub Desktop.
список
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ConsoleApplication3.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы. | |
// | |
#include "pch.h" | |
#include <iostream> | |
struct Node { | |
int value=10; | |
struct Node *next; | |
struct Node *prev; | |
}; | |
struct List { | |
struct Node* first; | |
struct Node* last; | |
}; | |
struct List* create() { | |
struct List* list = (struct List*)malloc(sizeof(struct List)); | |
list->first = NULL; | |
list->last = NULL; | |
return list; | |
} | |
void insert(int value, struct List* list) | |
{ | |
if (list->first == NULL && list->last == NULL) | |
{ | |
struct Node* node = (struct Node*)malloc(sizeof(struct Node)); | |
node->value = value; | |
node->next = NULL; | |
node->prev = NULL; | |
list->first = node; | |
list->last = node; | |
} | |
else { | |
struct Node* node = (struct Node*)malloc(sizeof(struct Node)); | |
node->value = value; | |
node->prev = list->last; | |
node->next = NULL; | |
list->last = node; | |
} | |
//printf("%d", s.value); | |
//s.value += 10; | |
//s.next = s; | |
printf("List: %d\n", list->last->value); | |
} | |
int main() | |
{ | |
struct List* list = create(); | |
insert(5, list); | |
insert(10, list); | |
insert(15, list); | |
insert(20, list); | |
insert(25, list); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment