-
Notifications
You must be signed in to change notification settings - Fork 0
/
03 SingleList.cpp
73 lines (65 loc) · 1.18 KB
/
03 SingleList.cpp
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
/*
* @Description:
* @Author: HailayLin
* @Date: 2021-12-14 17:13:09
* @LastEditTime: 2021-12-14 20:10:36
* @FilePath: \Algorithm\03 SingleList.cpp
*/
/**
Beijing Tianjin Shanghai Chongqing Tangshan
*/
#include<iostream>
#include<string>
#include<bits/stdc++.h>
using namespace std;
typedef int Status;
typedef string ElemType;
#define OK 1
#define ERROR 0
typedef struct LNode {
ElemType data;
LNode *next;
}LNode, *LinkList;
Status InitList(LinkList &L) {
L = new LNode;
L->next = NULL;
return OK;
}
Status showList(LinkList L) {
if(L->next == NULL) {
cout << "empty!" << endl;
return ERROR;
}
else {
LinkList p = L->next;
int i = 1;
while (p != NULL) {
cout << i++ << ":" << p->data << endl;
p = p->next;
}
}
return OK;
}
Status CreateList_R(LinkList &L, int num) {
LinkList p = L;
string str;
for (int i=0; i<num; i++) {
cin >> str;
//cout << str << endl;
LNode *s = new LNode;
s->data = str;
s->next = NULL;
p->next = s;
p = s;
}
return OK;
}
int main()
{
LinkList Lname;
InitList(Lname); //놓迦뺏데졍깊
showList(Lname); //데졍깊깁저
CreateList_R(Lname,5); //빈꿨랬눼쉔데졍깊
showList(Lname); //데졍깊깁저
return 0;
}