匿名使用者
匿名使用者 發問時間: 電腦與網際網路程式設計 · 10 年前

C語言程式題目

學校的作業,有點不知道如何著手,有人能幫忙嗎030,不是要寫程式出來,只是寫個大概的樣子或是範例,我會再照自己的意思去修改...

對於LINK這部分不是說很熟悉,不太會使用。

1. Problem: Editor

Using Doubly Linked List to design and implement your program.

=> Command Line 模式 (Full Screen 模式亦可)Functions:

i. New File, Open File, Save File

ii. Move Forward or Backward (one line or a block)

iii. Insert a Line

iv. Delete a Line

v. Search a Word // 單一列 or 檔案全部

vi. Copy Lines // a block

vii. Paste Lines // a block

viii. Cut Lines // a block

ix. Move Lines // a block

x. List All Lines and Current Line with Line Number on the screen

Notes:

i. 使用 doubly linked list 設計程式

ii. 讀入每一列空間均使用動態記憶體配置的方式儲存資料

Ex:

Input file:

1 Hi, this assignment looks great.

2 We have to study hand and work harder to do it.

3 Sure… I know.

當將指標(Current Line ptr)移到目前要處理的第二列資料處,其相對應的 doubly linked list

1 個解答

評分
  • 其威
    Lv 7
    10 年前
    最佳解答

    首先你需要設計 double linked list 的 node, 例如:typedef struct _DLL_Node DLL_Node;struct _DLL_Node { DLL_Node *priv, DLL_Node *next, char *data};data 就可以用來放每行的資料. 我不知道你的 "區塊" 是怎樣定義, 所以用 line 當單位.void insert(DLL_Node *pos, DLL_Node *newline){ DLL_Node *next_pos = pos->next; newline->priv = pos; newline->next = next_pos; pos->next = newline; if (next_pos) next_pos->priv = pos;}void delete(DLL_Node *pos){ DLL_Node *priv_pos = pos->priv; DLL_Node *next_pos = pos->next; if (priv_pos) priv_pos->next = next_pos; if (next_pos) next_pos->priv = priv_pos; free_node(pos);}void search(DLL_Node *from, char *target, DLL_Node **found, int *pos){ // 自己檢查 found 跟 pos 是否為 NULL... while(from) { *pos = your_string_search_function(from->data, target); if (*pos != -1) { *found = from; return; } from = from->next; } *found = NULL;}void _clone_node(DLL_Node *from, DLL_Node *to){ to->priv = from->priv; to->next = from->next; your_data_copy_function(from->data, to->data);}DLL_Node *buf; void copy(DLL_Node *start, DLL_Node *end){ strict DLL_Node *newline, *i, **tmp = &buf; free_list(buf); for (i = start;i != end;i = i->next) { newline = (DLL_Node *)malloc(sizeof(*newline)); _clone_node(i, newline); newline->priv = *tmp; newline->next = NULL; tmp = &newline; }}void paste(DLL_Node *pos){ DLL_Node *tmp = buf, *next_pos = pos->next; if (!buf) return; while (tmp->next) tmp = tmp->next; pos->next = buf; buf->priv = pos; tmp->next = next_pos; if (next_pos) next_pos->priv = tmp;}void cut(DLL_Node *start, DLL_Node *end){ free_list(buf); buf = start; end->next->priv = start->priv; start->priv->next = end->next; end->next = NULL;}

    2010-12-14 09:59:50 補充:

    void move(DLL_Node *start, DLL_Node *end, DLL_Node *to)

    {

    DLL_Node *oldbuf = buf;

    cut(start, end);

    paste(to);

    buf = oldbuf;

    }

    2010-12-14 10:03:49 補充:

    一直說我超過字數, 還有一個貼不上來...

    印資料的函式就自己寫吧!

還有問題?馬上發問,尋求解答。