當前位置:首頁 » 編程語言 » c語言有向量和列表嗎
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言有向量和列表嗎

發布時間: 2023-02-18 03:35:01

『壹』 c語言表示列表的問題

/*
抱歉,又是我
*/

//#define debug

struct dimension
{
int num_row ;
int num_col ;
} ;

void table_set_entry (const int t[] ,const struct dimension *dim ,const int row ,const int col ,const int v)
{
if (t == 0 || dim == 0 || row < 0 || col < 0 || row >= dim->num_row || col >= dim->num_col)
return ;

t[col * dim->num_row + row] = v ;

return ;
}

int table_get_entry (const int t[] ,const struct dimension *dim ,const int row ,const int col)
{
if (t == 0 || dim == 0 || row < 0 || col < 0 || row >= dim->num_row || col >= dim->num_col)
return 0 ;

return t[col * dim->num_row + row] ;
}

void table_clear (const int t[] ,struct dimension *dim)
{
if (t == 0 || dim == 0)
return ;

const int* pb = t ;
const int* pe = t + dim->num_row * dim->num_col ;
int* p ;

for (p = pb ; p < pe ; p++)
*p = 0 ;

return ;
}

void table_ (const int a[] ,const int b[] ,struct dimension *dim)
{
if (a == 0 || b == 0 || dim == 0)
return ;

const int* pab = a ;
const int* pae = a + dim->num_row * dim->num_col ;
int* pa ;

const int* pbb = b ;
int* pb ;

for (pa = pab ,pb = pbb ; pa < pae ; pa++ ,pb++)
*pb = *pa ;

return ;
}

#ifdef debug

int main ()
{
void table_set_entry (const int t[] ,const struct dimension *dim ,const int row ,const int col ,const int v) ;
int table_get_entry (const int t[] ,const struct dimension *dim ,const int row ,const int col) ;
void table_clear (const int t[] ,struct dimension *dim) ;
void table_ (const int a[] ,const int b[] ,struct dimension *dim) ;

int t[10][10] ;
int f[100] ;
const struct dimension dim = {10 ,10} ;
const int row = 4 ;
const int col = 7 ;
const int v = 250 ;

table_set_entry (t ,&dim ,row ,col ,v) ;

printf ("isn't %d equal to %d ?\n" ,t[col][row] ,table_get_entry (t ,&dim ,row ,col)) ;

table_ (t ,f ,&dim) ;
table_clear (t ,&dim) ;

printf ("t : %d while f : %d\n" ,t[col][row] ,f[col * dim.num_row + row]) ;

return 0 ;
}

#endif

『貳』 C語言能否定義向量,怎樣定義

C語言不支持向量;
可以自己定義結構體,用兩個坐標來表示或輻角表示

『叄』 C語言的概述提到位元組和變數還有向量是什麼意思

位元組表示大小,在計算機中存儲的最小單位就是位元組
變數表示在程序編寫過程中需要用到的中間值
向量就是數學中的概念了,用不同的C語言代碼可以實現向量的基本操作

『肆』 學習C語言具備的能力.

其實呢,學習c語言沒有其他,編程能力都是靠代碼推出來的。你首先得端正學習態度,語言的運用千萬不要待全部學完語法後才開始。你必須從模仿開始,邊模仿開始。當然,得先買一本好書,我建議你先去買譚浩強編寫的書,適合初學者。還有,就算不知道某條語句什麼意思,你也要把代碼敲進去,而不要等,當你把語法都學完,你會發現,你對c已經很熟悉了,可以融會貫通了。不管學習什麼語言,都是一個長期的過程。只有堅持了,代碼敲多了,你才能學好。記住,編程能力不是光聽課和看書就能提高的,最最重要的還是多寫程序!
要說必背必記的東西,就是英語單詞了。說實話,英語不需要太多。但是,有扎實的英語單詞功底對於程序的表達很重要,當每個人的編程能力都差不多的話,如果你的變數名是用英語命名的,會使你的程序看起來更清晰,更流暢,你的競爭力也就比別人高了。

『伍』 數據結構(C語言)

#include<stdio.h>

//順序表
#define ListSize 100 //表空間的大小可根據實際需要而定,這里假設為100
typedef int DataType; //DataType的類型可根據實際情況而定,這里假設為int
typedef struct
{
DataType data[ListSize];//向量data用於存放表結點
int length;//當前的表長度
}SeqList;

//表的初始化
void InitList(SeqList *L)//將表的長度置為0
{
L->length=0;
}

//將新結點x按升序插入L所指的順序表
int Insert_SqList(SeqList *L,DataType x)
{
int i=0,j;
//表空間溢出
if (L->length>=ListSize)
{
printf("表空間溢出\n");
return 0;
}
//第一個元素直接插入
if(L->length==0)
L->data[L->length]=x;
else
{
//尋找插入位置
//跳出循環2個條件1:一直找到末尾沒有比x大的
//2:找到比x不小的元素
while(i<L->length&&L->data[i]<x) i++;

if(i==L->length)//如果到末尾,直接添加
L->data[i]=x;
else
{
//結點後移
for(j=L->length-1;j>=i;j--)
L->data[j+1]=L->data[j];
L->data[i]=x; //插入x
}
}

//表長加1
L->length++;
return 1;
}

//列印順序表
int ListPrint(SeqList *L)
{
int i;
if(L->length==0)
{
printf("順序表為空\n");
return 0;
}

printf("順序表:\n");
for(i=0;i<L->length;i++)
printf("%d ",L->data[i]);
return 1;
}

int main()
{
SeqList L,*p;
int num,j;
DataType x;

p=&L;

printf("請輸入元素個數:");
scanf("%d",&num);

//表的初始化
InitList(p);

//錄入數據
for(j=1;j<=num;j++)
{
printf("輸入第%d個元素:",j);
scanf("%d",&x);
if(Insert_SqList(p,x)!=1)
return 1;
}
//列印順序表
ListPrint(p);
return 0;
}

『陸』 C語言數據結構中的向量的具體定義是什麼怎麼使用最重要的是使用。誠請高手出來交流學問!

向量一般用二維的坐標表示 你可以直接用坐標點表示 終點減起始點(end start)
我這里給你結構體的表示方法
struct Point
{
double x;
double y;
};//坐標表示
struct Vactor
{
point start;
point end;
};//向量 表示
向量在實際運用舉例
double proct (V*v1)
{
V vt1,vt2;
vt1.strat.x=vt1.start.y=0;
vt1.end.x=V1->end.x-v1->start.x;
vt1.end.y=V1->end.y-v1->start.y;
////////////以下可以寫自己設計的演算法函數
}
你可以嘗試運用此方法求個點積 引申 進而判斷線與線 面與面的關系

『柒』 請問C語言及數據結構中的向量具體表示什麼意思

向量就是順序表,一般以數組實現,可能用定長數組實現,存放元素個數有限制,也可能用動態長度數組實現,一旦元素裝滿後會再次申請更大的空間並將原有數據拷貝過去。說白了,向量就是一個鏈表。當然,其擴展性、實用性遠遠高於我們平常使用的鏈表。你可以在程序里#include <vector.h>,然後就如vector內部查看向量的定義,對學習數據結構幫助很大哦。