Example #1
0
void main()
{
    
    int i;
    ElemType e;
    struct node *L;
    struct node *L1,*L2;
	ElemType a[5]={'a','b','c','d','e'},b[5]={'f','g','h','i','j'};
    InitList(L);					//初始化
    InsElem(L,'a',1);
    InsElem(L,'c',2);
    InsElem(L,'a',3);
    InsElem(L,'e',4);
    InsElem(L,'d',5);
    InsElem(L,'b',6);
    printf("线性表L:");DispList(L);
    printf("长度:%d\n",GetLength(L));
    i=3;GetElem(L,i,e);
    printf("第%d个元素:%c\n",i,e);
    e='a';
    printf("元素%c是第%d个元素\n",e,Locate(L,e));
    i=4;printf("删除第%d个元素\n",i);
    DelElem(L,i);
    printf("线性表:");DispList(L);   //
	CreateListF(L1,a,5);
    printf("线性表L1:");
    DispList(L1);
    CreateListR(L2,b,5);
    printf("线性表L2:");
    DispList(L2);
}
Example #2
0
void main()
{
	LinkList *L1,*L2,*L3;
	ElemType a[]={'1','3','5'};
	ElemType b[]={'2','4','6','7'};
	InitList(L1);
	InitList(L2);
	InitList(L3);
	CreateListR(L1,a,3);
	printf("L1:");DispList(L1);
	CreateListR(L2,b,4);
	printf("L2:");DispList(L2);
	printf("归并\n");
	UnionList(L1,L2,L3);
	printf("L3:");DispList(L3);
}
Example #3
0
int main(void)
{
	ElemType site[11] = { 'a', 'n', 'o', 't', 'h', 'e', 'r', 'h', 'o', 'm', 'e' };
	LinkList *Link, *LinkR;
	ElemType e;

	CreateListF(Link, site, 11);
	CreateListR(LinkR, site, 11);
	DispList(Link);
	DispList(LinkR);
	DestroyList(LinkR);
	if (ListEmpty(Link))
	{
		printf("List is empty\n");
	}
	else
	{
		printf("List isn't empty\n");
	}
	printf("ListLength: %d\n", ListLength(Link));
	GetElem(Link, ListLength(Link), e);
	ListInsert(Link, 2, e);
	DispList(Link);
	ListDelete(Link, 3, e);
	DispList(Link);
	printf("The location of 'o' is %d\n", LocateElem(Link, 'o'));
	DestroyList(Link);

	return 0;
}
Example #4
0
int main() {
    linknode *flist,*rlist,*find;
    int index; char value;
    rlist=(linknode*)malloc(sizeof(linknode));
    rlist->next=NULL;
    printf("plase input a sting,end with the KEY_Enter \n");
    //flist=CreateListF();
    //printLinkList(flist);
    CreateListR(rlist);
    printLinkList(rlist);
    printf("list length=%d \n",getLength(rlist));
    printf("set insert node:index,value:");
    scanf("%d,%c",&index,&value);
    printf("insert a element!");
    insertList(rlist,value,index);
    printLinkList(rlist);
    printf("list length=%d \n",getLength(rlist));
    printf("set delete node index:");
    scanf("%d",&index);
    deleteList(rlist,index);
    printf("delete a element!");
    printLinkList(rlist);
    printf("list length=%d \n",getLength(rlist));
    printf("set visit node index:");
    scanf("%d",&index);
    find=getNode(rlist,index);
    if(find!=NULL)
    {
        printf("this node value=%c \n",find->data);
    }
    
    return 0;
}
Example #5
0
void main()
{
	PolyNode *ha,*hb,*hc;
	PolyArray a={{1.2,0},{2.5,1},{3.2,3},{-2.5,5}};
	PolyArray b={{-1.2,0},{2.5,1},{3.2,3},{2.5,5},{5.4,10}};
	CreateListR(ha,a,4);
	CreateListR(hb,b,5);
	printf("原多项式A:   ");DispPoly(ha);
	printf("原多项式B:   ");DispPoly(hb);
	Sort(ha);
	Sort(hb);
	printf("有序多项式A: ");DispPoly(ha);
	printf("有序多项式B: ");DispPoly(hb);
	Add(ha,hb,hc);
	printf("多项式相加:  ");DispPoly(hc);
	DestroyList(ha);
	DestroyList(hb);
	DestroyList(hc);
}
Example #6
0
void main()
{
	LinkList *L;
	int n=10;
	char a[]={'1','3','2','9','0','4','7','6','5','8'};
	InitList(L);
	CreateListR(L,a,n);
	printf("L:");DispList(L);
	printf("排序\n");
	sort(L);
	printf("L:");DispList(L);
	DestroyList(L);
}
Example #7
0
int main()
{
	int arr[10]={6,3,8,5,1,18,9,2,4,15};
	LinkList *list,*t;
	CreateListR(list,arr,10);
	DispList(list);
	
//	Delete(list,3,5);
//	DispList(list);
	
	t=reverse(list);
	DispList(t);
	
//	ListSort(list);
//	DispList(list);
	return 0;
}