⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 get_node_list.cmt

📁 稀疏矩阵、链表、图、队列、二叉树、多叉树、排序、遗传算法等的实现
💻 CMT
字号:
/**************************************************************************
**  SP_GET_NODE_LIST                                                     **
**                                                                       **
**    Retrieves a pointer to the node list associated with the passed    **
**  dimension and header element sequence number.                        **
**                                                                       **
**  INPUT:                                                               **
**    sp -- The sparse matrix which contains the header list stack       **
**    dim -- The dimension of the header list being requested            **
**    seq -- The sequence number of the header element                   **
**                                                                       **
**  OUTPUT:                                                              **
**    SP_NODE -- A pointer to the node list                              **
**                                                                       **
**  SIDE EFFECTS:                                                        **
**    The error_no field of the sparse matrix can be set to an error if  **
**  an error is encountered.  Whenever an error is encountered, this     **
**  value is set and a NULL pointer is returned.  Thus, if a NULL        **
**  pointer is returned from this function it is important to examine    **
**  the error_no of the associated sparse matrix before assuming that    **
**  the node list is empty.                                              **
**                                                                       **
**  NOTES:                                                               **
**    It is possible for the node list associated with a dimension and   **
**  header element to be empty if no values are in the matrix.           **
**  Therefore, the error_no value should be checked in the associated    **
**  sparse matrix whenever a NULL pointer is returned.                   **
**                                                                       **
**************************************************************************/

#include <stdio.h>
#include "sparse.h"

SP_NODE *sp_get_node_list(SPARSE_MATRIX *sp, int dim, int seq)
/* SPARSE_MATRIX *sp The sparse matrix in which to find the header list */
/* int dim           The dimension number of the header list */
/*     seq           The sequence number of the header list element */
{
  SP_HDR_ELEMENT *header_element;

  /* If the sparse matrix passed is empty, then there are no nodes to 
     be found */
  if (sp == (SPARSE_MATRIX *)NULL)
    return ((SP_NODE *)NULL);

  sp->error_no = SP_NOERR;

fprintf(stdout, "sp_get_node_list: Calling sp_hdr_list_element_get(sparse, %d, %d)\n", dim, seq);
  /* Retrieve the header list element associated with the dimension and 
     sequence*/
  header_element = sp_hdr_list_element_get(sp, dim, seq);
  if ((sp->error_no != SP_NOERR) || (header_element == (SP_HDR_ELEMENT *)NULL))
  {
fprintf(stdout, "sp_get_node_list: Bad header element returned\n");
fprintf(stdout, "sp_get_node_list: Error number = %d\n", sp->error_no);
    return((SP_NODE *)NULL);
  }

fprintf(stdout, "sp_get_node_list: Returning a header with sequence number %d\n", header_element->sequence);
  return(header_element->first);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -