-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvlist.c
96 lines (77 loc) · 1.48 KB
/
vlist.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include<stdio.h>
#include<stdlib.h>
#include<ncurses.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include "hlist.h"
#include "vlist.h"
void init_vlist(vlist *vl){
vl->top = NULL;
vl->bottom = NULL;
}
int vlength (vlist vl){
vnode *temp;
temp = vl.top;
if(temp == NULL) {
return 0;
}
int vlen = 1;
if(temp == vl.bottom){
return vlen;
}
do {
temp = temp->next;
vlen++;
}while(temp != vl.bottom);
return vlen;
}
void vinsert (vlist *vl, hlist *hl, int pos){
vnode *temp, *new_vnode;
int vlen, i = 0;
vlen = vlength(*vl);
if (pos <0 || pos > vlen)
return;
new_vnode = (vnode*)malloc(sizeof(vnode));
new_vnode->row = hl->head;
if(vlen == 0) {
vl->top = new_vnode;
vl->bottom = new_vnode;
new_vnode->prev = NULL;
new_vnode->next = NULL;
return;
}
if(pos == 0) {
new_vnode->next = vl->top;
new_vnode->prev = NULL;
vl->top->prev = new_vnode;
vl->top = new_vnode;
return;
}
if (pos == vlen) {
new_vnode->prev = vl->bottom;
new_vnode->next = NULL;
//new_vnode->row = NULL;
vl->bottom->next = new_vnode;
vl->bottom = new_vnode;
return;
}
temp = vl->top;
for(i = 0; i < pos - 1; i++) {
temp = temp->next;
}
new_vnode->prev = temp;
new_vnode->next = temp->next;
temp->next->prev = new_vnode;
temp->next = new_vnode;
}
void vreplace(vlist *vl, hlist *hl, int y){
vnode *vtemp;
vtemp = vl->top;
while(y--){
vtemp = vtemp->next;
}
vtemp->row = hl->head;
}