多重链表实现课程注册

//List.c
#include "List.h"
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>


void CreateEmptyList(List *L)
{
	*L=(Position)malloc(sizeof(struct Node));      //清空链表(只留头节点) 
	(*L)->Next_course=NULL;
	(*L)->Next_name=NULL;
	(*L)->Name_next=NULL;
	(*L)->Name_num=NULL;
}

Position Find_same_course(ElementType *X,List L) //在链表中寻找课程相同课程名的节点 
{
	Position P;
	P=L;                                     //寻找某个元素在链表中的地址 
	while(P->Next_course!=L)                  //若找到,返回元素所在的节点指针,否则返回空指针 
	{
		P=P->Next_course;
		if(!strcmp(X,P->Course))
		{
			return P;
		}                                     //没问题 
	}
	if(!strcmp(X,L->Course))
	{
		return L;
	}
	return P=NULL;
}

Position Find_same_name(ElementType *X,List L) //在链表中寻找课程相同学生名字的节点 
{
	Position P;
	P=L;                                     //寻找某个元素在链表中的地址 
	while(P->Next_name!=L)                  //若找到,返回元素所在的节点指针,否则返回空指针 
	{
		P=P->Next_name;
		if(!strcmp(X,P->Name))
		{
			return P;
		}                                     //没问题 
	}
	if(!strcmp(X,L->Name))
	{
		return L;
	}
	return P=NULL;
}

Position Find_same_name_num(ElementType *X,List L) //在链表中寻找课程相同学生名字的节点 
{
	Position P;
	P=L;                                     //寻找某个元素在链表中的地址 
	while(P->Name_num!=L)                  //若找到,返回元素所在的节点指针,否则返回空指针 
	{
		P=P->Name_num;
		if(!strcmp(X,P->Name))
		{
			return P;
		}                                     //没问题 
	}
	if(!strcmp(X,L->Name))
	{
		return L;
	}
	return P=NULL;
}

void InsertH_course(List L,Position Jiedian)
{
	if(L==NULL)
	{
		return;
	} 
	List p;                                              //后插,直接插入节点 
	p=L->Next_course;
	L->Next_course=Jiedian;
	Jiedian->Next_course=p;
}

void InsertH_name_num(List L,Position Jiedian)
{
	if(L==NULL)
	{
		return;
	} 
	List p;                                              //后插,直接插入节点 
	p=L->Name_num;
	L->Name_num=Jiedian;
	Jiedian->Name_num=p;
}

void InsertH_name(List L,Position Jiedian)
{
	if(L==NULL)
	{
		return;
	} 
	List p;                                              //后插,直接插入节点 
	p=L->Next_name;
	L->Next_name=Jiedian;
	Jiedian->Next_name=p;
}

void InsertH_name_next(List L,Position Jiedian)
{
	if(L==NULL)
	{
		return;
	} 
	List p;                                              //后插,直接插入节点 
	p=L->Name_next;
	L->Name_next=Jiedian;
	Jiedian->Name_next=p;
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//List.h 
#ifndef _LIST_H_
typedef char ElementType;
#define LEN 15 

struct Node;

typedef struct Node *PtrToNode;       
typedef PtrToNode List;
typedef PtrToNode Position;

struct Node
{
	ElementType Course[LEN];                     
	ElementType Name[LEN];
	Position Next_course;
	Position Next_name;
	Position Name_next;
	Position Name_num;
	
};

void CreateEmptyList(List *L); 
Position Find_same_course(ElementType *X,List L);
Position Find_same_name(ElementType *X,List L);
Position Find_same_name_num(ElementType *X,List L);
void InsertH_course(List L,Position Jiedian);
void InsertH_name_num(List L,Position Jiedian);
void InsertH_name(List L,Position Jiedian);
void InsertH_name_next(List L,Position Jiedian);

#endif
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//main.c 
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<malloc.h>
#include "List.h"

int main(void)
{
	List School;
	CreateEmptyList(&School);                 //生成了一个头节点,可用于之后的查找 
	printf("\nV1.0 By zhouxing-HIT-qq960020310%%%%%%%%%%%%%\n");
	printf("\n%%%%%%%%%%%%%课程选课信息注册系统%%%%%%%%%%%%%\n");
	
	int i;
	
	while(1)
	{
		printf("\n*************请按照提示进行操作************\n");
		printf("--1------进行选课情况导入!\n");
		printf("--2------课程选课名单输出!\n");
		printf("--3------学生所选课目录!\n");
		printf("--4------退出课程管理系统!\n");
		scanf("%d",&i);
		switch(i)
		{
			case 1:
				{
					char p_course[LEN];
					char q_name[LEN];

					printf("**********请输入:课程名+学生名(空格隔开)************\n");
					scanf("%s",p_course);
					scanf("%s",q_name);
					
					if(!((!strcmp(p_course,"quit"))||(!strcmp(q_name,"quit")))) 
						{
							strcpy(School->Course,p_course);
			    			strcpy(School->Name,q_name);
			    			School->Next_course=School;
			    			School->Next_name=School;
			    			School->Name_next=School;
			    			School->Name_num=School;
						}
					else
						{
							printf("----------感谢使用,再见!-----------"); 
							return;
						}
	
					printf("**********请输入课程名+学生名(空格隔开)************\n");
					scanf("%s",p_course);
					scanf("%s",q_name); 
			
					while(!((!strcmp(p_course,"quit"))||(!strcmp(q_name,"quit"))))
						{				
						
							Position TmpCell;
	            			TmpCell=malloc(sizeof(struct Node));
	            		
	           				strcpy(TmpCell->Course,p_course);
	           			
	           				strcpy(TmpCell->Name,q_name);
	         			    TmpCell->Next_course=TmpCell;       //生成一个结构体的所有指针成员都指向自己的节点 
	            			TmpCell->Next_name=TmpCell;
	            			TmpCell->Name_next=TmpCell;
	           				TmpCell->Name_num=TmpCell;
	            			Position g,h,w,y;
	            			g=Find_same_course(p_course,School);
	           			 	h=Find_same_name_num(q_name,School);
	            
	            			if(g!=NULL)
	            				{
									w=Find_same_name(q_name,g);
	            					if(w==NULL)
	            						{
											if(h==NULL)
	            								{
	            									InsertH_name(g,TmpCell);
	            									InsertH_name_num(School,TmpCell);
	            								}
	            							else
	            								{
	            									InsertH_name(g,TmpCell);
	            									InsertH_name_next(h,TmpCell);
	            								}
	            						}
	            					else
									{
										printf("\n************输入重复啦!\n");
									} 
								
	            				}
	            			if(g==NULL)
	            				{
	            					if(h==NULL)
	            					{
	            						InsertH_course(School,TmpCell);
	            						InsertH_name_num(School,TmpCell);
	            					}
	            					else
	            					{
	            						InsertH_course(School,TmpCell);
	            						InsertH_name_next(h,TmpCell);
	            					}
	            				}
	            				
	            			printf("**********请输入课程名+学生名(空格隔开)************\n");
							scanf("%s",p_course);
							scanf("%s",q_name); 
							if((!strcmp(p_course,"quit"))||(!strcmp(q_name,"quit")))
									{
										break;
									}
						}
				break;
				}		
			
		case 2:
			{
				printf("请输入您要查询的课程的名字:\n");
				char s[LEN];
				scanf("%s",s);
				List y,y_1,y_2;
				y=School;
				y_1=NULL;
				while(strcmp(s,"quit"))
				{
			    	while(y->Next_course!=School)
			        	{
			        		y=y->Next_course;
			        		if(!strcmp(y->Course,s))
				          		{  
					         		y_1=y;
			              		}
			        	} 
			    	if(!strcmp(School->Course,s))
						{
							y_1=School;
						}
					if(y_1==NULL)
						{
							printf("课程名输入错误,请重新输入:\n");
						}
					else
						{
							y_2=y_1;
							while(y_2->Next_name!=y_1)
								{
									y_2=y_2->Next_name;
									printf("%s\n",y_2->Name);
								}
							printf("%s\n",y_1->Name);
						}
				break;
				}
			break;
			
			}
			
		case 3:
			{
				printf("请输入您要查询的学生的名字:\n");
				char s[LEN];
				scanf("%s",s);
				List y_3,y_1_1,y_2_1;
				y_1_1=NULL; 
				y_3=School;
				while(strcmp(s,"quit"))
					{
			   			while(y_3->Name_num!=School)
			        		{
			        			y_3=y_3->Name_num;
			        			if(!strcmp(y_3->Name,s))
				           			{  
					         			y_1_1=y_3;
			               			}
			        		} 
			    		if(!strcmp(School->Name,s))
							{
								y_1_1=School;
							}
						if(y_1_1==NULL)
							{
								printf("课程名输入错误,请重新输入:\n");
							}
						else
							{
								y_2_1=y_1_1;
								while(y_2_1->Name_next!=y_1_1)
								{
									y_2_1=y_2_1->Name_next;
									printf("%s\n",y_2_1->Course);
								}
								printf("%s\n",y_1_1->Course);
							}
				break;
				}
			break;
			}

		case 4:
			{
				printf("谢谢使用,再见!\n");
				return;
			}
		}
	}

}

//List.h 
#ifndef _LIST_H_
typedef char ElementType;
#define LEN 15 

struct Node;

typedef struct Node *PtrToNode;       
typedef PtrToNode List;
typedef PtrToNode Position;

struct Node
{
    ElementType Course[LEN];                     
    ElementType Name[LEN];
    Position Next_course;
    Position Next_name;
    Position Name_next;
    Position Name_num;
    
};

void CreateEmptyList(List *L); 
Position Find_same_course(ElementType *X,List L);
Position Find_same_name(ElementType *X,List L);
Position Find_same_name_num(ElementType *X,List L);
void InsertH_course(List L,Position Jiedian);
void InsertH_name_num(List L,Position Jiedian);
void InsertH_name(List L,Position Jiedian);
void InsertH_name_next(List L,Position Jiedian);

#endif
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

//List.c
#include "List.h"
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>


void CreateEmptyList(List *L)
{
    *L=(Position)malloc(sizeof(struct Node));      //清空链表(只留头节点) 
    (*L)->Next_course=NULL;
    (*L)->Next_name=NULL;
    (*L)->Name_next=NULL;
    (*L)->Name_num=NULL;
}

Position Find_same_course(ElementType *X,List L) //在链表中寻找课程相同课程名的节点 
{
    Position P;
    P=L;                                     //寻找某个元素在链表中的地址 
    while(P->Next_course!=L)                  //若找到,返回元素所在的节点指针,否则返回空指针 
    {
        P=P->Next_course;
        if(!strcmp(X,P->Course))
        {
            return P;
        }                                     //没问题 
    }
    if(!strcmp(X,L->Course))
    {
        return L;
    }
    return P=NULL;
}

Position Find_same_name(ElementType *X,List L) //在链表中寻找课程相同学生名字的节点 
{
    Position P;
    P=L;                                     //寻找某个元素在链表中的地址 
    while(P->Next_name!=L)                  //若找到,返回元素所在的节点指针,否则返回空指针 
    {
        P=P->Next_name;
        if(!strcmp(X,P->Name))
        {
            return P;
        }                                     //没问题 
    }
    if(!strcmp(X,L->Name))
    {
        return L;
    }
    return P=NULL;
}

Position Find_same_name_num(ElementType *X,List L) //在链表中寻找课程相同学生名字的节点 
{
    Position P;
    P=L;                                     //寻找某个元素在链表中的地址 
    while(P->Name_num!=L)                  //若找到,返回元素所在的节点指针,否则返回空指针 
    {
        P=P->Name_num;
        if(!strcmp(X,P->Name))
        {
            return P;
        }                                     //没问题 
    }
    if(!strcmp(X,L->Name))
    {
        return L;
    }
    return P=NULL;
}

void InsertH_course(List L,Position Jiedian)
{
    if(L==NULL)
    {
        return;
    } 
    List p;                                              //后插,直接插入节点 
    p=L->Next_course;
    L->Next_course=Jiedian;
    Jiedian->Next_course=p;
}

void InsertH_name_num(List L,Position Jiedian)
{
    if(L==NULL)
    {
        return;
    } 
    List p;                                              //后插,直接插入节点 
    p=L->Name_num;
    L->Name_num=Jiedian;
    Jiedian->Name_num=p;
}

void InsertH_name(List L,Position Jiedian)
{
    if(L==NULL)
    {
        return;
    } 
    List p;                                              //后插,直接插入节点 
    p=L->Next_name;
    L->Next_name=Jiedian;
    Jiedian->Next_name=p;
}

void InsertH_name_next(List L,Position Jiedian)
{
    if(L==NULL)
    {
        return;
    } 
    List p;                                              //后插,直接插入节点 
    p=L->Name_next;
    L->Name_next=Jiedian;
    Jiedian->Name_next=p;
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

//main.c 
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<malloc.h>
#include "List.h"

int main(void)
{
    List School;
    CreateEmptyList(&School);                 //生成了一个头节点,可用于之后的查找 
    printf("\nV1.0 By zhouxing-HIT-qq960020310%%%%%%%%%%%%%\n");
    printf("\n%%%%%%%%%%%%%课程选课信息注册系统%%%%%%%%%%%%%\n");
    
    int i;
    
    while(1)
    {
        printf("\n*************请按照提示进行操作************\n");
        printf("--1------进行选课情况导入!\n");
        printf("--2------课程选课名单输出!\n");
        printf("--3------学生所选课目录!\n");
        printf("--4------退出课程管理系统!\n");
        scanf("%d",&i);
        switch(i)
        {
            case 1:
                {
                    char p_course[LEN];
                    char q_name[LEN];

                    printf("**********请输入:课程名+学生名(空格隔开)************\n");
                    scanf("%s",p_course);
                    scanf("%s",q_name);
                    
                    if(!((!strcmp(p_course,"quit"))||(!strcmp(q_name,"quit")))) 
                        {
                            strcpy(School->Course,p_course);
                            strcpy(School->Name,q_name);
                            School->Next_course=School;
                            School->Next_name=School;
                            School->Name_next=School;
                            School->Name_num=School;
                        }
                    else
                        {
                            printf("----------感谢使用,再见!-----------"); 
                            return;
                        }
    
                    printf("**********请输入课程名+学生名(空格隔开)************\n");
                    scanf("%s",p_course);
                    scanf("%s",q_name); 
            
                    while(!((!strcmp(p_course,"quit"))||(!strcmp(q_name,"quit"))))
                        {                
                        
                            Position TmpCell;
                            TmpCell=malloc(sizeof(struct Node));
                        
                               strcpy(TmpCell->Course,p_course);
                           
                               strcpy(TmpCell->Name,q_name);
                             TmpCell->Next_course=TmpCell;       //生成一个结构体的所有指针成员都指向自己的节点 
                            TmpCell->Next_name=TmpCell;
                            TmpCell->Name_next=TmpCell;
                               TmpCell->Name_num=TmpCell;
                            Position g,h,w,y;
                            g=Find_same_course(p_course,School);
                                h=Find_same_name_num(q_name,School);
                
                            if(g!=NULL)
                                {
                                    w=Find_same_name(q_name,g);
                                    if(w==NULL)
                                        {
                                            if(h==NULL)
                                                {
                                                    InsertH_name(g,TmpCell);
                                                    InsertH_name_num(School,TmpCell);
                                                }
                                            else
                                                {
                                                    InsertH_name(g,TmpCell);
                                                    InsertH_name_next(h,TmpCell);
                                                }
                                        }
                                    else
                                    {
                                        printf("\n************输入重复啦!\n");
                                    } 
                                
                                }
                            if(g==NULL)
                                {
                                    if(h==NULL)
                                    {
                                        InsertH_course(School,TmpCell);
                                        InsertH_name_num(School,TmpCell);
                                    }
                                    else
                                    {
                                        InsertH_course(School,TmpCell);
                                        InsertH_name_next(h,TmpCell);
                                    }
                                }
                                
                            printf("**********请输入课程名+学生名(空格隔开)************\n");
                            scanf("%s",p_course);
                            scanf("%s",q_name); 
                            if((!strcmp(p_course,"quit"))||(!strcmp(q_name,"quit")))
                                    {
                                        break;
                                    }
                        }
                break;
                }        
            
        case 2:
            {
                printf("请输入您要查询的课程的名字:\n");
                char s[LEN];
                scanf("%s",s);
                List y,y_1,y_2;
                y=School;
                y_1=NULL;
                while(strcmp(s,"quit"))
                {
                    while(y->Next_course!=School)
                        {
                            y=y->Next_course;
                            if(!strcmp(y->Course,s))
                                  {  
                                     y_1=y;
                                  }
                        } 
                    if(!strcmp(School->Course,s))
                        {
                            y_1=School;
                        }
                    if(y_1==NULL)
                        {
                            printf("课程名输入错误,请重新输入:\n");
                        }
                    else
                        {
                            y_2=y_1;
                            while(y_2->Next_name!=y_1)
                                {
                                    y_2=y_2->Next_name;
                                    printf("%s\n",y_2->Name);
                                }
                            printf("%s\n",y_1->Name);
                        }
                break;
                }
            break;
            
            }
            
        case 3:
            {
                printf("请输入您要查询的学生的名字:\n");
                char s[LEN];
                scanf("%s",s);
                List y_3,y_1_1,y_2_1;
                y_1_1=NULL; 
                y_3=School;
                while(strcmp(s,"quit"))
                    {
                           while(y_3->Name_num!=School)
                            {
                                y_3=y_3->Name_num;
                                if(!strcmp(y_3->Name,s))
                                       {  
                                         y_1_1=y_3;
                                       }
                            } 
                        if(!strcmp(School->Name,s))
                            {
                                y_1_1=School;
                            }
                        if(y_1_1==NULL)
                            {
                                printf("课程名输入错误,请重新输入:\n");
                            }
                        else
                            {
                                y_2_1=y_1_1;
                                while(y_2_1->Name_next!=y_1_1)
                                {
                                    y_2_1=y_2_1->Name_next;
                                    printf("%s\n",y_2_1->Course);
                                }
                                printf("%s\n",y_1_1->Course);
                            }
                break;
                }
            break;
            }

        case 4:
            {
                printf("谢谢使用,再见!\n");
                return;
            }
        }
    }

}

//main.c 
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<malloc.h>
#include "List.h"

int main(void)
{
	List School;
	CreateEmptyList(&School);                 //生成了一个头节点,可用于之后的查找 
	printf("\nV1.0 By zhouxing-HIT-qq960020310%%%%%%%%%%%%%\n");
	printf("\n%%%%%%%%%%%%%课程选课信息注册系统%%%%%%%%%%%%%\n");
	
	int i;
	
	while(1)
	{
		printf("\n*************请按照提示进行操作************\n");
		printf("--1------进行选课情况导入!\n");
		printf("--2------课程选课名单输出!\n");
		printf("--3------学生所选课目录!\n");
		printf("--4------退出课程管理系统!\n");
		scanf("%d",&i);
		switch(i)
		{
			case 1:
				{
					char p_course[LEN];
					char q_name[LEN];

					printf("**********请输入:课程名+学生名(空格隔开)************\n");
					scanf("%s",p_course);
					scanf("%s",q_name);
					
					if(!((!strcmp(p_course,"quit"))||(!strcmp(q_name,"quit")))) 
						{
							strcpy(School->Course,p_course);
			    			strcpy(School->Name,q_name);
			    			School->Next_course=School;
			    			School->Next_name=School;
			    			School->Name_next=School;
			    			School->Name_num=School;
						}
					else
						{
							printf("----------感谢使用,再见!-----------"); 
							return;
						}
	
					printf("**********请输入课程名+学生名(空格隔开)************\n");
					scanf("%s",p_course);
					scanf("%s",q_name); 
			
					while(!((!strcmp(p_course,"quit"))||(!strcmp(q_name,"quit"))))
						{				
						
							Position TmpCell;
	            			TmpCell=malloc(sizeof(struct Node));
	            		
	           				strcpy(TmpCell->Course,p_course);
	           			
	           				strcpy(TmpCell->Name,q_name);
	         			    TmpCell->Next_course=TmpCell;       //生成一个结构体的所有指针成员都指向自己的节点 
	            			TmpCell->Next_name=TmpCell;
	            			TmpCell->Name_next=TmpCell;
	           				TmpCell->Name_num=TmpCell;
	            			Position g,h,w,y;
	            			g=Find_same_course(p_course,School);
	           			 	h=Find_same_name_num(q_name,School);
	            
	            			if(g!=NULL)
	            				{
									w=Find_same_name(q_name,g);
	            					if(w==NULL)
	            						{
											if(h==NULL)
	            								{
	            									InsertH_name(g,TmpCell);
	            									InsertH_name_num(School,TmpCell);
	            								}
	            							else
	            								{
	            									InsertH_name(g,TmpCell);
	            									InsertH_name_next(h,TmpCell);
	            								}
	            						}
	            					else
									{
										printf("\n************输入重复啦!\n");
									} 
								
	            				}
	            			if(g==NULL)
	            				{
	            					if(h==NULL)
	            					{
	            						InsertH_course(School,TmpCell);
	            						InsertH_name_num(School,TmpCell);
	            					}
	            					else
	            					{
	            						InsertH_course(School,TmpCell);
	            						InsertH_name_next(h,TmpCell);
	            					}
	            				}
	            				
	            			printf("**********请输入课程名+学生名(空格隔开)************\n");
							scanf("%s",p_course);
							scanf("%s",q_name); 
							if((!strcmp(p_course,"quit"))||(!strcmp(q_name,"quit")))
									{
										break;
									}
						}
				break;
				}		
			
		case 2:
			{
				printf("请输入您要查询的课程的名字:\n");
				char s[LEN];
				scanf("%s",s);
				List y,y_1,y_2;
				y=School;
				y_1=NULL;
				while(strcmp(s,"quit"))
				{
			    	while(y->Next_course!=School)
			        	{
			        		y=y->Next_course;
			        		if(!strcmp(y->Course,s))
				          		{  
					         		y_1=y;
			              		}
			        	} 
			    	if(!strcmp(School->Course,s))
						{
							y_1=School;
						}
					if(y_1==NULL)
						{
							printf("课程名输入错误,请重新输入:\n");
						}
					else
						{
							y_2=y_1;
							while(y_2->Next_name!=y_1)
								{
									y_2=y_2->Next_name;
									printf("%s\n",y_2->Name);
								}
							printf("%s\n",y_1->Name);
						}
				break;
				}
			break;
			
			}
			
		case 3:
			{
				printf("请输入您要查询的学生的名字:\n");
				char s[LEN];
				scanf("%s",s);
				List y_3,y_1_1,y_2_1;
				y_1_1=NULL; 
				y_3=School;
				while(strcmp(s,"quit"))
					{
			   			while(y_3->Name_num!=School)
			        		{
			        			y_3=y_3->Name_num;
			        			if(!strcmp(y_3->Name,s))
				           			{  
					         			y_1_1=y_3;
			               			}
			        		} 
			    		if(!strcmp(School->Name,s))
							{
								y_1_1=School;
							}
						if(y_1_1==NULL)
							{
								printf("课程名输入错误,请重新输入:\n");
							}
						else
							{
								y_2_1=y_1_1;
								while(y_2_1->Name_next!=y_1_1)
								{
									y_2_1=y_2_1->Name_next;
									printf("%s\n",y_2_1->Course);
								}
								printf("%s\n",y_1_1->Course);
							}
				break;
				}
			break;
			}

		case 4:
			{
				printf("谢谢使用,再见!\n");
				return;
			}
		}
	}

}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//List.h 
#ifndef _LIST_H_
typedef char ElementType;
#define LEN 15 

struct Node;

typedef struct Node *PtrToNode;       
typedef PtrToNode List;
typedef PtrToNode Position;

struct Node
{
	ElementType Course[LEN];                     
	ElementType Name[LEN];
	Position Next_course;
	Position Next_name;
	Position Name_next;
	Position Name_num;
	
};

void CreateEmptyList(List *L); 
Position Find_same_course(ElementType *X,List L);
Position Find_same_name(ElementType *X,List L);
Position Find_same_name_num(ElementType *X,List L);
void InsertH_course(List L,Position Jiedian);
void InsertH_name_num(List L,Position Jiedian);
void InsertH_name(List L,Position Jiedian);
void InsertH_name_next(List L,Position Jiedian);

#endif
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//List.c
#include "List.h"
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>


void CreateEmptyList(List *L)
{
	*L=(Position)malloc(sizeof(struct Node));      //清空链表(只留头节点) 
	(*L)->Next_course=NULL;
	(*L)->Next_name=NULL;
	(*L)->Name_next=NULL;
	(*L)->Name_num=NULL;
}

Position Find_same_course(ElementType *X,List L) //在链表中寻找课程相同课程名的节点 
{
	Position P;
	P=L;                                     //寻找某个元素在链表中的地址 
	while(P->Next_course!=L)                  //若找到,返回元素所在的节点指针,否则返回空指针 
	{
		P=P->Next_course;
		if(!strcmp(X,P->Course))
		{
			return P;
		}                                     //没问题 
	}
	if(!strcmp(X,L->Course))
	{
		return L;
	}
	return P=NULL;
}

Position Find_same_name(ElementType *X,List L) //在链表中寻找课程相同学生名字的节点 
{
	Position P;
	P=L;                                     //寻找某个元素在链表中的地址 
	while(P->Next_name!=L)                  //若找到,返回元素所在的节点指针,否则返回空指针 
	{
		P=P->Next_name;
		if(!strcmp(X,P->Name))
		{
			return P;
		}                                     //没问题 
	}
	if(!strcmp(X,L->Name))
	{
		return L;
	}
	return P=NULL;
}

Position Find_same_name_num(ElementType *X,List L) //在链表中寻找课程相同学生名字的节点 
{
	Position P;
	P=L;                                     //寻找某个元素在链表中的地址 
	while(P->Name_num!=L)                  //若找到,返回元素所在的节点指针,否则返回空指针 
	{
		P=P->Name_num;
		if(!strcmp(X,P->Name))
		{
			return P;
		}                                     //没问题 
	}
	if(!strcmp(X,L->Name))
	{
		return L;
	}
	return P=NULL;
}

void InsertH_course(List L,Position Jiedian)
{
	if(L==NULL)
	{
		return;
	} 
	List p;                                              //后插,直接插入节点 
	p=L->Next_course;
	L->Next_course=Jiedian;
	Jiedian->Next_course=p;
}

void InsertH_name_num(List L,Position Jiedian)
{
	if(L==NULL)
	{
		return;
	} 
	List p;                                              //后插,直接插入节点 
	p=L->Name_num;
	L->Name_num=Jiedian;
	Jiedian->Name_num=p;
}

void InsertH_name(List L,Position Jiedian)
{
	if(L==NULL)
	{
		return;
	} 
	List p;                                              //后插,直接插入节点 
	p=L->Next_name;
	L->Next_name=Jiedian;
	Jiedian->Next_name=p;
}

void InsertH_name_next(List L,Position Jiedian)
{
	if(L==NULL)
	{
		return;
	} 
	List p;                                              //后插,直接插入节点 
	p=L->Name_next;
	L->Name_next=Jiedian;
	Jiedian->Name_next=p;
}

 

转载于:https://my.oschina.net/u/3397950/blog/873411

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Java中实现多重链表结构可以使用嵌套的链表结构。下面是一个简单的示例代码: ``` public class MultiLinkedListNode { private int data; private MultiLinkedListNode next; private MultiLinkedListNode down; public MultiLinkedListNode(int data) { this.data = data; this.next = null; this.down = null; } public void setNext(MultiLinkedListNode next) { this.next = next; } public void setDown(MultiLinkedListNode down) { this.down = down; } public MultiLinkedListNode getNext() { return next; } public MultiLinkedListNode getDown() { return down; } public int getData() { return data; } } ``` 在上面的代码中,`MultiLinkedListNode`类表示多重链表的节点,包含一个`data`字段用于存储节点的数据,一个`next`字段表示下一个节点的引用,一个`down`字段表示下一级链表的头节点的引用。可以使用`setNext`和`setDown`方法设置`next`和`down`引用,使用`getNext`和`getDown`方法获取`next`和`down`引用,使用`getData`方法获取节点的数据。 使用上述节点实现多重链表结构的示例如下: ``` public class MultiLinkedList { private MultiLinkedListNode head; public MultiLinkedList() { this.head = null; } public void add(int data) { MultiLinkedListNode newNode = new MultiLinkedListNode(data); if (head == null) { head = newNode; } else { MultiLinkedListNode current = head; while (current.getNext() != null) { current = current.getNext(); } current.setNext(newNode); } } public void addDown(int data) { MultiLinkedListNode newNode = new MultiLinkedListNode(data); if (head == null) { head = newNode; } else { MultiLinkedListNode current = head; while (current.getDown() != null) { current = current.getDown(); } current.setDown(newNode); } } } ``` 在上面的代码中,`MultiLinkedList`类表示多重链表,包含一个`head`字段表示头节点的引用。可以使用`add`方法向当前层级的链表中添加节点,使用`addDown`方法添加下一级链表的头节点。 使用上述多重链表的示例代码如下: ``` MultiLinkedList multiLinkedList = new MultiLinkedList(); multiLinkedList.add(1); multiLinkedList.add(2); multiLinkedList.add(3); multiLinkedList.addDown(4); multiLinkedList.addDown(5); multiLinkedList.add(6); multiLinkedList.addDown(7); ``` 上述代码表示构建了一个多重链表,第一层级的链表包含节点1、2、3和节点6,节点1和节点6下面分别有一个下一级链表,第二层级的链表分别包含节点4、5和节点7。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值