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

📄 hdr_list_element_get.cmt

📁 稀疏矩阵、链表、图、队列、二叉树、多叉树、排序、遗传算法等的实现
💻 CMT
字号:
/**************************************************************************
**  HDR_LIST_ELEMENT_GET                                                 **
**                                                                       **
**    Retrieves a header list element.                                   **
**                                                                       **
**  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_HDR_ELEMENT * -- A pointer to the header element                **
**                                                                       **
**  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 header element associated with a dimension  **
**  sequence to be empty if no header element is 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_HDR_ELEMENT *sp_hdr_list_element_get(SPARSE_MATRIX *sp, int dim, int seq)
/* SPARSE_MATRIX *sp  The sparse matrix in which to find the header list 
                        element */
/* int dim            The dimension number of the header list element*/
/*     seq            The sequence number of the header list element */
{
  SP_HDR_ELEMENT *header_list, *header_element;

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

  sp->error_no = SP_NOERR;

  /* Retrieve the header list associated with the dimension */
  header_list = sp_get_header_list(sp, dim);
  if ((sp->error_no != SP_NOERR) || (header_list == (SP_HDR_ELEMENT *)NULL))
  {
    return((SP_HDR_ELEMENT *)NULL);
  }

  /* Make sure that the sequence number specified is within range */
  if ((seq < sp_get_range_min(sp, dim)) || (sp->error_no != SP_NOERR))
  {
    sp->error_no = SP_DLOW;
    return((SP_HDR_ELEMENT *)NULL);
  }

  /* Make sure that the sequence number specified is within range */
  if ((seq > sp_get_range_max(sp, dim)) || (sp->error_no != SP_NOERR))
  {
    sp->error_no = SP_DHIGH;
    return((SP_HDR_ELEMENT *)NULL);
  }

  /* Search the header list for the requested sequence */
  header_element = header_list;
fprintf(stdout, "sp_hdr_list_element_get: Header of the list sequence is %d\n", 
                header_element->sequence);
fprintf(stdout, "sp_hdr_list_element_get: Next in list sequence is %d\n",
                (header_element->next)->sequence);
fprintf(stdout, "sp_hdr_list_element_get: Looking for sequence %d\n", seq);
  while ((header_element->next->sequence <= seq) && 
         (header_element->next != header_list))
  {
fprintf(stdout, "sp_hdr_list_element_get: Passing by sequence number %d\n", header_element->sequence);
    header_element = header_element->next;
  }

fprintf(stdout, "sp_hdr_list_element_get: Checking to see if the sequence number is correct\n");
fprintf(stdout, "sp_hdr_list_element_get: Current sequence = %d\n", header_element->sequence);
fprintf(stdout, "sp_hdr_list_element_get: Next sequence = %d\n", header_element->next->sequence);
  /* If the header_element is not the same sequence number as passed in, 
     then the sequence number is not in the list */
  if (header_element->sequence != seq)
  {
fprintf(stdout, "sp_hdr_list_element_get: Header element not found\n");
    return((SP_HDR_ELEMENT *)NULL);
  }
  else
  {
fprintf(stdout, "sp_hdr_list_element_get: Returning header element with sequence number %d\n", header_element->sequence);
    return(header_element);
  }
}

⌨️ 快捷键说明

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