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

📄 add_tuple.c

📁 稀疏矩阵、链表、图、队列、二叉树、多叉树、排序、遗传算法等的实现
💻 C
字号:
/**************************************************************************
**  SP_ADD_TUPLE                                                         **
**                                                                       **
**    Adds a sequence number into a tuple.                               **
**                                                                       **
**  INPUT:                                                               **
**    tuple -- The tuple which is to get the new sequence number         **
**    dim -- The dimension getting a new sequence value                  **
**    seq -- The sequence number being added                             **
**                                                                       **
**  OUTPUT:                                                              **
**    SP_TUPLE * -- A pointer to the modified tuple                      **
**                                                                       **
**  SIDE EFFECTS:                                                        **
**    None.                                                              **
**                                                                       **
**  NOTES:                                                               **
**                                                                       **
**************************************************************************/

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

SP_TUPLE *sp_add_tuple(SP_TUPLE *tuple, int dim, int seq)
/* SP_TUPLE *tuple  The tuple which is to get the new sequence number */
/* int dim             The dimension number */
/*     seq             The sequence number being added */
{
  int *new_seq;

  /* If the tuple is empty, then no sequence can be added */
  if (tuple == (SP_TUPLE *)NULL)
  {
    return((SP_TUPLE *)NULL);
  }

  /* If the passed dimension is outside the range of the tuple dimension, then
     the insert fails */
  if ((tuple->dimensions < dim) || (dim < (int)1))
  {
    return((SP_TUPLE *)NULL);
  }

  new_seq = (int *)(tuple->seq + ((dim - 1)));
  *new_seq = seq;
  return(tuple);
}

⌨️ 快捷键说明

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