1、int sq_insert(int list, int *p_n, int i, int x)int j; if (i*p_n) return(1); if (*p_n=MAXSIZE) return(2); for (j=*p_n+1; ji; j-) listj=listj-1; listi=x; (*p_n)+; return(0); /*delete in a seq list*/int sq_delete(int list, int *p_n, int i) int j;=*p_n) return(1); for (j = i+1; j=*p_n; j+) listj-1 = lis
2、tj; (*p_n)-;void main() int i,x,temp; printf(please input the number for nn);n= scanf(%d,&n); for (i=0; istruct node char data; struct node *next; ;typedef struct node NODE;/*This function creates a link_list with N nodes.*/NODE *create_link_list(int n)int i; NODE *head, *p, *q; if (n=0) return NULL
3、; head = (NODE *) malloc(sizeof(NODE); p = head;Please input %d chars for the link listnn; scanf(%c , &(p-data); q=(NODE *)malloc(sizeof(NODE);test3n p-next=q; p=q; getchar(); p-next=NULL; return (head);/*This function inserts a node whose value is b*/*before the node whose value is a, if the node i
4、s not exist,*/*then insert it at the end of the list*/void insert(NODE *p_head, char a, char b) NODE *p, *q; q = (NODE *)malloc(sizeof(NODE); q-data = b;next =NULL; if (* p_head = NULL) * p_head = q; else p=(NODE*)malloc(sizeof(NODE); p = * p_head; while (p-data != a &next != NULL) p = p-next; q-nex
5、t = p-next = q;/*The function deletes the node whose value is a,*/*if success, return 0, or return 1*/int deletenode(NODE *p_head, char a) q=*p_head; if (q=NULL) return(1); if (q-data = a) * p_head = q- free(q); return (0); while (q- p = q; q = q- if (q- p-next = q- free(q); return(0); else return(1
6、); NODE *my_head,*p; /* create a link list with m nodes */ int m; char ch_a,ch_b;please input the number of nodes for the link_listnm=m);test1n my_head = (NODE *) malloc(sizeof(NODE); my_head=create_link_list(m); /*Output the link list*/The link list is like: p=my_head; while (p !,p-data); p=p- /*in
7、sert a node whose value is b before a*/Please input the position for an ch_a=%cch_a);Please input the value that you want to insertn ch_b=ch_b); insert(&my_head,ch_a,ch_b);The link list after insertion is like: /*delete a node whose value is a*/Please input the position for a a= deletenode(&my_head,ch_a);The link list after deleting is like:3. 运行以下程序并分析各子函数的主要功能。#include struct tagNode int data; struct tagNode *pNext;typedef struct tagNode* pNode;/将结点插入到链表的适当位置,这是一个降序排列的链表/void insertList(pNode head,/链表头结
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1