LIST.CPP
资源名称:C++100.rar [点击查看]
上传用户:wszmarenbt
上传日期:2013-04-26
资源大小:2552k
文件大小:1k
源码类别:
Windows编程
开发平台:
Visual C++
- //THE IMPLEMENTATION OF THE CLASS "LIST"
- //FILE LIST.CPP
- #include "List.h"
- NODE* LIST::GET_HEAD()
- {
- return (HEAD);
- }
- void LIST::DISPLAY(NODE *TEMP)
- {
- if (HEAD==0)
- {
- printf("----Sorry!!! It's EMPTY !!! ");
- }
- else
- {
- while(TEMP!=0)
- {
- printf("%d ",TEMP->DATA);
- TEMP=TEMP->NEXT;
- }
- }
- }
- void LIST::INSERT(int Data)
- {
- NODE *TEMP=HEAD;
- NODE *PREVIOUS;
- NODE *NEWNODE;
- NEWNODE=new NODE;
- NEWNODE->DATA=Data;
- NEWNODE->NEXT=0;
- if(HEAD==0)
- {
- HEAD=NEWNODE;
- }
- else
- {
- while(((TEMP->DATA)<=Data)&&(TEMP!=0))
- {
- PREVIOUS=TEMP;
- TEMP=TEMP->NEXT;
- }
- if(TEMP==HEAD)
- {
- NEWNODE->NEXT=HEAD;
- HEAD=NEWNODE;
- }
- else
- {
- NEWNODE->NEXT=TEMP;
- PREVIOUS->NEXT=NEWNODE;
- }
- }
- }
- void LIST::CLEAR()
- {
- NODE *TEMP_HEAD=HEAD;
- if (TEMP_HEAD==0) return;
- do
- {
- NODE *TEMP_NODE=TEMP_HEAD;
- TEMP_HEAD=TEMP_HEAD->NEXT;
- delete TEMP_NODE;
- }
- while (TEMP_HEAD!=0);
- }