要求:
- 逐行讀取指定文件中的數(shù)據(jù)妓雾,解析后保存在順序表中炮温。其中撤蟆,文件中每行數(shù)據(jù)格式為“學(xué)號(hào),姓名,年 齡”奕塑,比如“10225048,張三,24”(提示:采用順序表結(jié)構(gòu)時(shí),順序表中每個(gè)表元素包含三類信息:學(xué)號(hào)家肯,姓名龄砰,和年齡;采用單鏈表結(jié)構(gòu)時(shí)讨衣,單鏈表中每個(gè)結(jié)點(diǎn)的數(shù)據(jù)域包含三類信息:學(xué)號(hào)换棚,姓名,和年齡)反镇,
- 根據(jù)鍵盤輸入進(jìn)行相關(guān)操作固蚤,比如,若鍵盤輸入為“P3”歹茶,則打印出第3項(xiàng)信息(注意:采用順序表結(jié)構(gòu)時(shí)夕玩,第3項(xiàng)數(shù)據(jù)對(duì)應(yīng)下標(biāo)為2的表元素你弦;采用單鏈表結(jié)構(gòu)時(shí),第3項(xiàng)數(shù)據(jù)對(duì)應(yīng)鏈表中第3個(gè)結(jié)點(diǎn)的信息燎孟;)禽作;若鍵盤輸入為“D3”,則刪除第3個(gè)表元素揩页;若鍵盤輸入為“I3,10225038,張四,24”旷偿,則在第3項(xiàng)前插入一個(gè)學(xué)生的信息(10225038,張四,24)。
實(shí)現(xiàn)代碼:
- 頭文件
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
#include <conio.h>
#define LIST_INCREASEMENT 10
#define ORIGINA_DATA_NUM 8
#define SIZE 256
typedef struct
{
char id[SIZE] = { 0 };
char name[SIZE] = { 0 };
char age[SIZE] = { 0 };
}student;
typedef struct
{
student *element;
int list_curr_length;
int list_size;
}SqList;
typedef struct LNode
{
student *data;
struct LNode *next;
}LinkNode;
int SqListMain(void);
int LinkedListMain(void);
void SqListInstr(void);
void DisplaySqList(SqList *L);
void InitSqList(SqList *&L);
void SqListEmpty(SqList *L);
void SqListLength(SqList *L);
void DestroySqList(SqList *&L);
bool SqListInsert(SqList *&L, int i, student e);
bool SqListDelete(SqList *&L, int i);
bool SqListGetInsert(SqList *&L);
bool PrintSqList(SqList *L, int i);
int LinkedListMain(void);
void LinListLength(LinkNode *L);
void LinListInstr(void);
void InitLinList(LinkNode *&L);
void DisplayLinList(LinkNode *L);
void DestroyLinList(LinkNode *&L);
void EmptyLinList(LinkNode *L);
bool LinListGetInsert(LinkNode *&L);
bool LinListDelete(LinkNode *&L, int i);
bool LinListInsert(LinkNode *&L, int i, student e);
- Sequence List 實(shí)現(xiàn):
#include "head.h"
SqList *L;
bool flag_1 = false;
void InitSqList(SqList *&L)
{
L = (SqList *)malloc(sizeof(SqList));
L->element = (student *)malloc(sizeof(student) * 100);
L->list_size = 100;
L->list_curr_length = 0;
}
void DestroySqList(SqList *&L)
{
free(L);
}
void SqListEmpty(SqList *L)
{
if (L->list_curr_length == 0)
printf("\n順序表為空爆侣。\n\n");
else
printf("\n順序表不為空萍程。\n\n");
return;
}
void SqListLength(SqList *L)
{
printf("\n順序表長(zhǎng)度為:%d\n\n", L->list_curr_length);
return;
}
void DisplaySqList(SqList *L)
{
if (!L->list_curr_length)
{
printf("列表為空,無(wú)法打印累提。\n");
return ;
}
printf("----------------------------\n\n");
for (int i = 0; i < L->list_curr_length; i++)
printf("%s, %s, %s\n", L->element[i].id, L->element[i].name, L->element[i].age);
printf("----------------------------\n");
return;
}
bool PrintSqList(SqList *L, int i)
{
if (i < 1 || i > L->list_curr_length)
{
printf("輸入有誤尘喝,當(dāng)前順序表長(zhǎng)度為%d,請(qǐng)重新輸入斋陪。\n", L->list_curr_length);
return false;
}
i--;
printf("\n%s, %s, %s\n", L->element[i].id, L->element[i].name, L->element[i].age);
printf("\n");
return true;
}
/*
bool SqListGetElem(SqList *L, int i)
{
if (i < 1 || i > L->list_curr_length)
{
printf("輸入有誤朽褪,當(dāng)前順序表長(zhǎng)度為%d,請(qǐng)重新輸入无虚。\n", L->list_curr_length);
return false;
}
i--;
printf("\n%s, %s, %s\n", L->element[i].id, L->element[i].name, L->element[i].age);
printf("\n");
return true;
}
*/
/*
int SqListLocateElem(SqList *L, student e)
{
int i = 0;
while (i < L->list_curr_length && L->element[i].id != e.id)
i++;
if (i >= L->list_curr_length)
return 0;
else
return i + 1;
}
*/
bool SqListInsert(SqList *&L, int i, student e)
{
int j;
if (i < 1 || i > L->list_curr_length + 1)
{
printf("輸入有誤缔赠,當(dāng)前順序表長(zhǎng)度為%d,請(qǐng)重新輸入友题。\n", L->list_curr_length);
return false;
}
i--;
if (L->list_curr_length >= L->list_size)
{
student *new_element;
new_element = (student *)realloc(L->element, L->list_size + LIST_INCREASEMENT);
L->element = new_element;
L->list_size += LIST_INCREASEMENT;
}
for (j = L->list_curr_length; j > i; j--)
{
strcpy(L->element[j].age, L->element[j - 1].age);
strcpy(L->element[j].id, L->element[j - 1].id);
strcpy(L->element[j].name, L->element[j - 1].name);
}
strcpy(L->element[i].id, e.id);
strcpy(L->element[i].name, e.name);
strcpy(L->element[i].age, strcat(e.age, "\n"));
/*
memcpy(L->element[i].id, e.id, strlen(e.id) + 1);
memcpy(L->element[i].name, e.name, strlen(e.name) + 1);
memcpy(L->element[i].age, e.age, strlen(e.age) + 1);
*/
L->list_curr_length++;
if (flag_1)
{
printf("成功插入節(jié)點(diǎn)嗤堰,當(dāng)前節(jié)點(diǎn)列表為:\n\n");
DisplaySqList(L);
}
return true;
}
bool SqListDelete(SqList *&L, int i)
{
int j;
if (i < 1 || i > L->list_curr_length)
{
printf("輸入有誤,當(dāng)前順序表長(zhǎng)度為%d度宦,請(qǐng)重新輸入踢匣。\n", L->list_curr_length);
return false;
}
i--;
for (j = i; j < L->list_curr_length - 1; j++)
{
strcpy(L->element[j].age, L->element[j + 1].age);
strcpy(L->element[j].id, L->element[j + 1].id);
strcpy(L->element[j].name, L->element[j + 1].name);
}
L->list_curr_length--;
printf("成功刪除節(jié)點(diǎn),當(dāng)前節(jié)點(diǎn)列表為:\n\n");
DisplaySqList(L);
return true;
}
void SqListInstr(void)
{
printf("\n操作說(shuō)明:\n");
printf("----------------------------\n\n");
printf(" QQ: 退出\n\n");
printf(" TT: 打印操作說(shuō)明\n\n");
printf(" RR: 刪除整個(gè)列表\n\n");
printf(" EE: 判斷列表是否為空\(chéng)n\n");
printf(" LL: 返回列表長(zhǎng)度\n\n");
printf(" SS: 打印完整列表\n\n");
printf(" NN: 重新初始化列表\n\n");
printf("I+數(shù)字: 插入新節(jié)點(diǎn)\n\n");
printf("P+數(shù)字: 打印單個(gè)節(jié)點(diǎn)\n\n");
printf("D+數(shù)字: 刪除單個(gè)節(jié)點(diǎn)\n\n");
printf("----------------------------\n\n");
return;
}
bool SqListGetInsert(SqList *&L)
{
FILE *fp = NULL;
student insert_elem;
char e_oneline[1024], *temp;
if ((fp = fopen("data.txt", "r")) == NULL)
{
printf("error!\n");
return false;
}
int i = 1;
while (!feof(fp) && i < ORIGINA_DATA_NUM + 1)
{
fgets(e_oneline, 1024, fp);
strcpy(insert_elem.id, strtok(e_oneline, ","));
strcpy(insert_elem.name, strtok(NULL, ","));
strcpy(insert_elem.age, strtok(NULL, ","));
/*
memcpy(insert_elem.id, temp, strlen(temp) + 1);
memcpy(insert_elem.name, temp, strlen(temp) + 1);
memcpy(insert_elem.age, temp, strlen(temp) + 1);
*/
SqListInsert(L, i, insert_elem);
i++;
}
fclose(fp);
printf("\n初始化成功戈抄,當(dāng)前節(jié)點(diǎn)列表為:\n\n");
DisplaySqList(L);
flag_1 = true;
return true;
}
int SqListMain(void)
{
student insert_elem;
int input_t;
char input_o;
SqListInstr();
InitSqList(L);
SqListGetInsert(L);
printf("請(qǐng)輸入指令:");
scanf(" %c%d", &input_o, &input_t);
if (input_o == 'I')
{
printf("\n請(qǐng)輸入待插入項(xiàng): ");
scanf("%s %s %s", insert_elem.id, insert_elem.name, insert_elem.age);
// printf("%s, %s, %s, %c, %d\n", insert_elem.id, insert_elem.name, insert_elem.age, input_o, input_t);
}
while (input_o != 'Q')
{
switch (input_o)
{
case 'P':
PrintSqList(L, input_t);
break;
case 'D':
SqListDelete(L, input_t);
break;
case 'I':
SqListInsert(L, input_t, insert_elem);
break;
case 'R':
DestroySqList(L);
break;
case 'E':
SqListEmpty(L);
break;
case 'L':
SqListLength(L);
break;
case 'S':
DisplaySqList(L);
break;
case 'T':
SqListInstr();
break;
case 'N':
InitSqList(L);
flag_1 = false;
SqListGetInsert(L);
flag_1 = true;
break;
default:
printf("指令有誤离唬,請(qǐng)重新輸入。\n");
break;
}
printf("請(qǐng)輸入指令:");
scanf(" %c%d", &input_o, &input_t);
if (input_o == 'I')
{
printf("\n請(qǐng)輸入待插入項(xiàng): ");
scanf("%s %s %s", insert_elem.id, insert_elem.name, insert_elem.age);
// printf("%s, %s, %s, %c, %d\n", insert_elem.id, insert_elem.name, insert_elem.age, input_o, input_t);
}
}
return 0;
}
- Linked List 實(shí)現(xiàn):
#include "head.h"
LinkNode *L;
bool flag_2 = false;
void InitLinList(LinkNode *&L)
{
L = (LinkNode *)malloc(sizeof(LinkNode));
L->data = (student *)malloc(sizeof(student));
L->next = NULL;
}
void DestroyLinList(LinkNode *&L)
{
LinkNode *pre = L, *p = pre->next;
while (p != NULL)
{
free(pre);
pre = p;
p = pre->next;
}
free(pre); //此時(shí)p為NULL,pre指向尾結(jié)點(diǎn),釋放它
}
void EmptyLinList(LinkNode *L)
{
if (!L->next)
printf("\n順序表為空划鸽。\n\n");
else
printf("\n順序表不為空输莺。\n\n");
return;
}
void LinListLength(LinkNode *L)
{
LinkNode *p = L; int i = 0;
while (p->next != NULL)
{
i++;
p = p->next;
}
printf("\n鏈表長(zhǎng)度為:%d\n\n", i);
return;
}
bool LinListDelete(LinkNode *&L, int i)
{
int j = 0;
LinkNode *p = L, *q;
if (i <= 0) return false; //i錯(cuò)誤返回假
while (j < i - 1 && p != NULL) //查找第i-1個(gè)結(jié)點(diǎn)
{
j++;
p = p->next;
}
if (p == NULL) //未找到位序?yàn)閕-1的結(jié)點(diǎn)
return false;
else //找到位序?yàn)閕-1的結(jié)點(diǎn)p
{
q = p->next; //q指向要?jiǎng)h除的結(jié)點(diǎn)
if (q == NULL)
return false; //若不存在第i個(gè)結(jié)點(diǎn),返回false
p->next = q->next; //從單鏈表中刪除q結(jié)點(diǎn)
free(q); //釋放q結(jié)點(diǎn)
}
printf("\n成功刪除節(jié)點(diǎn),當(dāng)前節(jié)點(diǎn)列表為:\n\n");
DisplayLinList(L);
return true;
}
bool LinListGetInsert(LinkNode *&L)
{
FILE *fp = NULL;
student insert_elem;
char e_oneline[1024], *temp;
if ((fp = fopen("data.txt", "r")) == NULL)
{
printf("error!\n");
return false;
}
int i = 1;
while (!feof(fp) && i < ORIGINA_DATA_NUM + 1)
{
fgets(e_oneline, 1024, fp);
strcpy(insert_elem.id, strtok(e_oneline, ","));
strcpy(insert_elem.name, strtok(NULL, ","));
strcpy(insert_elem.age, strtok(NULL, ","));
/*
memcpy(insert_elem.id, temp, strlen(temp) + 1);
memcpy(insert_elem.name, temp, strlen(temp) + 1);
memcpy(insert_elem.age, temp, strlen(temp) + 1);
*/
LinListInsert(L, i, insert_elem);
i++;
}
fclose(fp);
printf("\n初始化成功裸诽,當(dāng)前節(jié)點(diǎn)列表為:\n\n");
DisplayLinList(L);
flag_2 = true;
return true;
}
void DisplayLinList(LinkNode *L)
{
LinkNode *p = L->next;
printf("----------------------------\n\n");
while (p != NULL)
{
printf("%s, %s, %s\n", p->data->id, p->data->name, p->data->age);
p = p->next;
}
printf("----------------------------\n\n");
}
void LinListInstr(void)
{
printf("\n操作說(shuō)明:\n");
printf("----------------------------\n\n");
printf(" QQ: 退出\n\n");
printf(" TT: 打印操作說(shuō)明\n\n");
printf(" RR: 刪除整個(gè)列表\n\n");
printf(" EE: 判斷列表是否為空\(chéng)n\n");
printf(" LL: 返回列表長(zhǎng)度\n\n");
printf(" SS: 打印完整列表\n\n");
printf(" NN: 重新初始化列表\n\n");
printf("I+數(shù)字: 插入新節(jié)點(diǎn)\n\n");
printf("P+數(shù)字: 打印單個(gè)節(jié)點(diǎn)\n\n");
printf("D+數(shù)字: 刪除單個(gè)節(jié)點(diǎn)\n\n");
printf("----------------------------\n\n");
return;
}
bool LinListInsert(LinkNode *&L, int i, student e)
{
int j = 0;
LinkNode *p = L, *s;
if (i <= 0)
return false; //i錯(cuò)誤返回假
while (j < i - 1 && p != NULL) //查找第i-1個(gè)結(jié)點(diǎn)p
{
j++;
p = p->next;
}
if (p == NULL) //未找到位序?yàn)閕-1的結(jié)點(diǎn)
return false;
else //找到位序?yàn)閕-1的結(jié)點(diǎn)*p
{
s = (LinkNode *)malloc(sizeof(LinkNode));//創(chuàng)建新結(jié)點(diǎn)*s
s->data = (student *)malloc(sizeof(student));
strcpy(s->data->id, e.id);
strcpy(s->data->name, e.name);
strcpy(s->data->age, strcat(e.age, "\n"));
s->next = p->next; //將s結(jié)點(diǎn)插入到結(jié)點(diǎn)p之后
p->next = s;
return true;
}
if (flag_2)
{
printf("成功插入節(jié)點(diǎn)嫂用,當(dāng)前節(jié)點(diǎn)列表為:\n\n");
DisplayLinList(L);
}
}
bool PrintLinList(LinkNode *L, int i)
{
int j = 0;
LinkNode *p = L->next;
if (i <= 0)
return false; //i錯(cuò)誤返回假
while (j < i - 1 && p != NULL) //查找第i-1個(gè)結(jié)點(diǎn)p
{
j++;
p = p->next;
}
if (p == NULL) //未找到位序?yàn)閕-1的結(jié)點(diǎn)
return false;
else //找到位序?yàn)閕-1的結(jié)點(diǎn)*p
{
printf("\n%s, %s, %s\n", p->data->id, p->data->name, p->data->age);
return true;
}
}
int LinkedListMain(void)
{
student insert_elem;
int input_t;
char input_o;
LinListInstr();
InitLinList(L);
LinListGetInsert(L);
printf("\n請(qǐng)輸入指令:");
scanf(" %c%d", &input_o, &input_t);
if (input_o == 'I')
{
printf("\n請(qǐng)輸入待插入項(xiàng): ");
scanf("%s %s %s", insert_elem.id, insert_elem.name, insert_elem.age);
// printf("%s, %s, %s, %c, %d\n", insert_elem.id, insert_elem.name, insert_elem.age, input_o, input_t);
}
while (input_o != 'Q')
{
switch (input_o)
{
case 'P':
PrintLinList(L, input_t);
break;
case 'D':
LinListDelete(L, input_t);
break;
case 'I':
LinListInsert(L, input_t, insert_elem);
break;
case 'R':
DestroyLinList(L);
break;
case 'E':
EmptyLinList(L);
break;
case 'L':
LinListLength(L);
break;
case 'S':
DisplayLinList(L);
break;
case 'T':
LinListInstr();
break;
case 'N':
InitLinList(L);
flag_2 = false;
LinListGetInsert(L);
flag_2 = true;
break;
default:
printf("指令有誤,請(qǐng)重新輸入丈冬。\n");
break;
}
printf("\n請(qǐng)輸入指令:");
scanf(" %c%d", &input_o, &input_t);
if (input_o == 'I')
{
printf("\n請(qǐng)輸入待插入項(xiàng): ");
scanf("%s %s %s", insert_elem.id, insert_elem.name, insert_elem.age);
// printf("%s, %s, %s, %c, %d\n", insert_elem.id, insert_elem.name, insert_elem.age, input_o, input_t);
}
}
return 0;
}
- main() 函數(shù):
#include "head.h"
void main(void)
{
char choice;
printf("請(qǐng)選擇存儲(chǔ)模式(S/L/Q):");
scanf("%c", &choice);
while (choice != 'Q')
{
switch (choice)
{
case 'S':
SqListMain();
break;
case 'L':
LinkedListMain();
break;
default:
printf("輸入有誤嘱函,請(qǐng)重新輸入: \n");
break;
}
printf("請(qǐng)選擇存儲(chǔ)模式(S/L/Q):");
scanf("%c", &choice);
}
return;
}
data.txt 文件:
10225048,張三,24
10225132,李四,22
10225027,王五,24
10225213,趙六,25
10225197,歐陽(yáng)奮強(qiáng),23
10225059,孫八,24
10225083,余久,23
10225112,張唯一,24
總結(jié):
-
fscanf()函數(shù)的使用
原型:int fscanf(FILE*stream,constchar*format,[argument...]);
頭文件:<stdio.h>
功能:從一個(gè)流中執(zhí)行格式化輸入,fscanf遇到空格和換行時(shí)結(jié)束埂蕊。這與fgets有區(qū)別往弓,fgets遇到空格不結(jié)束橄浓。#include <stdio.h> #include <stdlib.h> int main() { char str1[10], str2[10], str3[10]; int year; FILE * fp; fp = fopen ("file.txt", "w+"); fputs("We are in 2014", fp); rewind(fp); fscanf(fp, "%s %s %s %d", str1, str2, str3, &year); printf("Read String1 |%s|\n", str1 ); printf("Read String2 |%s|\n", str2 ); printf("Read String3 |%s|\n", str3 ); printf("Read Integer |%d|\n", year ); fclose(fp); return(0); }
-
fgets()函數(shù)的使用
原型:char *fgets(char *buf, int bufsize, FILE *stream);
頭文件:<string.h>
功能:從文件流讀取一行,送到緩沖區(qū)亮航。
fgets(e_oneline, 1024, fp);
-
strcpy()函數(shù)的使用
原型:char *strcpy(char* dest, const char *src);
頭文件:<string.h> <stdio.h>
功能:把從src地址開始且含有NULL結(jié)束符的字符串復(fù)制到以dest開始的地址空間。strcpy(insert_elem.id, strtok(e_oneline, ",")); strcpy(insert_elem.name, strtok(NULL, ",")); strcpy(insert_elem.age, strtok(NULL, ","));
-
strtok()函數(shù)的使用
原型:char *strtok(char s[], const char *delim);
頭文件:<string.h>
功能:分解字符串為一組字符串匀们。s為要分解的字符串缴淋,delim為分隔符字符串。strcpy(insert_elem.id, strtok(e_oneline, ",")); strcpy(insert_elem.name, strtok(NULL, ",")); strcpy(insert_elem.age, strtok(NULL, ","));
-
memcpy()函數(shù)的使用
原型:void *memcpy(void *dest, const void *src, size_t n);
頭文件:c:<string.h>; c++:<cstring>
功能:從源src所指的內(nèi)存地址的起始位置開始拷貝n個(gè)字節(jié)到目標(biāo)dest所指的內(nèi)存地址的起始位置中泄朴。memcpy(insert_elem.id, temp, strlen(temp) + 1); memcpy(insert_elem.name, temp, strlen(temp) + 1); memcpy(insert_elem.age, temp, strlen(temp) + 1);
-
strcat()函數(shù)的使用
原型:extern char *strcat(char *dest, const char *src);
頭文件:c: <string.h>重抖;c++: <cstring>
功能:把src所指向的字符串(包括“\0”)復(fù)制到dest所指向的字符串后面(刪除dest原來(lái)末尾的“\0”)。要保證dest足夠長(zhǎng)祖灰,以容納被復(fù)制進(jìn)來(lái)的src钟沛,src中原有的字符不變,返回指向dest的指針局扶。
strcpy(L->element[i].age, strcat(e.age, "\n"));
-
feof()函數(shù)和文件的使用
原型:int feof(FILE *stream);
頭文件:<stdio.h>
功能:檢測(cè)流上的文件結(jié)束符恨统, 如果文件結(jié)束,則返回非0值三妈,否則返回0值畜埋,文件結(jié)束符只能被clearerr()清除。bool SqListGetInsert(SqList *&L) { FILE *fp = NULL; student insert_elem; char e_oneline[1024], *temp; if ((fp = fopen("data.txt", "r")) == NULL) { printf("error!\n"); return false; } int i = 1; while (!feof(fp) && i < ORIGINA_DATA_NUM + 1) { fgets(e_oneline, 1024, fp); strcpy(insert_elem.id, strtok(e_oneline, ",")); strcpy(insert_elem.name, strtok(NULL, ",")); strcpy(insert_elem.age, strtok(NULL, ",")); /* memcpy(insert_elem.id, temp, strlen(temp) + 1); memcpy(insert_elem.name, temp, strlen(temp) + 1); memcpy(insert_elem.age, temp, strlen(temp) + 1); */ SqListInsert(L, i, insert_elem); i++; } fclose(fp); printf("\n初始化成功畴蒲,當(dāng)前節(jié)點(diǎn)列表為:\n\n"); DisplaySqList(L); flag_1 = true; return true; }
-
實(shí)驗(yàn)過(guò)程中出現(xiàn)的錯(cuò)誤
將 strcpy(L->element[i].id, e.id); 寫為 L->element[i].id = e.id;
錯(cuò)誤原因:L->element[i].id 為一個(gè)已經(jīng)定義好的數(shù)組悠鞍,無(wú)法再為其重新定義,只可以為其賦值模燥。L->element[i].id = e.id; L->element[i].name = e.name; L->element[i].age =e.age;
正確代碼如下:
沒有為結(jié)構(gòu)體內(nèi)部的結(jié)構(gòu)體型變量分配空間:strcpy(L->element[i].id, e.id); strcpy(L->element[i].name, e.name); strcpy(L->element[i].age, strcat(e.age, "\n"));
錯(cuò)誤原因:L->data時(shí)student型的結(jié)構(gòu)體變量咖祭,雖然結(jié)構(gòu)體student在定義時(shí)已經(jīng)為id, name, age分配了空間,但是L->data仍然沒有分配空間蔫骂,需要為其重新分配么翰。void InitLinList(LinkNode *&L) { L = (LinkNode *)malloc(sizeof(LinkNode)); L->next = NULL; }
正確代碼如下:void InitLinList(LinkNode *&L) { L = (LinkNode *)malloc(sizeof(LinkNode)); L->data = (student *)malloc(sizeof(student)); L->next = NULL; }