데이터 구조 기초 편 --- - 2. 단일 체인 표 의 생 성 및 연산

3746 단어
/*
 *           
 * 2018.10.23
 * @L.F
 *
 * */

#include
#include
#include
typedef int DataType_t;//        DataType_t,   Int 

typedef struct Node    //       
{
	DataType_t Data;   //        
	struct Node *Next; //        
}LinkList;

LinkList *LinkListCreate() //        
{
	LinkList *h = (LinkList *)malloc(sizeof(LinkList)); //       
	h->Next = NULL; //      
	return h;
}

void LinkListInsertHead(LinkList *h, DataType_t Value)//       
{
	LinkList *Temp = (LinkList *)malloc(sizeof(LinkList));//       
	Temp->Data = Value;
	Temp->Next = h->Next;//                           
	h->Next = Temp;//                      
	return ;
}

void LinkListInsertTail(LinkList *h, DataType_t Value)//       
{
	LinkList *Temp = (LinkList *)malloc(sizeof(LinkList));//       
	Temp->Data = Value;
	while(h->Next != NULL)//        
	{
		h = h->Next;
	}
	Temp->Next = NULL;
	h->Next = Temp;
	return ;
}

void LinkListInsertPos(LinkList *h, int pos, DataType_t Value)//        
{
	LinkList *Temp = (LinkList *)malloc(sizeof(LinkList));
	Temp->Data = Value;
	int i =1;
	while(h->Next != NULL && i<= pos)
	{
		h = h->Next;
		i++;
	}
	if(h->Next == NULL)
	{
		printf("    
"); } else { Temp->Next = h->Next; h->Next = Temp; } return ; } void LinkListInsertSort(LinkList *h, DataType_t Value)// ( ) { LinkList *Temp = (LinkList *)malloc(sizeof(LinkList)); Temp->Data = Value; while(h->Next != NULL && h->Next->Data < Temp->Data) { h = h->Next; } Temp->Next = h->Next; h->Next = Temp; return ; } DataType_t LinkListDeleteHead(LinkList *h)// { /*h->Next = h->Next->Next;// */ /* * DataType_t Value; * Value = h->Next->Data; * h->Next = h->Next->Next; * */ /* */ DataType_t Value; LinkList *Temp = h->Next; Value = h->Next->Data; h->Next = h->Next->Next; free(Temp); Temp = NULL; return Value; } int LinkListUpdata(LinkList *h, DataType_t OldValue, DataType_t NewValue)// { while(h->Next != NULL) { if(h->Next->Data == OldValue) { h->Next->Data = NewValue; return 0; } h = h->Next; } printf("%d ", NewValue); return -1; } int LinkListSearch(LinkList *h,DataType_t Value)// { int pos = 0; while(h->Next != NULL) { if(h->Next->Data == Value) { return pos; } h = h->Next; pos++; } printf("%d
", Value); return -1; } void LinkListReverse(LinkList *h)// { LinkList *p = h->Next; LinkList *q; h->Next = NULL; while(p != NULL) { q = p; p = p->Next; q->Next = h->Next; h->Next = q; } return ; } void LinkListShow(LinkList *h)// { while(h->Next != NULL) { h = h->Next; printf(" %d", h->Data); } putchar(10); } int main(int argc, const char *argv[]) { LinkList *h = LinkListCreate(); int F,s,i,a,n; while(1) { printf(" : 1. 2. 3.
"); printf(" 4. 5. 6.
"); printf(" 7. 8.
"); scanf("%d", &F); switch(F) { case 1: printf(" :"); scanf("%d",&s); for(i=0; i

좋은 웹페이지 즐겨찾기