Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdlib.h>
- #include<stdio.h>
- #include<string.h>
- #include<ctype.h>
- typedef struct SNode_
- {
- struct SNode_ *prev, *next;
- int v;
- } SNode;
- typedef struct SList2_
- {
- SNode *first, *last, *cur;
- } SList2;
- void Add(SList2 *l, int v);
- void Scan(SList2 *l, int n);
- void Print(SList2 *l);
- SList2 *Create(void);
- SList2 *Create(void)
- {
- SList2 *l;
- l = (SList2*)malloc(sizeof(*l));
- l -> cur = l -> first = l -> last = NULL;
- return l;
- }
- void Add(SList2 *l, int v)
- {
- SNode *n;
- n = (SNode*)malloc(sizeof(*n));
- n -> v = v;
- n -> prev = n -> next = NULL;
- if (l -> cur == NULL)
- {
- l -> cur = l -> first = l -> last = n;
- }
- else
- {
- n -> prev = l -> cur;
- n -> next = l -> cur -> next;
- l -> cur -> next = n;
- if (n -> next) n -> next -> prev = n;
- else l -> last = n;
- }
- }
- void Scan(SList2 *l, int n)
- {
- int x = n + 1;
- for (int i = 0; i < n; i++)
- {
- x -= 1;
- Add(l, x);
- }
- }
- void Print(SList2 *l)
- {
- SNode *n = l -> first;
- printf("%d", n -> v);
- while (l -> cur != NULL)
- {
- printf("%d", n -> v);
- if (n -> next != NULL)
- {
- n = n -> next;
- }
- }
- }
- int main(void)
- {
- SList2 *l;
- l = Create();
- Scan(l, 6);
- Print(l);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement