单链表栈无法读取内存

#ifndef MY_LIST_H
#define MY_LIST_H

class OutOfBound {};
class IllegalSize{};

template
class MyList
{
public:
virtual void clear() = 0;
virtual int length() const = 0;
virtual void insert(int, const elemType &) = 0;
virtual void remove(int) = 0;
virtual int search(const elemType &) const = 0;

virtual const elemType& visit(int) const = 0;
virtual void traverse() const = 0;
virtual ~MyList(){}

};

#endif
#ifndef MYDIRLIST_H
#define MYDIRLIST_H
#include "mylist.h"
#include
using namespace std;

template
class MyDirList : public MyList < elemType >
{
private:
struct node{
elemType data;
node *pNext;
node() : pNext(NULL){}
node(const elemType &_data, node *p = NULL) :
data(_data), pNext(p){}
};
node *m_pHead;
int m_dLength;
node *moveTo(int) const;
public:
MyDirList(){
m_pHead = new node;
m_dLength = 0;
}
~MyDirList(){
clear();
delete m_pHead;
}
void clear();
int length() const { return m_dLength; }
void insert(int, const elemType &);
void remove(int);
int search(const elemType &) const;
const elemType &visit(int) const;
void traverse() const;
};

template
typename MyDirList::node* MyDirList::moveTo(int pos) const
{
if (pos < -1 || pos >= m_dLength) throw OutOfBound();
node *p = m_pHead;
while (pos-->=0) p = p->pNext;
return p;
}

template
void MyDirList::clear()
{
node *p = m_pHead->pNext, *q;
while (p != NULL)
{
q = p->pNext;
delete p;
p = q;
}
m_dLength = 0;
}

template
void MyDirList::insert(int pos, const elemType &_data)
{
if (pos < 0 || pos > m_dLength) throw OutOfBound();
node *p = moveTo(pos - 1);
node *tmp = new node(_data, p->pNext);
p->pNext = tmp;
m_dLength++;
}

template
void MyDirList::remove(int pos)
{
if (pos < 0 || pos >= m_dLength) throw OutOfBound();
node *p = moveTo(pos - 1);
node *q = p->pNext;
p->pNext = q->pNext;
delete q;
m_dLength--;
}

template
int MyDirList::search(const elemType &_data) const
{
node *p = m_pHead->pNext;
int pos = 0;
while (p != NULL)
{
if (_data == p->data) return pos;
p = p->pNext;
pos++;
}
return -1;
}

template
const elemType &MyDirList::visit(int pos) const
{
if (pos < 0 || pos >= m_dLength) throw OutOfBound();
node *p = moveTo(pos);
return p->data;
}

template
void MyDirList::traverse() const
{
node *p = m_pHead->pNext;
while (p != NULL)
{
int i = 0;
cout << "Data #" << i++ << ": " << p->data << endl;
p = p->pNext;
}
cout << "End of data" << endl;
}

#endif
#ifndef MYSTACK_H
#define MYSTACK_H
#include "mydirlist.h"
//在本文件中完成类接口的定义
template
class MyStack
{
public:
MyStack()
{
m_pStack = new MyDirList;
};
~MyStack();
void push_back(const elemType &value);
void pop_back();
bool isEmpty() const { return m_pStack == NULL; };
const elemType &back() const { return m_pStack->visit(m_pStack->length()); };
private:
MyDirList *m_pStack;

};

template
MyStack::~MyStack()
{
delete m_pStack;
}

template
void MyStack::push_back(const elemType & value)
{
m_pStack->insert(m_pStack->length(), value);
}
template
void MyStack::pop_back()
{
m_pStack->remove(m_pStack->length());
}

#endif
#include

#include "mystack.h"

using namespace std;
int main( )

{
MyStacka;
}

图片说明
最好只改stack里的。小白求赐教...

0

1个回答

p这个指针你没有初始化,还是cccccccc

0
qq_38211455
qq_38211455 回复caozhy: 你说的方法具体要怎么弄呢。。我已经快死了。。
2 年多之前 回复
qq_38211455
qq_38211455 回复caozhy: 具体要怎么弄呢。我觉得我应该不是p没初始化,而是在MyStack那里的m_pStack那个指针没有初始化,但是又不知道怎么弄,求大神赐教
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
内存无法读取
解决,软件SD卡解决无法读取、格式化修复工具
C++ 无法读取内存
vs2012调试程序时又遇到一个新问题,“无法读取内存”,找了半天终于找到,哭死: errors:OpenCV Error: Assertion failed (dims &amp;lt;= 2 &amp;amp;&amp;amp; data &amp;amp;&amp;amp; (unsigned)i0 &amp;lt; (unsigned)size.p[0] &amp;amp;&amp;amp; (unsigned)(i1*DataType&amp;lt;_Tp...
内存无法读取,怎么回事
[code=c]#include rn#includernusing namespace std;rnclass Studentrnrnpublic:rn float score;rn int num;rn char name[30];rnpublic:rn Student()rn rn strcpy_s(this->name, "nameless");rn this->num = 0;rn this->score = 0;rn rn int compare(float max)rn rn if (this->score>max)rn rn return 1;rn rn else if (this->score == max)rn rn return 2;rn rn return 3;rn rnrn;rnint main()rnrn int n = 0;rn do rn printf("请输入学生人数(1-30之间):\n");rn scanf_s("%d", &n);rn while (n<0|| n>30);rn Student*pStudents = new Student[n]; //定义学生类数组记录并比较成绩rn printf("请按学号,姓名,成绩的顺序输入学生信息\n");rn for (int i = 0; i < n; i++)rn rn printf("请输入地%d个学生的信息\n", i + 1);rn scanf_s("%d,%d,%d", &pStudents[i].num, &pStudents[i].name, &pStudents[i].score);rnrn Student*pStudents_M = new Student[1];rn float Max_score = 0;rn int Max_count = 1;rn for (int i = 0; i < n; i++)rn rn switch (pStudents[i].compare(Max_score))rn rn case 1:rn Max_score = pStudents[i].score;rn Max_count = 1;rn if (pStudents_M != NULL)rn rn delete[]pStudents_M;rn rn pStudents_M = new Student[1];rn pStudents_M[0] = pStudents[1];rn break;rn case 2:rn Student*pTemp = pStudents_M;rn pStudents_M = new Student[++Max_count];rn for (int j = 0; j < Max_count; j++)rn rn pStudents_M[j] = pTemp[j];rn rn pStudents_M[Max_count - 1] = pStudents[i];rn delete[]pTemp;rn break;rn rn rn printf("当前最高成绩为%d,成绩最高者:\n", Max_score);rn for (int i = 0; i < Max_count; i++)rn rn printf("%d,%s,%d\n", pStudents_M[i].num, pStudents_M[i].name, pStudents_M[i].score);rn rn delete[]pStudents;rn delete[]pStudents_M;rn return 0;rnrn rn[/code]rn新手上路多指教
关于内存无法读取~~
Type VS_NEWINFOrn astr As String * 1024rnEnd TypernrnDeclare Function GetFileVersionInfo Lib "Version.dll" Alias _rn "GetFileVersionInfoA" (ByVal lptstrFilename As String, ByVal _rn dwhandle As Long, ByVal dwlen As Long, lpData As Any) As LongrnDeclare Function GetFileVersionInfoSize Lib "Version.dll" Alias _rn "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, _rn lpdwHandle As Long) As LongrnDeclare Function VerQueryValue Lib "Version.dll" Alias _rn "VerQueryValueA" (pBlock As Any, ByVal lpSubBlock As String, _rn lplpBuffer As Any, puLen As Long) As LongrnDeclare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" _rn (dest As Any, ByVal Source As Long, ByVal Length As Long)rnDeclare Function GetSystemDirectory Lib "kernel32" Alias _rn "GetSystemDirectoryA" (ByVal Path As String, ByVal cbBytes As Long) As LongrnrnPublic Function GetFileCoName(FullFileName As String) As StringrnDim rc As LongrnDim lDummy As LongrnDim szBuffer() As ByternDim lBufferLen As LongrnDim lVerPointer As LongrnDim lVerbufferLen As LongrnDim astr As StringrnDim lTran As LongrnDim ab As VS_NEWINFOrnOn Error Resume NextrnlBufferLen = GetFileVersionInfoSize(FullFileName, lDummy)rnGetFileCoName = "未知"rnIf Not (lBufferLen < 1) Thenrn ReDim szBuffer(lBufferLen)rn lVerPointer = 0rn rc = GetFileVersionInfo(FullFileName, 0&, lBufferLen, szBuffer(0))rn rc = VerQueryValue(szBuffer(0), "\VarFileInfo\Translation", lVerPointer, lVerbufferLen)rn MoveMemory lTran, lVerPointer, 4&rn astr = "0" + Hex$(lTran)rn astr = Right$(astr, 4) + Left$(astr, 4)rn rc = VerQueryValue(szBuffer(0), "\StringFileInfo\" + astr + "\CompanyName", lVerPointer, lVerbufferLen)rn If rc Thenrn MoveMemory ab, lVerPointer, Len(ab) rn GetFileCoName = Left$(ab.astr, (InStr(ab.astr, Chr$(0)) - 1))rn Elsern GetFileCoName = "未知"rn End IfrnEnd IfrnEnd Function
小白求助,无法读取内存
int Del_book(BOOK * Head)rnrn BOOK * head=Head->pNext;//Head指向头结点,head指向第一个结点rn BOOK *temp;//存放要删除的结点rn int pos;rn int i;rn if (Empty_book(Head))rn rn printf("链表为空\n");rn return false;rn rn elsern rn int key;rn printf("1.搜索删除\n");rn printf("2.直接删除\n");rn scanf("%d", &key);rn if (key == 1)rn rn pos = loc_book(Head);rn rn if (key == 2)rn rn printf("请输入你要删除第几个数据:");rn scanf("%d", &pos);rn rn for (i = 0;i < pos - 1 && head != NULL;i++)rn rn head = head->pNext;//移动head到要删除的结点rn rn if (i > pos - 1 || head == NULL || pos > Lenth_book(Head))rn rn printf("删除失败\n");rn return false;rn rn temp =head;rn printf("删除数据成功,删除的图书为:\n");rn printf("编号:%d\t 名字:%s\t 类型:%s\t 作者:%s\t 出版:%s\t 价格:%f\n\n\n", temp->num, temp->name, temp->type, temp->author, temp->publish, temp->price);rn head = head->pNext;rn free(temp);rn temp = NULL;rn rn Treaverse_book(Head);rn return true;rnrn为什么会一直提示无法读取内存?rnrn[img=https://img-bbs.csdn.net/upload/201606/14/1465912513_626384.png][/img]
内存栈
所谓的内部栈,是为了与数据结构的栈相区分开来。 今天所说的栈是指虚拟机内存里的栈。 什么是栈呢?它是java虚拟机里的内存组成部分。 从内存角度来讲,当我们创建了一个对象,那么它就会被分配到内存中,那么当我们要对这个对象进行操纵时,该怎么办呢。 我们需要把这个对象从内存中“取”出来,如何取呢? 如果现在有三个线程需要操作这个对象,那么我们需要从内存中read出这个对象的内容,创建对象副本
单链表实现栈
//链表实现栈 //用一个表头为s的链表实现,所有插入的节点都变为到s的下一个节点。 #include<new> #include<iostream>template <typename T> struct Node{ T data; Node * next; }; template <typename Type> class Stack{ public:
学生管理系统之单链表和栈的应用
运用栈和链表 实现学生信息的建立、查找、删除、查询等
动态顺序表、单链表、栈、队列
seqlist.h#pragma once #define _SEQ_LIST_ #ifdef _SEQ_LIST_ #include<iostream> #include<assert.h> #include<string> using namespace std;#define DEFAULT_CAPACITY 3 typedef int DataType;typedef struct F
利用单链表实现栈
栈是一种仅限于在头尾操作的数据结构,和队列相反,栈的特点是“现金后出”,因此又称为LIFO。和队列一样,栈也有链表和数组两种实现方式,各自的优缺点和介绍队列时提到的基本相同。以下介绍使用链表实现栈的方式(链式栈)。下面是链式栈的示意图:因为栈的特点是“先进后出”,因此我们只需要一个指针指示栈顶即可,因为无论插入或者删除都是针对顶部的节点而已,也就是说,我们需要实现一个“头节点”会变化的链表,并且每次
数据结构-----单链表,栈与队
总结单链表,链栈和环形队列的创建和使用 1.单链表: typedef struct list { int m; struct list *next; //struct list *rihgt } mylist; class List { public: List() : plist(new mylist) { if (plist == nullptr) { ...
基于单链表的栈
// 基于C++template实现的单链表类 # ifndef SINGLE_LIST_HXX # define SINGLE_LIST_HXX //节点结构 template &amp;lt;typename T&amp;gt; class Node { public : T _value; Node* _next; public: Node() = default; Nod...
数据结构---栈(单链表实现)
源代码在博客里可下载,1C币。或者找Q:1286550014 一、头文件导入 #include&amp;amp;amp;amp;amp;amp;lt;stdio.h&amp;amp;amp;amp;amp;amp;gt; #include&amp;amp;amp;amp;amp;amp;lt;stdbool.h&amp;amp;amp;amp;amp;amp;gt; #include&amp;amp;amp;amp;amp;amp;lt;stdlib.h&amp;amp;amp;amp;amp;amp;gt
单链表实现队列 栈
#include <stdio.h> #include <stdlib.h>struct list { int data; struct list *next; };typedef struct list L;L *stackInsert (L *head, int data) { L *new = calloc(1, sizeof(L)); new->data =
栈、队列、单链表
栈: #define MAX_SIZE 100//队列的最大长度 //-------------------------栈----------------------- int top=0;//栈顶变量 void add(char st[],char intput){ //入栈函数 st[top]=intput; top++; } void pop(char st[]){
java单链表实现栈
栈的实现方式二:使用单链表来实现栈package stack; /** * * &amp;lt;p&amp;gt; * 功能描述:java栈的链表实现方式 * 编程思想:链表栈中包括结点类和栈顶结点,初始化时将栈顶结点指向null * 1、添加结点时将新加入的结点指向原本的栈顶结点,将新的栈顶结点指向新插入的节点 * 2、出栈时栈顶出栈并将新栈顶结点指向原栈顶结点 * &amp;lt;/p&amp;gt; * ...
java 单链表实现栈
人生最大的错误是不断担心会犯错。 由于数组实现栈时,长度必须固定,因此空间效率及适应性不是很理想。 单链表 每个节点的 next 引用都相当与一个链接或指针,指向另一节点。单链表的长度不再固定,可以根据实际不断变化, 如此以来,包含N个元素的单链表只占用 O(N) 空间,比定长数组更为灵活。 例子: 单链表节点的实现 --------------
栈的实现(单链表头插法)
struct LNODE { int data; stack next;};//头节点生成LNODE* creatstack() { LNODE * s = new LNODE; s-&amp;gt;next = NULL; return s;}void push(LNODE *head,int a) { stack s1 = new LNODE; s1-&amp;gt;data = a; s1-&amp;gt;next...
单链表的基本操作(3):单链表实现栈
我们知道,栈是一种“后进先出”的数据结构,对栈的插入和删除操作都是在栈头位置进行的,这与在单链表的表头插入和删除元素的原理类似,因此可以用单向链表实现栈。   单链表实现栈的Java代码: package parking; import java.util.Stack; class Node { Object data; Node next; public Node(Objec...
内存栈与内存堆得区别
内存堆像一个百宝箱一样存储各种各样的数据,当程序运行时,在内存栈需要的时候进行数据的创建储存调用,当一种局部程序执行结束后在内存堆里分配适量的空间进行存储,供接下来的程序进行执行,进行调用。内存堆与内存栈之间是一种并存的关系,内存栈执行在前,内存堆执行在后。
C++ 处理图片像素时无法读取内存
//bmps 中装的是CImagenfor(int i = 0; i < bmps[nIndex].GetHeight(); i++)n for(int j = 0; j < bmps[nIndex].GetWidth();j++)n BYTE * tp1=(BYTE*)bmps[nIndex].GetPixelAddress(i,j);n BYTE * tp2=(BYTE*)bmps[nIndex+1].GetPixelAddress(i,j);n BYTE * tpOut=(BYTE*)bitmap.GetPixelAddress(i,j);n _asmn emmsn mov eax,fadetA n movupd xmm3,[eax] n mov ebx,fadetBn movupd xmm4,[ebx]nn mov ecx,tp1 n movupd xmm5,[ecx]//这里tp1无法读取内存n mov edx,tp2n movupd xmm6,[edx]nn pxor xmm7,xmm7n punpcklbw xmm5,xmm7 n punpcklbw xmm6,xmm7n punpcklbw xmm3,xmm7 n punpcklbw xmm4,xmm7nn pmullw xmm5,xmm3n pmullw xmm6,xmm4n psrlw xmm5,8 n psrlw xmm6,8 n paddw xmm5,xmm6 n n packuswb xmm5,xmm7 nn mov edi,tpOutn movsd [edi],xmm5 nn EMMS; n n n n delete []fadetA;n delete []fadetB;n //tmp = bitmap;n //CDC* pDC;n //pDC = GetWindowDC(); n //bitmap.Draw(pDC->m_hDC,0,0); n Ondraw();n
VS2013 链表插入操作 无法读取内存
工程中共有三个文件rnList.h 文件rnrnclass Nodernpublic:rnchar data;rnNode *pred;rnNode *succ;rnrnNode()rnNode(char const& e, Node *p=NULL, Node *q=NULL) data = e; pred = p; succ = q; rn~Node()rn;rnrnclass Listrnpublic:rnNode *header;rnNode *trailer;rnrnint _size;rnrnList();rn~List()rnrnint size()const;rnrnNode * insertAsPred(int n, char const& letter);rnrnchar remove(int n);rnrnvoid traverse()const;rnrn;rnrnList.cpp 文件rnrn#include"List.h"rn#includernrnList::List()rnNode *header = new Node;rnNode *trailer = new Node;rnrnheader->succ = trailer;rnheader->pred = NULL;rntrailer->pred = header;rntrailer->succ = NULL;rnrn_size = 0;rnrnrnint List::size()constrnreturn _size;rnrnrnNode * List::insertAsPred(int n, char const& letter)rnNode *flag;rnflag = header->succ;rnint times = n;rnwhile (0succ;rntimes--;rnrnNode* newNode = new Node(letter, flag->pred, flag);rnflag->pred->succ = newNode;rnflag->pred = newNode;rn_size++;rnrnreturn newNode;rnrnrnrnchar List::remove(int n)rnNode *flag;rnflag = header->succ;rnint times = n;rnwhile (0succ;rntimes--;rnrnflag->pred->succ = flag->succ;rnflag->succ->pred = flag->pred;rnchar dataTemp = flag->data;rndelete flag;rnreturn dataTemp;rnrnrnvoid List::traverse()constrnNode* newNode = header->succ;rnwhile (newNode!=trailer)rnprintf("%c ", newNode->data);rnrnrnrnmain.cpp 文件rn#include"List.h"rn#includernrnint main()rnList *testList = new List();rntestList->insertAsPred(0, 'A');rnreturn 0;rnrnrn程序运行到"flag = header->succ;"中止,rn变量信息如下rn[img=https://img-bbs.csdn.net/upload/201504/06/1428304519_818298.png][/img]rnrn恳请指教!拜托各位了。
cocos2d-x的一个无法读取内存的问题
想请教一个关于内存的一个象棋游戏游戏内出现的问题,象棋游戏我在做AI的时候,分简单和困难,下面是简单模式AI产生一个步骤的接口(需要传入的是游戏场景指针):nStep* AI::genStep(SceneGameReal* game)nnnArray* allMove = allPossibleMove(game);nnint highScore = -100000;//初始化一个最高的走棋得分nnStep* ret;nnnnfor (int i = 0; i < allMove->count(); i++)nnnnStep* step = (Step*)allMove->objectAtIndex(i);nnVirtualMove(game, step);nnint score = calcScore(game);nnif (score > highScore)nnnnhighScore = score;nnret = step;nnnnInFactMove(game, step);nnnnnreturn ret;nnn另外一个是困难模式下产生步骤的接口(也是传入游戏场景指针,另外加一个函数操作深度,下面的_step和_level是AI中定义的成员):nStep* AI::genStep(SceneGameReal* game, int level)nnn_step = NULL;nn_level = level;nnalphaBetaSearch(level, -100000, 100000, game);nnreturn _step;nnnn那么问题来了,简单模式下可以正常的运行,但是换成困难模式就出现了无法读取内存了。(显示是this也就是AI的_step 和_level无法读取,但是容易模式又没有问题)
QQ2008无法读取它的内存,请教了?
我用winhex无法读取qq2008的内存,应该是hook,加了密了,用ReadProcessMemory()函数读取返回错误,也读不到,请问大哥们用什么好的办法呢?谢谢了!!!
遍历链表时出现无法读取内存
[img=https://img-bbs.csdn.net/upload/201609/18/1474201449_286244.png][/img]rnrn写了两个链表的函数,编译通过,运行时意外停止。调试时,出现无法读取内存的情况rnrn[code=c]#include rnusing namespace std; rnrntemplate rnvoid new_forward_list(T* head, int length)rnrn T* new_one = new T;rn head = new_one;rn new_one = NULL;rn head->next = NULL;rn rn for(int counter = 1; counter < length; counter++)rn rn new_one = new T;rn new_one->next = head;rn head = new_one;rn new_one = NULL;rn rnrnrntemplate rnvoid delete_part(T* head, unsigned int place, unsigned int n)rnrn if ((place == 0) || (n == 0))rn rn exit(-1);rn rnrn T* look_for, *end, *delete_ptr;rn look_for = end = delete_ptr = head;rnrn rn for(unsigned int counter = 1; counter < (place - 1); counter++)rn rn if (head->next != NULL)rn rn head = head->next;rn rn elsern rn exit(-1);rn rn rn for(unsigned int i = 1; i < (place + n - 1); i++)rn rn if(end->next != NULL)rn rn end = end->next;rn rn elsern rn exit(-1);rn rn rnrnrnclass examplernrnpublic:rn int a;rn example* next;rn;rnrnrnint main()rnrn example* head = NULL;rn new_forward_list(head, 10);rn delete_part(head, 3, 2);rn rn rn return 0;rn[/code]rn
单链表、链表队列、循环队列、栈
单链表、队列、栈
用单链表实现栈的问题
两个问题:rn1.用单链表实现栈时,push操作是在表头还是表尾?rn2.如果是在表头操作,那么想按push的顺序显示栈内的数据,该如何操作?rn例如压栈顺序为1 2 3 4 5,此时表头在5,如果按pop顺序显示,则为5 4 3 2 1。但是要求显示1 2 3 4 5.rn谢谢
算法导论 使用单链表实现栈
使用单链表实现栈1. 算法导论原题 10.2-2 Implement a stack using a singly linked list L. The operations PUSH and POP should still take O(1) time. 译:使用一个单链表实现一个栈。PUSH和POP操作仍然需要保持O(1)时间复杂度。 2. 如何使用单链表实现栈? 栈的主要
C语言单链表实现栈
#include <stdio.h> #include <stdlib.h>typedef struct NODE { int val; struct NODE *next; }node;//define nodenode * head=NULL;//init head_node of stack//create node node *create_node(int val) {
python用单链表实现栈
class LNode: &quot;&quot;&quot;节点的类&quot;&quot;&quot; def __init__(self,x): self.data = x self.next = None class MyStack: &quot;&quot;&quot;用链表实现栈&quot;&quot;&quot; def __init__(self): self.data = None self.
线性表,单链表,栈 java实现
线性表,单链表,栈的代码实现,java简单实现,内附有代码少许注释
单链表操作 和 栈、队列的应用
内容和要求 单链表操作 和 栈、队列的应用 基本要求:1)用前插法建立带表头结点的单链表; 2)在该链表中统计数据值为x的结点个数。 3)在该链表中值为k的结点前插入y结点,并删除k结点,如果没有值为k的结点则把y结点插在表尾。 4)定义一个顺序栈和循环队列,实现将队列中所有元素逆置。 实验数据:1)线性表为 6,2,11,5,2,4,2; 2)x=2; 3) k=5 或 k=10; 4)队列中的数据为 1,2,3,4,5,6
C++重写单链表实现的栈
#include&amp;lt;iostream&amp;gt; #include&amp;lt;assert.h&amp;gt; #include&amp;lt;string.h&amp;gt; typedef int ElemType; using namespace std; typedef struct StackNode { ElemType data; StackNode *next; }SNode; class CLin...
实现单链表、栈、队列功能
1、单链表实现增、删、改、查、排序功能,定义一个空的头结点,头指针指向头结点,头结点的指针域保存首节点 #include #include #include typedef struct Node{ int data; struct Node* pNext; }NODE,*PNODE; PNODE creat_list(void); void traverse_list(PNOD
利用栈反向打印单链表
# include # include # define SIZE 5  //初始定义链表的长度 //定义节点 typedef struct Node { int data; struct Node * pNext; }NODE, * PNODE; //定义栈 typedef struct Stack { int * base;  //栈空间基址
单链表的读取,插入和删除。
#include  #include  #define TRUE 1  #define FALSE 0  #define Status int  typedef struct DataType;  typedef struct node  {      DataType data [];      struct node *next;  }Node;
单链表的读取插入删除
1单链表的读取 声明一个指针P指向链表中的第一个结点,初始化j从1开始; 当jStatus GetElem(LinkList L, int i, ElemType *e){ LinkList p; p=L->next; int j=1; while(p && j<i){ p=p->next; ++j; } if(!p || j>i
读取文件创建单链表.c
# include # include FILE *fp ;typedef struct student {    int id ;    int age ;     int score ;    char name[20];    struct student *next ;}STU , *PSTU ; PSTU head = NULL ;int main () { fp = fopen ("s
单链表操作,无法输入
rn[code=C/C++]#includern#includern#define size 10;rntypedef struct node *list;rnstruct nodernrn int love;rn list next;rn;rnlist create()rnrn list first,second;rn first=(list)malloc(sizeof(struct node));rn second=(list)malloc(sizeof(struct node));rn second->next=NULL;rn printf("输入初始化值:\n");rn scanf("%d",first->love); //first->love=4;改成这样才行!rn printf("继续:\n");rn scanf("%d",second->love); //second->love=43;改成这样才行!rn first->next=second;rn return first;rnrnvoid insert(list *head,int i )rn rn list temp;rn list node=*head;rn int x=0;rn temp=(list)malloc(sizeof(struct node));rn while(1)rn rn x++;rn if(i==x)rn rn printf("请输入一个值:\n");rn scanf("%d",temp->love);rn temp->next=node->next;rn node->next=temp;rn rn node=node->next;rn rnrnvoid del(list *head,int i)rnrnrnrnvoid coutlist(list head)rnrn printf("输出:\n");rn for(;head;head=head->next)rn rn printf("%d\n",head->love);rn rnrnvoid choosecout()rnrn printf("选择:\n");rn printf("1.creat\t");rn printf("2.insert\t");rn printf("3.delete\t");rn printf("4.cout\t");rn printf("5.end\n");rnrnint main()rnrn int x;rn int i;rn list head=NULL;rn while(1)rn rn choosecout();rn scanf("%d",&x);rn switch(x)rn rn case 1:rn head=create();rn break;rn case 2:rn printf("输入要删除的位置序号\n");rn scanf("%d",&i);rn insert(&head,i);rn break;rn case 3:rn printf("输入要删除的位置序号\n");rn scanf("%d",&i);rn del(&head,i);rn break;rn case 4:rn coutlist(head);rn break;rn case 5:rn return 0;rn rn rn[/code] rn每次都无法输入!scanf("%d",first->love); scanf("%d",second->love); scanf("%d",temp->love); 都是无法输入的!调试时说时位置冲突: 0xC0000005: 写入位置 0xcdcdcdcd 时发生访问冲突,郁闷!
单链表无法输出
[code=c]rn#includern#includern#includern#define OK 1rn#define ERROR 0rnrntypedef struct Lnode rn int data;rn struct Lnode *next;rn int length;rnLnode;rnrnvoid list_create(Lnode *L);rnvoid list_insert(Lnode *L,int i);rnvoid list_delete(Lnode *L,int i);rnvoid get_tail_data(Lnode L,int *e);rnvoid print(Lnode L);rnint main(void)rnrn Lnode L;rn list_create(&L);rn print(L);rnrnvoid list_create(Lnode *L)rnrn int i,n;rn Lnode *p;rn L=(Lnode *)malloc(sizeof(Lnode));rn if(L==NULL)rn exit(-1);rn rn L->next=NULL;rn printf("Input the length of the list:\n");rn scanf("%d",&n);//the next node is nullrn for(i=1;i<=n;i++)rn printf("Input data%d:",i);rn p=(Lnode *)malloc(sizeof(Lnode));rn scanf("%d",&p->data);rn ++L->length;rn L->next=p;//add the next nodern p->next=L->next;rn rn printf("The length of the list is %d\n",L->length);rn//CreateList_lrnrnvoid print(Lnode L)rnrn Lnode *p;rn p=&L;rn printf("Now the datas int the linked list is\n");rn for(p=p->next;p!=NULL;p=p->next)rn printf("%d ",*(p->data));//Linked_list.c:52: error: invalid type argument of ‘unary *’ (have ‘int’)rn printf("\n");rnrn[/code]
相关热词 c#异步发送kafka c#窗体编号 c# 操作二进制文件 c# 反射 机制 c#线程 窗体失去响应 c#角度转弧度 c# 解析gps数据 c# vs设置 语法版本 c# json含回车 c#多线程demo